Пример #1
0
        /// <summary>
        /// Callback function to be called by the system.
        /// </summary>
        /// <param name="handle">An <see cref="API.MidiDeviceHandle"/> to the MIDI input device to associate with the callback function.</param>
        /// <param name="message">An <see cref="API.MidiInputMessage"/> containing the message.</param>
        /// <param name="instance">An <see cref="IntPtr"/> to the instance data supplied by the <see cref="API.OpenMidiInputDevice"/> function.</param>
        /// <param name="messageParameterA">An <see cref="IntPtr"/> to the first message parameter.</param>
        /// <param name="messageParameterB">An <see cref="IntPtr"/> to the second message parameter.</param>
        private void Callback(API.MidiDeviceHandle handle, API.MidiInputMessage message, IntPtr instance, IntPtr messageParameterA, IntPtr messageParameterB)
        {
            switch (message)
            {
            case API.MidiInputMessage.MIDI_INPUT_MESSAGE_DATA:

                // A = Packed MIDI message, B = Time in milliseconds since Start
                ProcessShortMessage(new ShortMessage(messageParameterA, messageParameterB));

                break;

            case API.MidiInputMessage.MIDI_INPUT_MESSAGE_LONG_DATA:

                // Extracts the MIDI header for message validation
                API.MidiHeader midiHeader = (API.MidiHeader)Marshal.PtrToStructure(messageParameterA, typeof(API.MidiHeader));

                // Prevents creation of long messages when the MIDI header buffer is empty
                if (midiHeader.BytesRecorded == 0)
                {
                    ReleaseBuffer(messageParameterA);
                    return;
                }

                // A = Pointer to MIDI header, B = Time in milliseconds since Start
                ProcessLongMessage(new LongMessage(messageParameterA, messageParameterB));

                break;

            case API.MidiInputMessage.MIDI_INPUT_MESSAGE_MORE_DATA:
                Console.WriteLine("MIDI IN MORE DATA");
                // A = Packed MIDI message, B = Time in milliseconds since Start
                break;

            case API.MidiInputMessage.MIDI_INPUT_MESSAGE_ERROR:

                // A = Invalid MIDI message, B = Time in milliseconds since Start
                break;

            case API.MidiInputMessage.MIDI_INPUT_MESSAGE_LONG_ERROR:

                // A = Pointer to MIDI header, B = Time in milliseconds since Start
                break;

            case API.MidiInputMessage.MIDI_INPUT_MESSAGE_OPEN:

                this.IsOpen = true;

                break;

            case API.MidiInputMessage.MIDI_INPUT_MESSAGE_CLOSE:

                this.IsOpen = false;

                break;
            }
        }
Пример #2
0
 /// <summary>
 /// Callback function to be called by the system.
 /// </summary>
 /// <param name="handle">An <see cref="API.MidiDeviceHandle"/> to the MIDI output device to associate with the callback function.</param>
 /// <param name="message">An <see cref="API.MidiOutputMessage"/> containing the message.</param>
 /// <param name="instance">An <see cref="IntPtr"/> to the instance data supplied by the <see cref="API.OpenMidiOutputDevice"/> function.</param>
 /// <param name="messageParameterA">An <see cref="IntPtr"/> to the first message parameter.</param>
 /// <param name="messageParameterB">An <see cref="IntPtr"/> to the second message parameter.</param>
 private void Callback(API.MidiDeviceHandle handle, API.MidiOutputMessage message, IntPtr instance, IntPtr messageParameterA, IntPtr messageParameterB)
 {
     if (message == API.MidiOutputMessage.MIDI_OUTPUT_MESSAGE_OPEN)
     {
         this.IsOpen = true;
     }
     else if (message == API.MidiOutputMessage.MIDI_OUTPUT_MESSAGE_CLOSE)
     {
         this.IsOpen = false;
     }
     else
     {
         // API.MidiOutputMessage.MIDI_OUTPUT_MESSAGE_DONE
         Ready?.Invoke(this, new EventArgs());
     }
 }