Skip to content

Commit ca3371a

Browse files
author
lathoub
committed
ActiveSensingTimeout has its own callback handler
removed ErrorActiveSensingTimeout
1 parent 1640504 commit ca3371a

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

examples/ReceiverActiveSensing/ReceiverActiveSensing.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ struct MyMIDISettings : public MIDI_NAMESPACE::DefaultSettings
2222

2323
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, MyMIDISettings);
2424

25-
void errorHandler(int8_t err)
25+
void activeSensingTimeoutExceptionHandler(bool active)
2626
{
27-
if (bitRead(err, ErrorActiveSensingTimeout))
27+
if (!active)
2828
{
2929
MIDI.sendControlChange(AllSoundOff, 0, 1);
3030
MIDI.sendControlChange(AllNotesOff, 0, 1);
@@ -41,7 +41,7 @@ void setup()
4141
pinMode(LED_BUILTIN, OUTPUT);
4242
digitalWrite(LED_BUILTIN, LOW);
4343

44-
MIDI.setHandleError(errorHandler);
44+
MIDI.setHandleActiveSensingTimeout(activeSensingTimeoutExceptionHandler);
4545
MIDI.begin(1);
4646
}
4747

src/MIDI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class MidiInterface
185185
public:
186186
inline void setHandleMessage(void (*fptr)(const MidiMessage&)) { mMessageCallback = fptr; };
187187
inline void setHandleError(ErrorCallback fptr) { mErrorCallback = fptr; }
188+
inline void setHandleActiveSensingTimeout(ActiveSensingTimeoutCallback fptr) { mActiveSensingTimeoutCallback = fptr; }
188189
inline void setHandleNoteOff(NoteOffCallback fptr) { mNoteOffCallback = fptr; }
189190
inline void setHandleNoteOn(NoteOnCallback fptr) { mNoteOnCallback = fptr; }
190191
inline void setHandleAfterTouchPoly(AfterTouchPolyCallback fptr) { mAfterTouchPolyCallback = fptr; }
@@ -212,6 +213,7 @@ class MidiInterface
212213

213214
void (*mMessageCallback)(const MidiMessage& message) = nullptr;
214215
ErrorCallback mErrorCallback = nullptr;
216+
ActiveSensingTimeoutCallback mActiveSensingTimeoutCallback = nullptr;
215217
NoteOffCallback mNoteOffCallback = nullptr;
216218
NoteOnCallback mNoteOnCallback = nullptr;
217219
AfterTouchPolyCallback mAfterTouchPolyCallback = nullptr;

src/MIDI.hpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -723,24 +723,20 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
723723
sendActiveSensing();
724724
}
725725

726+
// Once an Active Sensing message is received, the unit will begin monitoring
727+
// the intervalbetween all subsequent messages. If there is an interval of 420 ms
728+
// or longer betweenmessages while monitoring is active, the same processing
729+
// as when All Sound Off, All Notes Off,and Reset All Controllers messages are
730+
// received will be carried out. The unit will then stopmonitoring the message interval.
726731
if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActive)
727732
{
728733
if ((Platform::now() - mLastMessageReceivedTime > Settings::ReceiverActiveSensingTimeout))
729734
{
730-
// Once an Active Sensing message is received, the unit will begin monitoring
731-
// the intervalbetween all subsequent messages. If there is an interval of 420 ms
732-
// or longer betweenmessages while monitoring is active, the same processing
733-
// as when All Sound Off, All Notes Off,and Reset All Controllers messages are
734-
// received will be carried out. The unit will then stopmonitoring the message interval.
735735
mReceiverActiveSensingActive = false;
736736

737-
// its up to the error handler to send the stop processing messages
737+
// its up to the handler to send the stop processing messages
738738
// (also, no clue what the channel is on which to send them)
739-
740-
// no need to check if bit is already set, it is not (due to the mActiveSensingActive switch)
741-
mLastError |= 1UL << ErrorActiveSensingTimeout; // set the ErrorActiveSensingTimeout bit
742-
if (mErrorCallback)
743-
mErrorCallback(mLastError);
739+
mActiveSensingTimeoutCallback(true);
744740
}
745741
}
746742
#endif
@@ -759,17 +755,9 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
759755

760756
if (mMessage.type == ActiveSensing && !mReceiverActiveSensingActive)
761757
{
762-
// Once an Active Sensing message is received, the unit will begin monitoring
763-
// the intervalbetween all subsequent messages. If there is an interval of 420 ms
764-
// or longer betweenmessages while monitoring is active, the same processing
765-
// as when All Sound Off, All Notes Off,and Reset All Controllers messages are
766-
// received will be carried out. The unit will then stopmonitoring the message interval.
767758
mReceiverActiveSensingActive = true;
768759

769-
// Clear the ErrorActiveSensingTimeout bit
770-
mLastError &= ~(1UL << ErrorActiveSensingTimeout);
771-
if (mErrorCallback)
772-
mErrorCallback(mLastError);
760+
mActiveSensingTimeoutCallback(false);
773761
}
774762
}
775763

src/midi_Defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ typedef byte FilterMode;
5757
// -----------------------------------------------------------------------------
5858
// Errors
5959
static const uint8_t ErrorParse = 0;
60-
static const uint8_t ErrorActiveSensingTimeout = 1;
6160
static const uint8_t WarningSplitSysEx = 2;
6261

6362
// -----------------------------------------------------------------------------
6463
// Aliasing
6564

6665
using ErrorCallback = void (*)(int8_t);
66+
using ActiveSensingTimeoutCallback = void (*)(bool);
6767
using NoteOffCallback = void (*)(Channel channel, byte note, byte velocity);
6868
using NoteOnCallback = void (*)(Channel channel, byte note, byte velocity);
6969
using AfterTouchPolyCallback = void (*)(Channel channel, byte note, byte velocity);

0 commit comments

Comments
 (0)