From 5fab6b3fc38fa7fbbf06acae55a9f992076acd73 Mon Sep 17 00:00:00 2001 From: lathoub Date: Tue, 4 Feb 2020 10:46:14 +0100 Subject: [PATCH] replaced ActiveSensing with Sender Active Sensing Receiver active Sensing is not implemented (yet) --- src/MIDI.h | 7 +++---- src/MIDI.hpp | 38 +++++++++++--------------------------- src/midi_Settings.h | 11 +++++++++++ 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/MIDI.h b/src/MIDI.h index 78ba06c..268c6a9 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -86,8 +86,6 @@ public: DataByte inPressure, Channel inChannel); - inline void sendActiveSensing(); - inline void sendSysEx(unsigned inLength, const byte* inArray, bool inArrayContainsBoundaries = false); @@ -242,9 +240,10 @@ private: unsigned mCurrentNrpnNumber; bool mThruActivated : 1; Thru::Mode mThruFilterMode : 7; + unsigned long mLastMessageSentTime; + bool mSenderActiveSensingActivated; MidiMessage mMessage; - unsigned long mLastSendMessageTime; - bool mActiveSensingActivated; + private: inline StatusByte getStatus(MidiType inType, diff --git a/src/MIDI.hpp b/src/MIDI.hpp index 0f1aea1..76a4fb8 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -40,8 +40,8 @@ inline MidiInterface::MidiInterface(SerialPort& inSerial) , mPendingMessageIndex(0) , mCurrentRpnNumber(0xffff) , mCurrentNrpnNumber(0xffff) - , mActiveSensingActivated(false) - , mLastSendMessageTime(0) + , mSenderActiveSensingActivated(false) + , mLastMessageSentTime(0) , mThruActivated(true) , mThruFilterMode(Thru::Full) { @@ -102,15 +102,15 @@ void MidiInterface::begin(Channel inChannel) mCurrentRpnNumber = 0xffff; mCurrentNrpnNumber = 0xffff; - mActiveSensingActivated = false; - mLastSendMessageTime = millis(); - mMessage.valid = false; mMessage.type = InvalidType; mMessage.channel = 0; mMessage.data1 = 0; mMessage.data2 = 0; + mSenderActiveSensingActivated = Settings::UseSenderActiveSensing; + mLastMessageSentTime = millis(); + mThruFilterMode = Thru::Full; mThruActivated = true; } @@ -182,9 +182,9 @@ void MidiInterface::send(MidiType inType, { sendRealTime(inType); // System Real-time and 1 byte. } - - if (mActiveSensingActivated) - mLastSendMessageTime = millis(); + + if (mSenderActiveSensingActivated) + mLastMessageSentTime = millis(); } // ----------------------------------------------------------------------------- @@ -320,22 +320,6 @@ void MidiInterface::sendPitchBend(double inPitchValue, sendPitchBend(value, inChannel); } -/*! \brief Send an Active Sensing message. - - This message is intended to be sent - repeatedly to tell the receiver that a connection is alive. Use - of this message is optional. When initially received, the - receiver will expect to receive another Active Sensing - message each 300ms (max), and if it does not then it will - assume that the connection has been terminated. - */ -template -void MidiInterface::sendActiveSensing() -{ - sendRealTime(ActiveSensing); -} - - /*! \brief Generate and send a System Exclusive frame. \param inLength The size of the array to send \param inArray The byte array containing the data to send @@ -682,10 +666,10 @@ 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 (mActiveSensingActivated && (millis() - mLastSendMessageTime) > 250) + if (mSenderActiveSensingActivated && (millis() - mLastMessageSentTime) > 250) { - sendActiveSensing(); - mLastSendMessageTime = millis(); + sendRealTime(ActiveSensing); + mLastMessageSentTime = millis(); } if (inChannel >= MIDI_CHANNEL_OFF) diff --git a/src/midi_Settings.h b/src/midi_Settings.h index 493a3b3..9e1a52c 100644 --- a/src/midi_Settings.h +++ b/src/midi_Settings.h @@ -61,6 +61,17 @@ struct DefaultSettings */ static const bool HandleNullVelocityNoteOnAsNoteOff = true; + /*! 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 + receiver will expect to receive another Active Sensing + 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.. + */ + static const bool UseSenderActiveSensing = true; + /*! 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 a lot of traffic, but might induce MIDI Thru and treatment latency.