UseSenderActiveSensing & UseReceiverActiveSensing to enable/disable Active Sensing

UseSenderActiveSensing & UseReceiverActiveSensing in Settings are global switches to turn on/off ActiveSensing (and save memory)
This commit is contained in:
lathoub 2020-03-22 17:19:15 +01:00
parent 8730ae0bde
commit d4b692ab76
3 changed files with 30 additions and 15 deletions

View File

@ -235,6 +235,8 @@ public:
inline void turnThruOff();
inline void setThruFilterMode(Thru::Mode inThruFilterMode);
inline void UpdateLastSentTime();
private:
void thruFilter(byte inChannel);
@ -273,13 +275,6 @@ private:
private:
inline StatusByte getStatus(MidiType inType,
Channel inChannel) const;
inline void UpdateLastSentTime()
{
if (mSenderActiveSensingPeriodicity)
mLastMessageSentTime = Platform::now();
};
};
// -----------------------------------------------------------------------------

View File

@ -47,6 +47,7 @@ inline MidiInterface<Transport, Settings, Platform>::MidiInterface(Transport& in
, mThruFilterMode(Thru::Full)
, mLastError(0)
{
mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity;
}
/*! \brief Destructor for MidiInterface.
@ -82,7 +83,6 @@ void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
mCurrentRpnNumber = 0xffff;
mCurrentNrpnNumber = 0xffff;
mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity;
mLastMessageSentTime = Platform::now();
mMessage.valid = false;
@ -718,13 +718,13 @@ 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 ((mSenderActiveSensingPeriodicity > 0) && (Platform::now() - mLastMessageSentTime) > mSenderActiveSensingPeriodicity)
if (Settings::UseSenderActiveSensing && (mSenderActiveSensingPeriodicity > 0) && (Platform::now() - mLastMessageSentTime) > mSenderActiveSensingPeriodicity)
{
sendActiveSensing();
mLastMessageSentTime = Platform::now();
sendActiveSensing();
mLastMessageSentTime = Platform::now();
}
if (mReceiverActiveSensingActivated && (mLastMessageReceivedTime + ActiveSensingTimeout < Platform::now()))
if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActivated && (mLastMessageReceivedTime + ActiveSensingTimeout < Platform::now()))
{
mReceiverActiveSensingActivated = false;
@ -741,7 +741,8 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
return false;
#ifndef RegionActiveSending
if (mMessage.type == ActiveSensing)
if (Settings::UseReceiverActiveSensing && mMessage.type == ActiveSensing)
{
// When an ActiveSensing message is received, the time keeping is activated.
// When a timeout occurs, an error message is send and time keeping ends.
@ -756,7 +757,7 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
}
// Keep the time of the last received message, so we can check for the timeout
if (mReceiverActiveSensingActivated)
if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActivated)
mLastMessageReceivedTime = Platform::now();
#endif
@ -1384,6 +1385,13 @@ inline void MidiInterface<Transport, Settings, Platform>::turnThruOff()
mThruFilterMode = Thru::Off;
}
template<class Transport, class Settings, class Platform>
inline void MidiInterface<Transport, Settings, Platform>::UpdateLastSentTime()
{
if (Settings::UseSenderActiveSensing && mSenderActiveSensingPeriodicity)
mLastMessageSentTime = Platform::now();
}
/*! @} */ // End of doc group MIDI Thru
// This method is called upon reception of a message

View File

@ -61,6 +61,18 @@ struct DefaultSettings
*/
static const bool HandleNullVelocityNoteOnAsNoteOff = true;
/*! 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)
*/
static const bool UseSenderActiveSensing = false;
/*! Global switch to turn on/off receiver ActiveSensing
Set to true to check for message timeouts (via ErrorCallback)
Set to false will not check if chained device are still alive (if they use ActiveSensing) (will also save memory)
*/
static const bool UseReceiverActiveSensing = false;
/*! Active Sensing is intended to be sent
repeatedly by the sender to tell the receiver that a connection is alive. Use
of this message is optional. When initially received, the