public void When_RawData() { var message = new MidiChannelPressureMessage(8, 14); var data = message.RawData.ToArray(); CollectionAssert.AreEqual(new byte[] { 216, 14 }, data); }
protected override void ProcessRecord() { if (ValidateCommonParameters()) { var message = new MidiChannelPressureMessage(Channel, Pressure); Port.RawPort.SendMessage(message); } }
/// <summary> /// Create a new MIDI message based on the message type and parameter(s) values, /// and send it to the chosen output device /// </summary> /// <param name="sender">Element that fired the event</param> /// <param name="e">Event arguments</param> private void sendButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { IMidiMessage midiMessageToSend = null; switch (_currentMessageType) { case MidiMessageType.NoteOff: midiMessageToSend = new MidiNoteOffMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToByte(GetParameterValue(parameter2)), Convert.ToByte(GetParameterValue(parameter3))); break; case MidiMessageType.NoteOn: midiMessageToSend = new MidiNoteOnMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToByte(GetParameterValue(parameter2)), Convert.ToByte(GetParameterValue(parameter3))); break; case MidiMessageType.PolyphonicKeyPressure: midiMessageToSend = new MidiPolyphonicKeyPressureMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToByte(GetParameterValue(parameter2)), Convert.ToByte(GetParameterValue(parameter3))); break; case MidiMessageType.ControlChange: midiMessageToSend = new MidiControlChangeMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToByte(GetParameterValue(parameter2)), Convert.ToByte(GetParameterValue(parameter3))); break; case MidiMessageType.ProgramChange: midiMessageToSend = new MidiProgramChangeMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToByte(GetParameterValue(parameter2))); break; case MidiMessageType.ChannelPressure: midiMessageToSend = new MidiChannelPressureMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToByte(GetParameterValue(parameter2))); break; case MidiMessageType.PitchBendChange: midiMessageToSend = new MidiPitchBendChangeMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToUInt16(GetParameterValue(parameter2))); break; case MidiMessageType.SystemExclusive: var dataWriter = new DataWriter(); var sysExMessage = sysExMessageContent.Text; var sysExMessageLength = sysExMessage.Length; // Do not send a blank SysEx message if (sysExMessageLength == 0) { return; } // SysEx messages are two characters long with 1-character space in between them // So we add 1 to the message length, so that it is perfectly divisible by 3 // The loop count tracks the number of individual message pieces int loopCount = (sysExMessageLength + 1) / 3; // Expecting a string of format "F0 NN NN NN NN.... F7", where NN is a byte in hex for (int i = 0; i < loopCount; i++) { var messageString = sysExMessage.Substring(3 * i, 2); var messageByte = Convert.ToByte(messageString, 16); dataWriter.WriteByte(messageByte); } midiMessageToSend = new MidiSystemExclusiveMessage(dataWriter.DetachBuffer()); break; case MidiMessageType.MidiTimeCode: midiMessageToSend = new MidiTimeCodeMessage(Convert.ToByte(GetParameterValue(parameter1)), Convert.ToByte(GetParameterValue(parameter2))); break; case MidiMessageType.SongPositionPointer: midiMessageToSend = new MidiSongPositionPointerMessage(Convert.ToUInt16(GetParameterValue(parameter1))); break; case MidiMessageType.SongSelect: midiMessageToSend = new MidiSongSelectMessage(Convert.ToByte(GetParameterValue(parameter1))); break; case MidiMessageType.TuneRequest: midiMessageToSend = new MidiTuneRequestMessage(); break; case MidiMessageType.TimingClock: midiMessageToSend = new MidiTimingClockMessage(); break; case MidiMessageType.Start: midiMessageToSend = new MidiStartMessage(); break; case MidiMessageType.Continue: midiMessageToSend = new MidiContinueMessage(); break; case MidiMessageType.Stop: midiMessageToSend = new MidiStopMessage(); break; case MidiMessageType.ActiveSensing: midiMessageToSend = new MidiActiveSensingMessage(); break; case MidiMessageType.SystemReset: midiMessageToSend = new MidiSystemResetMessage(); break; case MidiMessageType.None: default: return; } // Send the message _currentMidiOutputDevice.SendMessage(midiMessageToSend); NotifyUser("Message sent successfully"); }
/// <summary> /// Create a new MIDI message based on the message type and Parameter(s) values, /// and send it to the chosen output device /// </summary> /// <param name="sender">Element that fired the event</param> /// <param name="e">Event arguments</param> private void SendButton_Clicked(object sender, EventArgs e) { MidiMessage midiMessageToSend = null; switch (this.currentMessageType) { case MidiEvent.NoteOff: midiMessageToSend = new MidiNoteOffMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToByte(this.Parameter2.SelectedItem), Convert.ToByte(this.Parameter3.SelectedItem)); break; case MidiEvent.NoteOn: midiMessageToSend = new MidiNoteOnMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToByte(this.Parameter2.SelectedItem), Convert.ToByte(this.Parameter3.SelectedItem)); break; case MidiEvent.PAf: midiMessageToSend = new MidiPolyphonicKeyPressureMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToByte(this.Parameter2.SelectedItem), Convert.ToByte(this.Parameter3.SelectedItem)); break; case MidiEvent.CC: midiMessageToSend = new MidiControlChangeMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToByte(this.Parameter2.SelectedItem), Convert.ToByte(this.Parameter3.SelectedItem)); break; case MidiEvent.Program: midiMessageToSend = new MidiProgramChangeMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToByte(this.Parameter2.SelectedItem)); break; case MidiEvent.CAf: midiMessageToSend = new MidiChannelPressureMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToByte(this.Parameter2.SelectedItem)); break; case MidiEvent.Pitch: midiMessageToSend = new MidiPitchBendChangeMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToUInt16(this.Parameter2.SelectedItem)); break; case MidiEvent.SysEx1: var dataWriter = new List <byte>(); var sysExMessage = this.SysExMessageContent.Text; var sysExMessageLength = sysExMessage.Length; // Do not send a blank SysEx message if (sysExMessageLength == 0) { return; } // SysEx messages are two characters long with 1-character space in between them // So we add 1 to the message length, so that it is perfectly divisible by 3 // The loop count tracks the number of individual message pieces int loopCount = (sysExMessageLength + 1) / 3; // Expecting a string of format "F0 NN NN NN NN.... F7", where NN is a byte in hex for (int i = 0; i < loopCount; i++) { var messageString = sysExMessage.Substring(3 * i, 2); var messageByte = Convert.ToByte(messageString, 16); dataWriter.Add(messageByte); } midiMessageToSend = new MidiSystemExclusiveMessage(dataWriter.ToArray()); break; case MidiEvent.MtcQuarterFrame: midiMessageToSend = new MidiTimeCodeMessage(Convert.ToByte(this.Parameter1.SelectedItem), Convert.ToByte(this.Parameter2.SelectedItem)); break; case MidiEvent.SongPositionPointer: midiMessageToSend = new MidiSongPositionPointerMessage(Convert.ToUInt16(this.Parameter1.SelectedItem)); break; case MidiEvent.SongSelect: midiMessageToSend = new MidiSongSelectMessage(Convert.ToByte(this.Parameter1.SelectedItem)); break; case MidiEvent.TuneRequest: midiMessageToSend = new MidiTuneRequestMessage(); break; case MidiEvent.MidiClock: midiMessageToSend = new MidiTimingClockMessage(); break; case MidiEvent.MidiStart: midiMessageToSend = new MidiStartMessage(); break; case MidiEvent.MidiContinue: midiMessageToSend = new MidiContinueMessage(); break; case MidiEvent.MidiStop: midiMessageToSend = new MidiStopMessage(); break; case MidiEvent.ActiveSense: midiMessageToSend = new MidiActiveSensingMessage(); break; case MidiEvent.Reset: midiMessageToSend = new MidiSystemResetMessage(); break; default: return; } // Send the message _synthesizer.SendMessage(midiMessageToSend); //this.rootPage.NotifyUser("Message sent successfully", NotifyType.StatusMessage); }
/// <summary> /// Create a new MIDI message based on the message type and parameter(s) values, /// and send it to the chosen output device /// </summary> /// <param name="sender">Element that fired the event</param> /// <param name="e">Event arguments</param> private void sendButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { IMidiMessage midiMessageToSend = null; switch (this.currentMessageType) { case MidiMessageType.NoteOff: midiMessageToSend = new MidiNoteOffMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToByte(this.parameter2.SelectedValue), Convert.ToByte(this.parameter3.SelectedValue)); break; case MidiMessageType.NoteOn: midiMessageToSend = new MidiNoteOnMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToByte(this.parameter2.SelectedValue), Convert.ToByte(this.parameter3.SelectedValue)); break; case MidiMessageType.PolyphonicKeyPressure: midiMessageToSend = new MidiPolyphonicKeyPressureMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToByte(this.parameter2.SelectedValue), Convert.ToByte(this.parameter3.SelectedValue)); break; case MidiMessageType.ControlChange: midiMessageToSend = new MidiControlChangeMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToByte(this.parameter2.SelectedValue), Convert.ToByte(this.parameter3.SelectedValue)); break; case MidiMessageType.ProgramChange: midiMessageToSend = new MidiProgramChangeMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToByte(this.parameter2.SelectedValue)); break; case MidiMessageType.ChannelPressure: midiMessageToSend = new MidiChannelPressureMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToByte(this.parameter2.SelectedValue)); break; case MidiMessageType.PitchBendChange: midiMessageToSend = new MidiPitchBendChangeMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToUInt16(this.parameter2.SelectedValue)); break; case MidiMessageType.SystemExclusive: var dataWriter = new DataWriter(); var sysExMessage = this.sysExMessageContent.Text; var sysExMessageLength = sysExMessage.Length; // Do not send a blank SysEx message if (sysExMessageLength == 0) { return; } // SysEx messages are two characters long with 1-character space in between them // So we add 1 to the message length, so that it is perfectly divisible by 3 // The loop count tracks the number of individual message pieces int loopCount = (sysExMessageLength + 1) / 3; // Expecting a string of format "F0 NN NN NN NN.... F7", where NN is a byte in hex for (int i = 0; i < loopCount; i++) { var messageString = sysExMessage.Substring(3 * i, 2); var messageByte = Convert.ToByte(messageString, 16); dataWriter.WriteByte(messageByte); } midiMessageToSend = new MidiSystemExclusiveMessage(dataWriter.DetachBuffer()); break; case MidiMessageType.MidiTimeCode: midiMessageToSend = new MidiTimeCodeMessage(Convert.ToByte(this.parameter1.SelectedValue), Convert.ToByte(this.parameter2.SelectedValue)); break; case MidiMessageType.SongPositionPointer: midiMessageToSend = new MidiSongPositionPointerMessage(Convert.ToUInt16(this.parameter1.SelectedValue)); break; case MidiMessageType.SongSelect: midiMessageToSend = new MidiSongSelectMessage(Convert.ToByte(this.parameter1.SelectedValue)); break; case MidiMessageType.TuneRequest: midiMessageToSend = new MidiTuneRequestMessage(); break; case MidiMessageType.TimingClock: midiMessageToSend = new MidiTimingClockMessage(); break; case MidiMessageType.Start: midiMessageToSend = new MidiStartMessage(); break; case MidiMessageType.Continue: midiMessageToSend = new MidiContinueMessage(); break; case MidiMessageType.Stop: midiMessageToSend = new MidiStopMessage(); break; case MidiMessageType.ActiveSensing: midiMessageToSend = new MidiActiveSensingMessage(); break; case MidiMessageType.SystemReset: midiMessageToSend = new MidiSystemResetMessage(); break; case MidiMessageType.None: default: return; } // Send the message this.currentMidiOutputDevice.SendMessage(midiMessageToSend); this.rootPage.NotifyUser("Message sent successfully", NotifyType.StatusMessage); }