ActiveSensingTimeout has its own callback handler

removed ErrorActiveSensingTimeout
This commit is contained in:
lathoub 2020-05-23 10:51:47 +02:00
parent 1640504544
commit ca3371a7f2
4 changed files with 14 additions and 24 deletions

View File

@ -22,9 +22,9 @@ struct MyMIDISettings : public MIDI_NAMESPACE::DefaultSettings
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, MyMIDISettings); 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(AllSoundOff, 0, 1);
MIDI.sendControlChange(AllNotesOff, 0, 1); MIDI.sendControlChange(AllNotesOff, 0, 1);
@ -41,7 +41,7 @@ void setup()
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
MIDI.setHandleError(errorHandler); MIDI.setHandleActiveSensingTimeout(activeSensingTimeoutExceptionHandler);
MIDI.begin(1); MIDI.begin(1);
} }

View File

@ -185,6 +185,7 @@ public:
public: public:
inline void setHandleMessage(void (*fptr)(const MidiMessage&)) { mMessageCallback = fptr; }; inline void setHandleMessage(void (*fptr)(const MidiMessage&)) { mMessageCallback = fptr; };
inline void setHandleError(ErrorCallback fptr) { mErrorCallback = fptr; } inline void setHandleError(ErrorCallback fptr) { mErrorCallback = fptr; }
inline void setHandleActiveSensingTimeout(ActiveSensingTimeoutCallback fptr) { mActiveSensingTimeoutCallback = fptr; }
inline void setHandleNoteOff(NoteOffCallback fptr) { mNoteOffCallback = fptr; } inline void setHandleNoteOff(NoteOffCallback fptr) { mNoteOffCallback = fptr; }
inline void setHandleNoteOn(NoteOnCallback fptr) { mNoteOnCallback = fptr; } inline void setHandleNoteOn(NoteOnCallback fptr) { mNoteOnCallback = fptr; }
inline void setHandleAfterTouchPoly(AfterTouchPolyCallback fptr) { mAfterTouchPolyCallback = fptr; } inline void setHandleAfterTouchPoly(AfterTouchPolyCallback fptr) { mAfterTouchPolyCallback = fptr; }
@ -212,6 +213,7 @@ private:
void (*mMessageCallback)(const MidiMessage& message) = nullptr; void (*mMessageCallback)(const MidiMessage& message) = nullptr;
ErrorCallback mErrorCallback = nullptr; ErrorCallback mErrorCallback = nullptr;
ActiveSensingTimeoutCallback mActiveSensingTimeoutCallback = nullptr;
NoteOffCallback mNoteOffCallback = nullptr; NoteOffCallback mNoteOffCallback = nullptr;
NoteOnCallback mNoteOnCallback = nullptr; NoteOnCallback mNoteOnCallback = nullptr;
AfterTouchPolyCallback mAfterTouchPolyCallback = nullptr; AfterTouchPolyCallback mAfterTouchPolyCallback = nullptr;

View File

@ -723,24 +723,20 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
sendActiveSensing(); 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 (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActive)
{ {
if ((Platform::now() - mLastMessageReceivedTime > Settings::ReceiverActiveSensingTimeout)) 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; 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) // (also, no clue what the channel is on which to send them)
mActiveSensingTimeoutCallback(true);
// 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);
} }
} }
#endif #endif
@ -759,17 +755,9 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
if (mMessage.type == ActiveSensing && !mReceiverActiveSensingActive) 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; mReceiverActiveSensingActive = true;
// Clear the ErrorActiveSensingTimeout bit mActiveSensingTimeoutCallback(false);
mLastError &= ~(1UL << ErrorActiveSensingTimeout);
if (mErrorCallback)
mErrorCallback(mLastError);
} }
} }

View File

@ -57,13 +57,13 @@ typedef byte FilterMode;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Errors // Errors
static const uint8_t ErrorParse = 0; static const uint8_t ErrorParse = 0;
static const uint8_t ErrorActiveSensingTimeout = 1;
static const uint8_t WarningSplitSysEx = 2; static const uint8_t WarningSplitSysEx = 2;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Aliasing // Aliasing
using ErrorCallback = void (*)(int8_t); using ErrorCallback = void (*)(int8_t);
using ActiveSensingTimeoutCallback = void (*)(bool);
using NoteOffCallback = void (*)(Channel channel, byte note, byte velocity); using NoteOffCallback = void (*)(Channel channel, byte note, byte velocity);
using NoteOnCallback = 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); using AfterTouchPolyCallback = void (*)(Channel channel, byte note, byte velocity);