예제 #1
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);
            }
        }
예제 #2
0
        private void OnShortMessage(int message, int milliseconds)
        {
            WriteBytesToStream(_channelMessageMemoryStream, message.GetThirdByte(), message.GetSecondByte());

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

            OnEventReceived(midiEvent, milliseconds);

            if (RaiseMidiTimeCodeReceived)
            {
                var midiTimeCodeEvent = midiEvent as MidiTimeCodeEvent;
                if (midiTimeCodeEvent != null)
                {
                    TryRaiseMidiTimeCodeReceived(midiTimeCodeEvent);
                }
            }
        }