@@ -40,8 +40,6 @@ inline MidiInterface<Transport, Settings, Platform>::MidiInterface(Transport& in
40
40
, mPendingMessageIndex (0 )
41
41
, mCurrentRpnNumber (0xffff )
42
42
, mCurrentNrpnNumber (0xffff )
43
- , mThruActivated (true )
44
- , mThruFilterMode (Thru::Full)
45
43
, mLastMessageSentTime (0 )
46
44
, mLastMessageReceivedTime (0 )
47
45
, mSenderActiveSensingPeriodicity (0 )
@@ -93,9 +91,8 @@ MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings,
93
91
mMessage .data2 = 0 ;
94
92
mMessage .length = 0 ;
95
93
96
- mThruFilterMode = Thru::Full;
97
- mThruActivated = mTransport .thruActivated ;
98
-
94
+ mThruFilterCallback = thruOn;
95
+ mThruMapCallback = thruEcho;
99
96
return *this ;
100
97
}
101
98
@@ -819,7 +816,7 @@ inline bool MidiInterface<Transport, Settings, Platform>::read(Channel inChannel
819
816
if (channelMatch)
820
817
launchCallback ();
821
818
822
- thruFilter (inChannel );
819
+ thruFilter ();
823
820
824
821
return channelMatch;
825
822
}
@@ -1399,51 +1396,26 @@ void MidiInterface<Transport, Settings, Platform>::launchCallback()
1399
1396
@{
1400
1397
*/
1401
1398
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
-
1422
1399
template <class Transport , class Settings , class Platform >
1423
1400
inline bool MidiInterface<Transport, Settings, Platform>::getThruState() const
1424
1401
{
1425
- return mThruActivated ;
1402
+ return mThruFilterCallback != thruOff ;
1426
1403
}
1427
1404
1428
1405
template <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 )
1430
1407
{
1431
- mThruActivated = true ;
1432
- mThruFilterMode = inThruFilterMode;
1433
-
1408
+ mThruFilterCallback = fptr;
1434
1409
return *this ;
1435
1410
}
1436
1411
1437
1412
template <class Transport , class Settings , class Platform >
1438
1413
inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::turnThruOff()
1439
1414
{
1440
- mThruActivated = false ;
1441
- mThruFilterMode = Thru::Off;
1442
-
1415
+ mThruFilterCallback = thruOff;
1443
1416
return *this ;
1444
1417
}
1445
1418
1446
-
1447
1419
/* ! @} */ // End of doc group MIDI Thru
1448
1420
1449
1421
// This method is called upon reception of a message
@@ -1453,51 +1425,20 @@ inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Se
1453
1425
// - Channel messages are passed to the output whether their channel
1454
1426
// is matching the input channel and the filter setting
1455
1427
template <class Transport , class Settings , class Platform >
1456
- void MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel )
1428
+ void MidiInterface<Transport, Settings, Platform>::thruFilter()
1457
1429
{
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 );
1461
1434
1462
1435
// First, check if the received message is Channel
1463
1436
if (mMessage .type >= NoteOff && mMessage .type <= PitchBend)
1464
1437
{
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 );
1501
1442
}
1502
1443
else
1503
1444
{
@@ -1517,19 +1458,19 @@ void MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel)
1517
1458
1518
1459
case SystemExclusive:
1519
1460
// Send SysEx (0xf0 and 0xf7 are included in the buffer)
1520
- sendSysEx (getSysExArrayLength (), getSysExArray () , true );
1461
+ sendSysEx (thruMessage. getSysExSize (), thruMessage. sysexArray , true );
1521
1462
break ;
1522
1463
1523
1464
case SongSelect:
1524
- sendSongSelect (mMessage .data1 );
1465
+ sendSongSelect (thruMessage .data1 );
1525
1466
break ;
1526
1467
1527
1468
case SongPosition:
1528
- sendSongPosition (mMessage .data1 | ((unsigned )mMessage .data2 << 7 ));
1469
+ sendSongPosition (thruMessage .data1 | ((unsigned )thruMessage .data2 << 7 ));
1529
1470
break ;
1530
1471
1531
1472
case TimeCodeQuarterFrame:
1532
- sendTimeCodeQuarterFrame (mMessage .data1 ,mMessage .data2 );
1473
+ sendTimeCodeQuarterFrame (thruMessage .data1 ,thruMessage .data2 );
1533
1474
break ;
1534
1475
1535
1476
default :
0 commit comments