ActiveSensingTimeout has its own callback handler

removed ErrorActiveSensingTimeout
This commit is contained in:
lathoub 2020-05-23 10:51:47 +02:00 committed by Francois Best
parent 0db6859802
commit 59fafdbf1a
4 changed files with 13 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

@ -212,6 +212,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

@ -769,24 +769,20 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
sendActiveSensing(); sendActiveSensing();
} }
if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActive)
{
if ((Platform::now() - mLastMessageReceivedTime > Settings::ReceiverActiveSensingTimeout))
{
// Once an Active Sensing message is received, the unit will begin monitoring // 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 // the intervalbetween all subsequent messages. If there is an interval of 420 ms
// or longer betweenmessages while monitoring is active, the same processing // or longer betweenmessages while monitoring is active, the same processing
// as when All Sound Off, All Notes Off,and Reset All Controllers messages are // 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. // received will be carried out. The unit will then stopmonitoring the message interval.
if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActive)
{
if ((Platform::now() - mLastMessageReceivedTime > Settings::ReceiverActiveSensingTimeout))
{
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
@ -805,17 +801,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

@ -56,13 +56,13 @@ typedef byte Channel;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// 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);