@@ -40,8 +40,6 @@ inline MidiInterface<Transport, Settings, Platform>::MidiInterface(Transport& in
4040 , mPendingMessageIndex (0 )
4141 , mCurrentRpnNumber (0xffff )
4242 , mCurrentNrpnNumber (0xffff )
43- , mThruActivated (true )
44- , mThruFilterMode (Thru::Full)
4543 , mLastMessageSentTime (0 )
4644 , mLastMessageReceivedTime (0 )
4745 , mSenderActiveSensingPeriodicity (0 )
@@ -93,9 +91,8 @@ MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings,
9391 mMessage .data2 = 0 ;
9492 mMessage .length = 0 ;
9593
96- mThruFilterMode = Thru::Full;
97- mThruActivated = mTransport .thruActivated ;
98-
94+ mThruFilterCallback = thruOn;
95+ mThruMapCallback = thruEcho;
9996 return *this ;
10097}
10198
@@ -819,7 +816,7 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
819816 if (channelMatch)
820817 launchCallback ();
821818
822- thruFilter (inChannel );
819+ thruFilter ();
823820
824821 return channelMatch;
825822}
@@ -1399,51 +1396,26 @@ void MidiInterface<Transport, Settings, Platform>::launchCallback()
13991396 @{
14001397 */
14011398
1402- /* ! \brief Set the filter for thru mirroring
1403- \param inThruFilterMode a filter mode
1404-
1405- @see Thru::Mode
1406- */
1407- template <class Transport , class Settings , class Platform >
1408- inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::setThruFilterMode(Thru::Mode inThruFilterMode)
1409- {
1410- mThruFilterMode = inThruFilterMode;
1411- mThruActivated = mThruFilterMode != Thru::Off;
1412-
1413- return *this ;
1414- }
1415-
1416- template <class Transport , class Settings , class Platform >
1417- inline Thru::Mode MidiInterface<Transport, Settings, Platform>::getFilterMode() const
1418- {
1419- return mThruFilterMode ;
1420- }
1421-
14221399template <class Transport , class Settings , class Platform >
14231400inline bool MidiInterface<Transport, Settings, Platform>::getThruState() const
14241401{
1425- return mThruActivated ;
1402+ return mThruFilterCallback != thruOff ;
14261403}
14271404
14281405template <class Transport , class Settings , class Platform >
1429- inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::turnThruOn(Thru::Mode inThruFilterMode )
1406+ inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::turnThruOn(ThruFilterCallback fptr )
14301407{
1431- mThruActivated = true ;
1432- mThruFilterMode = inThruFilterMode;
1433-
1408+ mThruFilterCallback = fptr;
14341409 return *this ;
14351410}
14361411
14371412template <class Transport , class Settings , class Platform >
14381413inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::turnThruOff()
14391414{
1440- mThruActivated = false ;
1441- mThruFilterMode = Thru::Off;
1442-
1415+ mThruFilterCallback = thruOff;
14431416 return *this ;
14441417}
14451418
1446-
14471419/* ! @} */ // End of doc group MIDI Thru
14481420
14491421// This method is called upon reception of a message
@@ -1453,51 +1425,20 @@ inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Se
14531425// - Channel messages are passed to the output whether their channel
14541426// is matching the input channel and the filter setting
14551427template <class Transport , class Settings , class Platform >
1456- void MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel )
1428+ void MidiInterface<Transport, Settings, Platform>::thruFilter()
14571429{
1458- // If the feature is disabled, don't do anything.
1459- if (!mThruActivated || (mThruFilterMode == Thru::Off))
1460- return ;
1430+ if (!mThruFilterCallback (mMessage ))
1431+ return ;
1432+
1433+ MidiMessage thruMessage = mThruMapCallback (mMessage );
14611434
14621435 // First, check if the received message is Channel
14631436 if (mMessage .type >= NoteOff && mMessage .type <= PitchBend)
14641437 {
1465- const bool filter_condition = ((mMessage .channel == inChannel) ||
1466- (inChannel == MIDI_CHANNEL_OMNI));
1467-
1468- // Now let's pass it to the output
1469- switch (mThruFilterMode )
1470- {
1471- case Thru::Full:
1472- send (mMessage .type ,
1473- mMessage .data1 ,
1474- mMessage .data2 ,
1475- mMessage .channel );
1476- break ;
1477-
1478- case Thru::SameChannel:
1479- if (filter_condition)
1480- {
1481- send (mMessage .type ,
1482- mMessage .data1 ,
1483- mMessage .data2 ,
1484- mMessage .channel );
1485- }
1486- break ;
1487-
1488- case Thru::DifferentChannel:
1489- if (!filter_condition)
1490- {
1491- send (mMessage .type ,
1492- mMessage .data1 ,
1493- mMessage .data2 ,
1494- mMessage .channel );
1495- }
1496- break ;
1497-
1498- default :
1499- break ;
1500- }
1438+ send (thruMessage.type ,
1439+ thruMessage.data1 ,
1440+ thruMessage.data2 ,
1441+ thruMessage.channel );
15011442 }
15021443 else
15031444 {
@@ -1517,19 +1458,19 @@ void MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel)
15171458
15181459 case SystemExclusive:
15191460 // Send SysEx (0xf0 and 0xf7 are included in the buffer)
1520- sendSysEx (getSysExArrayLength (), getSysExArray () , true );
1461+ sendSysEx (thruMessage. getSysExSize (), thruMessage. sysexArray , true );
15211462 break ;
15221463
15231464 case SongSelect:
1524- sendSongSelect (mMessage .data1 );
1465+ sendSongSelect (thruMessage .data1 );
15251466 break ;
15261467
15271468 case SongPosition:
1528- sendSongPosition (mMessage .data1 | ((unsigned )mMessage .data2 << 7 ));
1469+ sendSongPosition (thruMessage .data1 | ((unsigned )thruMessage .data2 << 7 ));
15291470 break ;
15301471
15311472 case TimeCodeQuarterFrame:
1532- sendTimeCodeQuarterFrame (mMessage .data1 ,mMessage .data2 );
1473+ sendTimeCodeQuarterFrame (thruMessage .data1 ,thruMessage .data2 );
15331474 break ;
15341475
15351476 default :
0 commit comments