From c9d3b9b5926abc63c24a8442c48a168cb599993f Mon Sep 17 00:00:00 2001 From: lathoub Date: Sun, 10 Oct 2021 15:33:28 +0200 Subject: [PATCH] no chaining for private functions, added example --- examples/Chaining/Chaining.ino | 37 ++++++++++++++++++++++++++++++++++ src/MIDI.h | 4 ++-- src/MIDI.hpp | 8 +++----- 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 examples/Chaining/Chaining.ino diff --git a/examples/Chaining/Chaining.ino b/examples/Chaining/Chaining.ino new file mode 100644 index 0000000..be36ee9 --- /dev/null +++ b/examples/Chaining/Chaining.ino @@ -0,0 +1,37 @@ +#include + +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); +} diff --git a/src/MIDI.h b/src/MIDI.h index ebdccd0..f1e49f0 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -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 diff --git a/src/MIDI.hpp b/src/MIDI.hpp index 7f92c78..bb9ffc1 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -1341,7 +1341,7 @@ MidiInterface& MidiInterface -MidiInterface& MidiInterface::launchCallback() +void MidiInterface::launchCallback() { if (mMessageCallback != 0) mMessageCallback(mMessage); @@ -1449,11 +1449,11 @@ inline MidiInterface& MidiInterface -MidiInterface& MidiInterface::thruFilter(Channel inChannel) +void MidiInterface::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& MidiInterface