diff --git a/examples/ReceiverActiveSensing/ReceiverActiveSensing.ino b/examples/ReceiverActiveSensing/ReceiverActiveSensing.ino index e8bcde5..6d91822 100644 --- a/examples/ReceiverActiveSensing/ReceiverActiveSensing.ino +++ b/examples/ReceiverActiveSensing/ReceiverActiveSensing.ino @@ -22,9 +22,9 @@ struct MyMIDISettings : public MIDI_NAMESPACE::DefaultSettings MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, MyMIDISettings); -void errorHandler(int8_t err) +void activeSensingTimeoutExceptionHandler(bool active) { - if (bitRead(err, ErrorActiveSensingTimeout)) + if (!active) { MIDI.sendControlChange(AllSoundOff, 0, 1); MIDI.sendControlChange(AllNotesOff, 0, 1); @@ -41,7 +41,7 @@ void setup() pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); - MIDI.setHandleError(errorHandler); + MIDI.setHandleActiveSensingTimeout(activeSensingTimeoutExceptionHandler); MIDI.begin(1); } diff --git a/src/MIDI.h b/src/MIDI.h index ffc7e16..a5bb5c7 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -185,6 +185,7 @@ public: public: inline void setHandleMessage(void (*fptr)(const MidiMessage&)) { mMessageCallback = fptr; }; inline void setHandleError(ErrorCallback fptr) { mErrorCallback = fptr; } + inline void setHandleActiveSensingTimeout(ActiveSensingTimeoutCallback fptr) { mActiveSensingTimeoutCallback = fptr; } inline void setHandleNoteOff(NoteOffCallback fptr) { mNoteOffCallback = fptr; } inline void setHandleNoteOn(NoteOnCallback fptr) { mNoteOnCallback = fptr; } inline void setHandleAfterTouchPoly(AfterTouchPolyCallback fptr) { mAfterTouchPolyCallback = fptr; } @@ -212,6 +213,7 @@ private: void (*mMessageCallback)(const MidiMessage& message) = nullptr; ErrorCallback mErrorCallback = nullptr; + ActiveSensingTimeoutCallback mActiveSensingTimeoutCallback = nullptr; NoteOffCallback mNoteOffCallback = nullptr; NoteOnCallback mNoteOnCallback = nullptr; AfterTouchPolyCallback mAfterTouchPolyCallback = nullptr; diff --git a/src/MIDI.hpp b/src/MIDI.hpp index 3b9e29b..1276060 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -723,24 +723,20 @@ inline bool MidiInterface::read(Channel inChannel sendActiveSensing(); } + // Once an Active Sensing message is received, the unit will begin monitoring + // the intervalbetween all subsequent messages. If there is an interval of 420 ms + // or longer betweenmessages while monitoring is active, the same processing + // as when All Sound Off, All Notes Off,and Reset All Controllers messages are + // received will be carried out. The unit will then stopmonitoring the message interval. if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActive) { if ((Platform::now() - mLastMessageReceivedTime > Settings::ReceiverActiveSensingTimeout)) { - // Once an Active Sensing message is received, the unit will begin monitoring - // the intervalbetween all subsequent messages. If there is an interval of 420 ms - // or longer betweenmessages while monitoring is active, the same processing - // as when All Sound Off, All Notes Off,and Reset All Controllers messages are - // received will be carried out. The unit will then stopmonitoring the message interval. mReceiverActiveSensingActive = false; - // its up to the error handler to send the stop processing messages + // its up to the handler to send the stop processing messages // (also, no clue what the channel is on which to send them) - - // no need to check if bit is already set, it is not (due to the mActiveSensingActive switch) - mLastError |= 1UL << ErrorActiveSensingTimeout; // set the ErrorActiveSensingTimeout bit - if (mErrorCallback) - mErrorCallback(mLastError); + mActiveSensingTimeoutCallback(true); } } #endif @@ -759,17 +755,9 @@ inline bool MidiInterface::read(Channel inChannel if (mMessage.type == ActiveSensing && !mReceiverActiveSensingActive) { - // Once an Active Sensing message is received, the unit will begin monitoring - // the intervalbetween all subsequent messages. If there is an interval of 420 ms - // or longer betweenmessages while monitoring is active, the same processing - // as when All Sound Off, All Notes Off,and Reset All Controllers messages are - // received will be carried out. The unit will then stopmonitoring the message interval. mReceiverActiveSensingActive = true; - // Clear the ErrorActiveSensingTimeout bit - mLastError &= ~(1UL << ErrorActiveSensingTimeout); - if (mErrorCallback) - mErrorCallback(mLastError); + mActiveSensingTimeoutCallback(false); } } diff --git a/src/midi_Defs.h b/src/midi_Defs.h index 623d97e..4ee9ec4 100644 --- a/src/midi_Defs.h +++ b/src/midi_Defs.h @@ -57,13 +57,13 @@ typedef byte FilterMode; // ----------------------------------------------------------------------------- // Errors static const uint8_t ErrorParse = 0; -static const uint8_t ErrorActiveSensingTimeout = 1; static const uint8_t WarningSplitSysEx = 2; // ----------------------------------------------------------------------------- // Aliasing using ErrorCallback = void (*)(int8_t); +using ActiveSensingTimeoutCallback = void (*)(bool); using NoteOffCallback = void (*)(Channel channel, byte note, byte velocity); using NoteOnCallback = void (*)(Channel channel, byte note, byte velocity); using AfterTouchPolyCallback = void (*)(Channel channel, byte note, byte velocity);