Skip to content

Commit 350f6d1

Browse files
lathoubfranky47
authored andcommitted
reworked active Sensing
1 parent f42c344 commit 350f6d1

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/MIDI.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ class MidiInterface
293293
MidiMessage mMessage;
294294
unsigned long mLastMessageSentTime;
295295
unsigned long mLastMessageReceivedTime;
296-
unsigned long mSenderActiveSensingPeriodicity;
297296
bool mReceiverActiveSensingActivated;
298297
int8_t mLastError;
299298

src/MIDI.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ inline MidiInterface<Transport, Settings, Platform>::MidiInterface(Transport& in
4242
, mCurrentNrpnNumber(0xffff)
4343
, mLastMessageSentTime(0)
4444
, mLastMessageReceivedTime(0)
45-
, mSenderActiveSensingPeriodicity(0)
4645
, mReceiverActiveSensingActivated(false)
4746
, mLastError(0)
47+
, mSenderActiveSensingPeriodicity(Settings::SenderActiveSensingPeriodicity)
4848
{
49-
mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity;
5049
}
5150

5251
/*! \brief Destructor for MidiInterface.
@@ -765,7 +764,7 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
765764
// assume that the connection has been terminated. At
766765
// termination, the receiver will turn off all voices and return to
767766
// normal (non- active sensing) operation.
768-
if (Settings::UseSenderActiveSensing && (mSenderActiveSensingPeriodicity > 0) && (Platform::now() - mLastMessageSentTime) > mSenderActiveSensingPeriodicity)
767+
if (Settings::UseSenderActiveSensing && (Platform::now() - mLastMessageSentTime) > Settings::SenderActiveSensingPeriodicity)
769768
{
770769
sendActiveSensing();
771770
mLastMessageSentTime = Platform::now();
@@ -1407,6 +1406,10 @@ template<class Transport, class Settings, class Platform>
14071406
inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::turnThruOff()
14081407
{
14091408
mThruFilterCallback = thruOff;
1409+
if (Settings::UseSenderActiveSensing)
1410+
{
1411+
mLastMessageSentTime = Platform::now();
1412+
}
14101413
return *this;
14111414
}
14121415

src/midi_Settings.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct DefaultSettings
7575
/*! Global switch to turn on/off sender ActiveSensing
7676
Set to true to send ActiveSensing
7777
Set to false will not send ActiveSensing message (will also save memory)
78+
as often as possible (1000 / SenderActiveSensingPeriodicity per second).
7879
*/
7980
static const bool UseSenderActiveSensing = false;
8081

@@ -95,10 +96,8 @@ struct DefaultSettings
9596
9697
Typical value is 250 (ms) - an Active Sensing command is send every 250ms.
9798
(All Roland devices send Active Sensing every 250ms)
98-
99-
Setting this field to 0 will disable sending MIDI active sensing.
10099
*/
101-
static const uint16_t SenderActiveSensingPeriodicity = 0;
100+
static const uint16_t SenderActiveSensingPeriodicity = 250;
102101
};
103102

104103
END_MIDI_NAMESPACE

src/serialMIDI.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ END_MIDI_NAMESPACE
124124
#endif
125125

126126
/*! \brief Create an instance of the library attached to a serial port with
127-
custom settings.
127+
custom MIDI settings (not to be confused with modified Serial Settings, like BaudRate)
128128
@see DefaultSettings
129129
@see MIDI_CREATE_INSTANCE
130130
*/
131-
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
132-
using Name##SerialTransport = MIDI_NAMESPACE::SerialMIDI<Type>; \
133-
using Name##Interface = MIDI_NAMESPACE::MidiInterface<Name##SerialTransport, Settings>; \
134-
using Name##Message = Name##Interface::MidiMessage; \
135-
Name##SerialTransport serial##Name(SerialPort); \
136-
Name##Interface Name((Name##SerialTransport&)serial##Name);
131+
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
132+
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
133+
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>, Settings> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
134+

0 commit comments

Comments
 (0)