reworked active Sensing

This commit is contained in:
lathoub 2020-05-16 16:35:03 +02:00 committed by Francois Best
parent f42c344375
commit 350f6d1ec4
4 changed files with 13 additions and 14 deletions

View File

@ -293,7 +293,6 @@ private:
MidiMessage mMessage;
unsigned long mLastMessageSentTime;
unsigned long mLastMessageReceivedTime;
unsigned long mSenderActiveSensingPeriodicity;
bool mReceiverActiveSensingActivated;
int8_t mLastError;

View File

@ -42,11 +42,10 @@ inline MidiInterface<Transport, Settings, Platform>::MidiInterface(Transport& in
, mCurrentNrpnNumber(0xffff)
, mLastMessageSentTime(0)
, mLastMessageReceivedTime(0)
, mSenderActiveSensingPeriodicity(0)
, mReceiverActiveSensingActivated(false)
, mLastError(0)
, mSenderActiveSensingPeriodicity(Settings::SenderActiveSensingPeriodicity)
{
mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity;
}
/*! \brief Destructor for MidiInterface.
@ -765,7 +764,7 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
// assume that the connection has been terminated. At
// termination, the receiver will turn off all voices and return to
// normal (non- active sensing) operation.
if (Settings::UseSenderActiveSensing && (mSenderActiveSensingPeriodicity > 0) && (Platform::now() - mLastMessageSentTime) > mSenderActiveSensingPeriodicity)
if (Settings::UseSenderActiveSensing && (Platform::now() - mLastMessageSentTime) > Settings::SenderActiveSensingPeriodicity)
{
sendActiveSensing();
mLastMessageSentTime = Platform::now();
@ -1407,6 +1406,10 @@ template<class Transport, class Settings, class Platform>
inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::turnThruOff()
{
mThruFilterCallback = thruOff;
if (Settings::UseSenderActiveSensing)
{
mLastMessageSentTime = Platform::now();
}
return *this;
}

View File

@ -75,6 +75,7 @@ struct DefaultSettings
/*! Global switch to turn on/off sender ActiveSensing
Set to true to send ActiveSensing
Set to false will not send ActiveSensing message (will also save memory)
as often as possible (1000 / SenderActiveSensingPeriodicity per second).
*/
static const bool UseSenderActiveSensing = false;
@ -95,10 +96,8 @@ struct DefaultSettings
Typical value is 250 (ms) - an Active Sensing command is send every 250ms.
(All Roland devices send Active Sensing every 250ms)
Setting this field to 0 will disable sending MIDI active sensing.
*/
static const uint16_t SenderActiveSensingPeriodicity = 0;
static const uint16_t SenderActiveSensingPeriodicity = 250;
};
END_MIDI_NAMESPACE

View File

@ -124,13 +124,11 @@ END_MIDI_NAMESPACE
#endif
/*! \brief Create an instance of the library attached to a serial port with
custom settings.
custom MIDI settings (not to be confused with modified Serial Settings, like BaudRate)
@see DefaultSettings
@see MIDI_CREATE_INSTANCE
*/
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
using Name##SerialTransport = MIDI_NAMESPACE::SerialMIDI<Type>; \
using Name##Interface = MIDI_NAMESPACE::MidiInterface<Name##SerialTransport, Settings>; \
using Name##Message = Name##Interface::MidiMessage; \
Name##SerialTransport serial##Name(SerialPort); \
Name##Interface Name((Name##SerialTransport&)serial##Name);
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>, Settings> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);