@@ -62,6 +62,7 @@ inline MidiInterface<SerialPort, Settings>::MidiInterface(SerialPort& inSerial)
62
62
mStopCallback = 0 ;
63
63
mActiveSensingCallback = 0 ;
64
64
mSystemResetCallback = 0 ;
65
+ mInjectMessageByteCallback = 0 ;
65
66
}
66
67
67
68
/* ! \brief Destructor for MidiInterface.
@@ -676,9 +677,20 @@ inline bool MidiInterface<SerialPort, Settings>::read(Channel inChannel)
676
677
template <class SerialPort , class Settings >
677
678
bool MidiInterface<SerialPort, Settings>::parse()
678
679
{
679
- if (mSerial .available () == 0 )
680
- // No data available.
680
+ byte extracted = 255 ;
681
+
682
+ if (mInjectMessageByteCallback != 0 ) {
683
+ extracted = mInjectMessageByteCallback ();
684
+ // extracted will remain 255 if no data is enqueued
685
+ }
686
+
687
+ if (extracted == 255 && mSerial .available () != 0 ) {
688
+ extracted = mSerial .read ();
689
+
690
+ } else if (extracted == 255 ) {
691
+ // No data available and no callback.
681
692
return false ;
693
+ }
682
694
683
695
// Parsing algorithm:
684
696
// Get a byte from the serial buffer.
@@ -689,8 +701,6 @@ bool MidiInterface<SerialPort, Settings>::parse()
689
701
// Else, add the extracted byte to the pending message, and check validity.
690
702
// When the message is done, store it.
691
703
692
- const byte extracted = mSerial .read ();
693
-
694
704
// Ignore Undefined
695
705
if (extracted == 0xf9 || extracted == 0xfd )
696
706
{
@@ -1165,6 +1175,7 @@ template<class SerialPort, class Settings> void MidiInterface<SerialPort, Settin
1165
1175
template <class SerialPort , class Settings > void MidiInterface<SerialPort, Settings>::setHandleStop(void (*fptr)(void )) { mStopCallback = fptr; }
1166
1176
template <class SerialPort , class Settings > void MidiInterface<SerialPort, Settings>::setHandleActiveSensing(void (*fptr)(void )) { mActiveSensingCallback = fptr; }
1167
1177
template <class SerialPort , class Settings > void MidiInterface<SerialPort, Settings>::setHandleSystemReset(void (*fptr)(void )) { mSystemResetCallback = fptr; }
1178
+ template <class SerialPort , class Settings > void MidiInterface<SerialPort, Settings>::setHandleInjectMessageByte(byte (*fptr)(void )) { mInjectMessageByteCallback = fptr; }
1168
1179
1169
1180
/* ! \brief Detach an external function from the given type.
1170
1181
0 commit comments