From 59fafdbf1aef1d2b5fc15a7acf89215e2a76c6da Mon Sep 17 00:00:00 2001 From: lathoub Date: Sat, 23 May 2020 10:51:47 +0200 Subject: [PATCH] ActiveSensingTimeout has its own callback handler removed ErrorActiveSensingTimeout --- .../ReceiverActiveSensing.ino | 6 ++-- src/MIDI.h | 1 + src/MIDI.hpp | 28 ++++++------------- src/midi_Defs.h | 2 +- 4 files changed, 13 insertions(+), 24 deletions(-) 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 7598cc6..67d316a 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -212,6 +212,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 1e9d7dc..c51e83e 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -769,24 +769,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 @@ -805,17 +801,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 89e7d0f..409407b 100644 --- a/src/midi_Defs.h +++ b/src/midi_Defs.h @@ -56,13 +56,13 @@ typedef byte Channel; // ----------------------------------------------------------------------------- // 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);