예제 #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);
            }
        }
        private void OnSysExEventSent(IntPtr sysExHeaderPointer)
        {
            byte[] data = null;

            try
            {
                data = MidiWinApi.UnpackSysExBytes(sysExHeaderPointer);
                var midiEvent = new NormalSysExEvent(data);
                OnEventSent(midiEvent);

                UnprepareSysExBuffer(sysExHeaderPointer);
                _sysExHeadersPointers.Remove(sysExHeaderPointer);
            }
            catch (Exception ex)
            {
                var exception = new MidiDeviceException("Failed to parse sent system exclusive event.", ex);
                exception.Data.Add("Data", data);
                OnError(exception);
            }
        }
예제 #5
0
        private void OnSysExMessage(IntPtr sysExHeaderPointer)
        {
            byte[] data = null;

            try
            {
                data = MidiWinApi.UnpackSysExBytes(sysExHeaderPointer);
                var midiEvent = new NormalSysExEvent(data);
                OnEventReceived(midiEvent);

                UnprepareSysExBuffer(sysExHeaderPointer);
                PrepareSysExBuffer();
            }
            catch (Exception ex)
            {
                var exception = new MidiDeviceException($"Failed to parse system exclusive message.", ex);
                exception.Data.Add("Data", data);
                OnError(exception);
            }
        }