no chaining for private functions, added example
This commit is contained in:
parent
892f65a9ee
commit
c9d3b9b592
|
|
@ -0,0 +1,37 @@
|
|||
#include <MIDI.h>
|
||||
|
||||
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(2, INPUT);
|
||||
|
||||
MIDI // chaining MIDI commands - order is from top to bottom (turnThruOff,... begin)
|
||||
.turnThruOff()
|
||||
// using a lamdba function for this callbacks
|
||||
.setHandleNoteOn([](byte channel, byte note, byte velocity)
|
||||
{
|
||||
// Do whatever you want when a note is pressed.
|
||||
|
||||
// Try to keep your callbacks short (no delays ect)
|
||||
// otherwise it would slow down the loop() and have a bad impact
|
||||
// on real-time performance.
|
||||
})
|
||||
.setHandleNoteOff([](byte channel, byte note, byte velocity)
|
||||
{
|
||||
// Do something when the note is released.
|
||||
// Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
|
||||
})
|
||||
.begin(MIDI_CHANNEL_OMNI); // Initiate MIDI communications, listen to all channels
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Call MIDI.read the fastest you can for real-time performance.
|
||||
MIDI.read();
|
||||
|
||||
if (digitalRead(2))
|
||||
MIDI // chained sendNoteOn commands
|
||||
.sendNoteOn(42, 127, 1)
|
||||
.sendNoteOn(40, 54, 1);
|
||||
}
|
||||
|
|
@ -208,7 +208,7 @@ public:
|
|||
inline MidiInterface& disconnectCallbackFromType(MidiType inType);
|
||||
|
||||
private:
|
||||
MidiInterface& launchCallback();
|
||||
void launchCallback();
|
||||
|
||||
void (*mMessageCallback)(const MidiMessage& message) = nullptr;
|
||||
ErrorCallback mErrorCallback = nullptr;
|
||||
|
|
@ -244,7 +244,7 @@ public:
|
|||
inline MidiInterface& setThruFilterMode(Thru::Mode inThruFilterMode);
|
||||
|
||||
private:
|
||||
MidiInterface& thruFilter(byte inChannel);
|
||||
void thruFilter(byte inChannel);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// MIDI Parsing
|
||||
|
|
|
|||
|
|
@ -1341,7 +1341,7 @@ MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings,
|
|||
|
||||
// Private - launch callback function based on received type.
|
||||
template<class Transport, class Settings, class Platform>
|
||||
MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::launchCallback()
|
||||
void MidiInterface<Transport, Settings, Platform>::launchCallback()
|
||||
{
|
||||
if (mMessageCallback != 0) mMessageCallback(mMessage);
|
||||
|
||||
|
|
@ -1449,11 +1449,11 @@ inline MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Se
|
|||
// - Channel messages are passed to the output whether their channel
|
||||
// is matching the input channel and the filter setting
|
||||
template<class Transport, class Settings, class Platform>
|
||||
MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel)
|
||||
void MidiInterface<Transport, Settings, Platform>::thruFilter(Channel inChannel)
|
||||
{
|
||||
// If the feature is disabled, don't do anything.
|
||||
if (!mThruActivated || (mThruFilterMode == Thru::Off))
|
||||
return *this;
|
||||
return;
|
||||
|
||||
// First, check if the received message is Channel
|
||||
if (mMessage.type >= NoteOff && mMessage.type <= PitchBend)
|
||||
|
|
@ -1532,8 +1532,6 @@ MidiInterface<Transport, Settings, Platform>& MidiInterface<Transport, Settings,
|
|||
break; // LCOV_EXCL_LINE - Unreacheable code, but prevents unhandled case warning.
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
END_MIDI_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue