public void TestNoteOnOff()
        {
            Console.WriteLine(string.Join(", ", MidiCommunicationChannel.AvailableMidiInputPorts.Select(a => a.Name)));
            Console.WriteLine(string.Join(", ", MidiCommunicationChannel.AvailableMidiOutputPorts.Select(a => a.Name)));

            using (MidiCommunicationChannel comms =
                       new MidiCommunicationChannel(TestInputPort, TestOutputPort))
            {
                var msg = ChannelVoiceMessage.NoteOn(TestMidiChannel, 80, 127);

                DebugMessage(msg);

                comms.SendMidiMessage(msg);

                Thread.Sleep(2000);
                msg = ChannelVoiceMessage.NoteOff(TestMidiChannel, 80, 30);


                DebugMessage(msg);
                comms.SendMidiMessage(msg);


                comms.NoteOn(MidiChannel.One, 80, 127);

                Thread.Sleep(2000);

                comms.NoteOff(MidiChannel.One, 80, 20);
            }
        }
Beispiel #2
0
        private byte[] SerializeChannelVoice(ChannelVoiceMessage message)
        {
            int status = message.Channel - 1;

            switch (message.MessageType)
            {
            case ChannelVoiceMessageType.Note:
                var    noteMessage = message as NoteMessage;
                byte[] notePacket  = new byte[3];
                var    firstByte   = (byte)(status | 0x80);
                if (noteMessage.IsOn)
                {
                    firstByte |= 0x10;     // Note-ON has command = 0x90
                }
                notePacket[0] = firstByte;
                notePacket[1] = (byte)noteMessage.Note;
                notePacket[2] = (byte)noteMessage.Velocity;
                return(notePacket);

            default:
                throw new MidiSerializerException($"Serializer not implemented for channel message {message.MessageType}");
            }
        }
 public static void NoteOn(this MidiCommunicationChannel self, int channel, int key, int velocity)
 {
     self.SendMidiMessage(ChannelVoiceMessage.NoteOn(channel, key, velocity));
 }
 public static void NoteOn(this MidiCommunicationChannel self, int channel, int bend)
 {
     self.SendMidiMessage(ChannelVoiceMessage.PitchBend(channel, bend));
 }
 public static void ProgramChange(this MidiCommunicationChannel self, int channel, int program)
 {
     self.SendMidiMessage(ChannelVoiceMessage.ProgramChange(channel, program));
 }
 public static void PolyphonicPressure(this MidiCommunicationChannel self, int channel, int key, int pressure)
 {
     self.SendMidiMessage(ChannelVoiceMessage.PolyphonicKeyPressure(channel, key, pressure));
 }
 public static void ControllerChange(this MidiCommunicationChannel self, int channel, int cc, int value)
 {
     self.SendMidiMessage(ChannelVoiceMessage.ControllerChange(channel, cc, value));
 }