Skip to content

Commit 59fafdb

Browse files
lathoubfranky47
authored andcommitted
ActiveSensingTimeout has its own callback handler
removed ErrorActiveSensingTimeout
1 parent 0db6859 commit 59fafdb

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class MidiInterface
212212

213213
void (*mMessageCallback)(const MidiMessage& message) = nullptr;
214214
ErrorCallback mErrorCallback = nullptr;
215+
ActiveSensingTimeoutCallback mActiveSensingTimeoutCallback = nullptr;
215216
NoteOffCallback mNoteOffCallback = nullptr;
216217
NoteOnCallback mNoteOnCallback = nullptr;
217218
AfterTouchPolyCallback mAfterTouchPolyCallback = nullptr;

src/MIDI.hpp

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

772+
// Once an Active Sensing message is received, the unit will begin monitoring
773+
// the intervalbetween all subsequent messages. If there is an interval of 420 ms
774+
// or longer betweenmessages while monitoring is active, the same processing
775+
// as when All Sound Off, All Notes Off,and Reset All Controllers messages are
776+
// received will be carried out. The unit will then stopmonitoring the message interval.
772777
if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActive)
773778
{
774779
if ((Platform::now() - mLastMessageReceivedTime > Settings::ReceiverActiveSensingTimeout))
775780
{
776-
// Once an Active Sensing message is received, the unit will begin monitoring
777-
// the intervalbetween all subsequent messages. If there is an interval of 420 ms
778-
// or longer betweenmessages while monitoring is active, the same processing
779-
// as when All Sound Off, All Notes Off,and Reset All Controllers messages are
780-
// received will be carried out. The unit will then stopmonitoring the message interval.
781781
mReceiverActiveSensingActive = false;
782782

783-
// its up to the error handler to send the stop processing messages
783+
// its up to the handler to send the stop processing messages
784784
// (also, no clue what the channel is on which to send them)
785-
786-
// no need to check if bit is already set, it is not (due to the mActiveSensingActive switch)
787-
mLastError |= 1UL << ErrorActiveSensingTimeout; // set the ErrorActiveSensingTimeout bit
788-
if (mErrorCallback)
789-
mErrorCallback(mLastError);
785+
mActiveSensingTimeoutCallback(true);
790786
}
791787
}
792788
#endif
@@ -805,17 +801,9 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
805801

806802
if (mMessage.type == ActiveSensing && !mReceiverActiveSensingActive)
807803
{
808-
// Once an Active Sensing message is received, the unit will begin monitoring
809-
// the intervalbetween all subsequent messages. If there is an interval of 420 ms
810-
// or longer betweenmessages while monitoring is active, the same processing
811-
// as when All Sound Off, All Notes Off,and Reset All Controllers messages are
812-
// received will be carried out. The unit will then stopmonitoring the message interval.
813804
mReceiverActiveSensingActive = true;
814805

815-
// Clear the ErrorActiveSensingTimeout bit
816-
mLastError &= ~(1UL << ErrorActiveSensingTimeout);
817-
if (mErrorCallback)
818-
mErrorCallback(mLastError);
806+
mActiveSensingTimeoutCallback(false);
819807
}
820808
}
821809

src/midi_Defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ typedef byte Channel;
5656
// -----------------------------------------------------------------------------
5757
// Errors
5858
static const uint8_t ErrorParse = 0;
59-
static const uint8_t ErrorActiveSensingTimeout = 1;
6059
static const uint8_t WarningSplitSysEx = 2;
6160

6261
// -----------------------------------------------------------------------------
6362
// Aliasing
6463

6564
using ErrorCallback = void (*)(int8_t);
65+
using ActiveSensingTimeoutCallback = void (*)(bool);
6666
using NoteOffCallback = void (*)(Channel channel, byte note, byte velocity);
6767
using NoteOnCallback = void (*)(Channel channel, byte note, byte velocity);
6868
using AfterTouchPolyCallback = void (*)(Channel channel, byte note, byte velocity);

0 commit comments

Comments
 (0)