From 35d1d6216a9e85cab05584e3af349a0d1cba3ff2 Mon Sep 17 00:00:00 2001 From: lathoub Date: Sat, 7 Mar 2020 10:15:59 +0100 Subject: [PATCH] set ActiveSensing Periodicity in ms Gives more control over the bool value. Typical value is 300 (ms) - an Active Sensing command is send every 300ms; or 0 (zero) to disable sending ActiveSensing --- src/MIDI.h | 2 +- src/MIDI.hpp | 8 ++++---- src/midi_Settings.h | 7 +++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/MIDI.h b/src/MIDI.h index e757174..9ae8ca9 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -247,7 +247,7 @@ private: MidiMessage mMessage; unsigned long mLastMessageSentTime; - bool mSenderActiveSensingActivated; + unsigned long mSenderActiveSensingPeriodicity; private: inline StatusByte getStatus(MidiType inType, diff --git a/src/MIDI.hpp b/src/MIDI.hpp index cbd03db..821742f 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -41,7 +41,7 @@ inline MidiInterface::MidiInterface(Encoder& inEnco , mCurrentRpnNumber(0xffff) , mCurrentNrpnNumber(0xffff) , mLastMessageSentTime(0) - , mSenderActiveSensingActivated(false) + , mSenderActiveSensingPeriodicity(0) , mThruActivated(false) , mThruFilterMode(Thru::Full) { @@ -98,7 +98,7 @@ void MidiInterface::begin(Channel inChannel) mCurrentRpnNumber = 0xffff; mCurrentNrpnNumber = 0xffff; - mSenderActiveSensingActivated = Settings::UseSenderActiveSensing; + mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity; mLastMessageSentTime = Platform::now(); mMessage.valid = false; @@ -184,7 +184,7 @@ void MidiInterface::send(MidiType inType, sendRealTime(inType); // System Real-time and 1 byte. } - if (mSenderActiveSensingActivated) + if (mSenderActiveSensingPeriodicity) mLastMessageSentTime = Platform::now(); } @@ -676,7 +676,7 @@ 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 (mSenderActiveSensingActivated && (Platform::now() - mLastMessageSentTime) > 270) + if ((mSenderActiveSensingPeriodicity > 0) && (Platform::now() - mLastMessageSentTime) > mSenderActiveSensingPeriodicity) { sendRealTime(ActiveSensing); mLastMessageSentTime = Platform::now(); diff --git a/src/midi_Settings.h b/src/midi_Settings.h index 84716c4..d5ef1c8 100644 --- a/src/midi_Settings.h +++ b/src/midi_Settings.h @@ -68,9 +68,12 @@ struct DefaultSettings message each 300ms (max), and if it does not then it will assume that the connection has been terminated. At termination, the receiver will turn off all voices and return to - normal (non- active sensing) operation.. + normal (non- active sensing) operation. + + Setting this field to 0 will disable MIDI active sensing. + Typical value is 300 (ms) - an Active Sensing command is send every 300ms. */ - static const bool UseSenderActiveSensing = false; + static const uint16_t SenderActiveSensingPeriodicity = 0; /*! Setting this to true will make MIDI.read parse only one byte of data for each call when data is available. This can speed up your application if receiving