示例#1
0
        private void OnMessage(IntPtr hMidi, MidiMessage wMsg, IntPtr dwInstance, IntPtr dwParam1, IntPtr dwParam2)
        {
            if (!IsListeningForEvents)
            {
                return;
            }

            switch (wMsg)
            {
            case MidiMessage.MIM_DATA:
            case MidiMessage.MIM_MOREDATA:
                OnShortMessage(dwParam1.ToInt32());
                break;

            case MidiMessage.MIM_LONGDATA:
                OnSysExMessage(dwParam1);
                break;

            case MidiMessage.MIM_ERROR:
                byte statusByte, firstDataByte, secondDataByte;
                MidiWinApi.UnpackShortEventBytes(dwParam1.ToInt32(), out statusByte, out firstDataByte, out secondDataByte);
                OnInvalidShortEventReceived(statusByte, firstDataByte, secondDataByte);
                break;

            case MidiMessage.MIM_LONGERROR:
                OnInvalidSysExEventReceived(MidiWinApi.UnpackSysExBytes(dwParam1));
                break;
            }
        }
示例#2
0
        private void OnShortMessage(int message)
        {
            try
            {
                byte statusByte, firstDataByte, secondDataByte;
                MidiWinApi.UnpackShortEventBytes(message, out statusByte, out firstDataByte, out secondDataByte);

                var midiEvent = _bytesToMidiEventConverter.Convert(statusByte, new[] { firstDataByte, secondDataByte });
                OnEventReceived(midiEvent);

                if (RaiseMidiTimeCodeReceived)
                {
                    var midiTimeCodeEvent = midiEvent as MidiTimeCodeEvent;
                    if (midiTimeCodeEvent != null)
                    {
                        TryRaiseMidiTimeCodeReceived(midiTimeCodeEvent);
                    }
                }
            }
            catch (Exception ex)
            {
                var exception = new MidiDeviceException($"Failed to parse short message.", ex);
                exception.Data.Add("Message", message);
                OnError(exception);
            }
        }
示例#3
0
        private void OnShortMessage(int message)
        {
            try
            {
                byte statusByte, firstDataByte, secondDataByte;
                MidiWinApi.UnpackShortEventBytes(message, out statusByte, out firstDataByte, out secondDataByte);

                WriteBytesToStream(_channelMessageMemoryStream, firstDataByte, secondDataByte);

                var eventReader = EventReaderFactory.GetReader(statusByte, smfOnly: false);
                var midiEvent   = eventReader.Read(_channelEventReader, ReadingSettings, statusByte);

                OnEventReceived(midiEvent);

                if (RaiseMidiTimeCodeReceived)
                {
                    var midiTimeCodeEvent = midiEvent as MidiTimeCodeEvent;
                    if (midiTimeCodeEvent != null)
                    {
                        TryRaiseMidiTimeCodeReceived(midiTimeCodeEvent);
                    }
                }
            }
            catch (Exception ex)
            {
                var exception = new MidiDeviceException($"Failed to parse short message.", ex);
                exception.Data.Add("Message", message);
                OnError(exception);
            }
        }