makes changes requested in #232 discussion

This commit is contained in:
Eric Sherman 2021-08-06 03:10:36 -04:00 committed by Francois Best
parent a6c3a48571
commit 1fe67bec4f
3 changed files with 7 additions and 39 deletions

View File

@ -236,8 +236,6 @@ private:
// MIDI Soft Thru // MIDI Soft Thru
public: public:
inline bool getThruState() const;
using ThruFilterCallback = bool (*)(const MidiMessage& inMessage); using ThruFilterCallback = bool (*)(const MidiMessage& inMessage);
using ThruMapCallback = MidiMessage (*)(const MidiMessage& inMessage); using ThruMapCallback = MidiMessage (*)(const MidiMessage& inMessage);
inline MidiInterface& turnThruOn(ThruFilterCallback fptr = thruOn); inline MidiInterface& turnThruOn(ThruFilterCallback fptr = thruOn);
@ -254,7 +252,7 @@ public:
} }
private: private:
void thruFilter(); void processThru();
static inline bool thruOn(const MidiMessage& inMessage) { (void)inMessage; return true; } static inline bool thruOn(const MidiMessage& inMessage) { (void)inMessage; return true; }
static inline bool thruOff(const MidiMessage& inMessage) { (void)inMessage; return false; } static inline bool thruOff(const MidiMessage& inMessage) { (void)inMessage; return false; }
static inline MidiMessage thruEcho(const MidiMessage& inMessage) { return inMessage; } static inline MidiMessage thruEcho(const MidiMessage& inMessage) { return inMessage; }

View File

@ -816,7 +816,7 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
if (channelMatch) if (channelMatch)
launchCallback(); launchCallback();
thruFilter(); processThru();
return channelMatch; return channelMatch;
} }
@ -1397,13 +1397,7 @@ void MidiInterface<Transport, Settings, Platform>::launchCallback()
*/ */
template<class Transport, class Settings, class Platform> template<class Transport, class Settings, class Platform>
inline bool MidiInterface<Transport, Settings, Platform>::getThruState() const inline void MidiInterface<Transport, Settings, Platform>::turnThruOn(ThruFilterCallback fptr)
{
return mThruFilterCallback != thruOff;
}
template<class Transport, class Settings, class Platform>
inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::turnThruOn(ThruFilterCallback fptr)
{ {
mThruFilterCallback = fptr; mThruFilterCallback = fptr;
return *this; return *this;
@ -1425,7 +1419,7 @@ inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Se
// - Channel messages are passed to the output whether their channel // - Channel messages are passed to the output whether their channel
// is matching the input channel and the filter setting // is matching the input channel and the filter setting
template<class Transport, class Settings, class Platform> template<class Transport, class Settings, class Platform>
void MidiInterface<Transport, Settings, Platform>::thruFilter() void MidiInterface<Transport, Settings, Platform>::processThru()
{ {
if (!mThruFilterCallback(mMessage)) if (!mThruFilterCallback(mMessage))
return; return;
@ -1433,7 +1427,7 @@ void MidiInterface<Transport, Settings, Platform>::thruFilter()
MidiMessage thruMessage = mThruMapCallback(mMessage); MidiMessage thruMessage = mThruMapCallback(mMessage);
// First, check if the received message is Channel // First, check if the received message is Channel
if (mMessage.type >= NoteOff && mMessage.type <= PitchBend) if (thruMessage.type >= NoteOff && thruMessage.type <= PitchBend)
{ {
send(thruMessage.type, send(thruMessage.type,
thruMessage.data1, thruMessage.data1,
@ -1443,7 +1437,7 @@ void MidiInterface<Transport, Settings, Platform>::thruFilter()
else else
{ {
// Send the message to the output // Send the message to the output
switch (mMessage.type) switch (thruMessage.type)
{ {
// Real Time and 1 byte // Real Time and 1 byte
case Clock: case Clock:
@ -1453,7 +1447,7 @@ void MidiInterface<Transport, Settings, Platform>::thruFilter()
case ActiveSensing: case ActiveSensing:
case SystemReset: case SystemReset:
case TuneRequest: case TuneRequest:
sendRealTime(mMessage.type); sendRealTime(thruMessage.type);
break; break;
case SystemExclusive: case SystemExclusive:

View File

@ -59,30 +59,6 @@ MidiMessage thruMapNoteOnFullVelocity(const MidiMessage& inMessage)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST(MidiThru, defaultValues)
{
EXPECT_EQ(midi.getThruState(), true);
midi.begin(); // Should not change the state
EXPECT_EQ(midi.getThruState(), true);
}
TEST(MidiThru, beginEnablesThru)
{
midi.turnThruOff();
EXPECT_EQ(midi.getThruState(), false);
midi.begin();
EXPECT_EQ(midi.getThruState(), true);
}
TEST(MidiThru, setGet)
{
midi.turnThruOff();
EXPECT_EQ(midi.getThruState(), false);
midi.turnThruOn();
EXPECT_EQ(midi.getThruState(), true);
}
TEST(MidiThru, off) TEST(MidiThru, off)
{ {
midi.begin(MIDI_CHANNEL_OMNI); midi.begin(MIDI_CHANNEL_OMNI);