Skip to content

Commit c9d3b9b

Browse files
committed
no chaining for private functions, added example
1 parent 892f65a commit c9d3b9b

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

examples/Chaining/Chaining.ino

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <MIDI.h>
2+
3+
MIDI_CREATE_DEFAULT_INSTANCE();
4+
5+
void setup()
6+
{
7+
pinMode(2, INPUT);
8+
9+
MIDI // chaining MIDI commands - order is from top to bottom (turnThruOff,... begin)
10+
.turnThruOff()
11+
// using a lamdba function for this callbacks
12+
.setHandleNoteOn([](byte channel, byte note, byte velocity)
13+
{
14+
// Do whatever you want when a note is pressed.
15+
16+
// Try to keep your callbacks short (no delays ect)
17+
// otherwise it would slow down the loop() and have a bad impact
18+
// on real-time performance.
19+
})
20+
.setHandleNoteOff([](byte channel, byte note, byte velocity)
21+
{
22+
// Do something when the note is released.
23+
// Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
24+
})
25+
.begin(MIDI_CHANNEL_OMNI); // Initiate MIDI communications, listen to all channels
26+
}
27+
28+
void loop()
29+
{
30+
// Call MIDI.read the fastest you can for real-time performance.
31+
MIDI.read();
32+
33+
if (digitalRead(2))
34+
MIDI // chained sendNoteOn commands
35+
.sendNoteOn(42, 127, 1)
36+
.sendNoteOn(40, 54, 1);
37+
}

src/MIDI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class MidiInterface
208208
inline MidiInterface& disconnectCallbackFromType(MidiType inType);
209209

210210
private:
211-
MidiInterface& launchCallback();
211+
void launchCallback();
212212

213213
void (*mMessageCallback)(const MidiMessage& message) = nullptr;
214214
ErrorCallback mErrorCallback = nullptr;
@@ -244,7 +244,7 @@ class MidiInterface
244244
inline MidiInterface& setThruFilterMode(Thru::Mode inThruFilterMode);
245245

246246
private:
247-
MidiInterface& thruFilter(byte inChannel);
247+
void thruFilter(byte inChannel);
248248

249249
// -------------------------------------------------------------------------
250250
// MIDI Parsing

src/MIDI.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings,
13411341

13421342
// Private - launch callback function based on received type.
13431343
template<class Transport, class Settings, class Platform>
1344-
MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::launchCallback()
1344+
void MidiInterface<Transport, Settings, Platform>::launchCallback()
13451345
{
13461346
if (mMessageCallback != 0) mMessageCallback(mMessage);
13471347

@@ -1449,11 +1449,11 @@ inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Se
14491449
// - Channel messages are passed to the output whether their channel
14501450
// is matching the input channel and the filter setting
14511451
template<class Transport, class Settings, class Platform>
1452-
MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel)
1452+
void MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel)
14531453
{
14541454
// If the feature is disabled, don't do anything.
14551455
if (!mThruActivated || (mThruFilterMode == Thru::Off))
1456-
return *this;
1456+
return;
14571457

14581458
// First, check if the received message is Channel
14591459
if (mMessage.type >= NoteOff && mMessage.type <= PitchBend)
@@ -1532,8 +1532,6 @@ MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings,
15321532
break; // LCOV_EXCL_LINE - Unreacheable code, but prevents unhandled case warning.
15331533
}
15341534
}
1535-
1536-
return *this;
15371535
}
15381536

15391537
END_MIDI_NAMESPACE

0 commit comments

Comments
 (0)