diff --git a/src/MIDI.h b/src/MIDI.h index 72c8b1b..e430703 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -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(); - }; - }; // ----------------------------------------------------------------------------- diff --git a/src/MIDI.hpp b/src/MIDI.hpp index 3ab35ec..9f4fd6c 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -47,6 +47,7 @@ inline MidiInterface::MidiInterface(Transport& in , mThruFilterMode(Thru::Full) , mLastError(0) { + mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity; } /*! \brief Destructor for MidiInterface. @@ -82,7 +83,6 @@ void MidiInterface::begin(Channel inChannel) mCurrentRpnNumber = 0xffff; mCurrentNrpnNumber = 0xffff; - mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity; mLastMessageSentTime = Platform::now(); mMessage.valid = false; @@ -718,13 +718,13 @@ inline bool MidiInterface::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::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,9 +757,9 @@ inline bool MidiInterface::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 handleNullVelocityNoteOnAsNoteOff(); @@ -1384,6 +1385,13 @@ inline void MidiInterface::turnThruOff() mThruFilterMode = Thru::Off; } +template +inline void MidiInterface::UpdateLastSentTime() +{ + if (Settings::UseSenderActiveSensing && mSenderActiveSensingPeriodicity) + mLastMessageSentTime = Platform::now(); +} + /*! @} */ // End of doc group MIDI Thru // This method is called upon reception of a message diff --git a/src/midi_Settings.h b/src/midi_Settings.h index bb2d013..21d5c5a 100644 --- a/src/midi_Settings.h +++ b/src/midi_Settings.h @@ -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