diff --git a/examples/Other/Arduino-Forum/MIDI-Note-Callback-IR/MIDI-Note-Callback-IR.ino b/examples/Other/Arduino-Forum/MIDI-Note-Callback-IR/MIDI-Note-Callback-IR.ino new file mode 100644 index 0000000000..bbba4115c5 --- /dev/null +++ b/examples/Other/Arduino-Forum/MIDI-Note-Callback-IR/MIDI-Note-Callback-IR.ino @@ -0,0 +1,43 @@ +/** + * + * + * Listen to MIDI notes 0 and 1, and print when Note On events are received. + * This was initially intended to send IR remote commands when a note event + * is received for one of these notes. + */ + +#include + +USBMIDI_Interface midi; // MIDI Interface to use + +void sendIR(uint32_t cmd) { + Serial << "Send IR 0x" << hex << cmd << dec << endl; + // Implement this +} + +struct MyCallback final : SimpleNoteCCValueCallback { + // Function is called when note event for given range of notes is received. + void update(const INoteCCValue ¬eInput, uint8_t index) override { + if (noteInput.getValue(index) == 0) // check that velocity > 0 + return; + switch (index) { // index in the range of notes + case 0: sendIR(0xFFE01F); break; + case 1: sendIR(0xFF609F); break; + } + } +}; + +// Listen to a range of 2 notes, and use MyCallback. +GenericNoteRange<2, MyCallback> noteInput = { + 0, // first note number + MyCallback(), // callback to use +}; + +void setup() { + Serial.begin(115200); + Control_Surface.begin(); +} + +void loop() { + Control_Surface.loop(); +} diff --git a/examples/examples.dox b/examples/examples.dox index adfc10363e..37f79b9697 100644 --- a/examples/examples.dox +++ b/examples/examples.dox @@ -1476,6 +1476,19 @@ * https://github.com/tttapa/Control-Surface */ +/** + * @example "MIDI-Note-Callback-IR.ino" + * + * MIDI-Note-Callback-IR + * ===================== + * + * + * + * Listen to MIDI notes 0 and 1, and print when Note On events are received. + * This was initially intended to send IR remote commands when a note event + * is received for one of these notes. + */ + /** * @example "MIDI-Input-Callback.ino" * diff --git a/src/MIDI_Inputs/NoteCCRange.hpp b/src/MIDI_Inputs/NoteCCRange.hpp index 55fc68d8ec..54c5d54d89 100644 --- a/src/MIDI_Inputs/NoteCCRange.hpp +++ b/src/MIDI_Inputs/NoteCCRange.hpp @@ -117,6 +117,20 @@ class GenericNoteCCRange } }; +template +using GenericNoteRange = + GenericNoteCCRange; + +template +using GenericCCRange = + GenericNoteCCRange; + +template +using GenericNoteValue = GenericNoteCCRange; + +template +using GenericCCValue = GenericNoteCCRange; + /** * @brief MIDI Input Element that listens to a range of notes. * @@ -125,30 +139,28 @@ class GenericNoteCCRange * The length of the range of notes to listen to. */ template -class NoteRange : public GenericNoteCCRange { +class NoteRange : public GenericNoteRange { public: NoteRange(MIDICNChannelAddress address) - : GenericNoteCCRange{address, {}} {} + : GenericNoteRange{address, {}} {} }; -class NoteValue : public GenericNoteCCRange { +class NoteValue : public GenericNoteValue<> { public: - NoteValue(MIDICNChannelAddress address) - : GenericNoteCCRange{address, {}} {} + NoteValue(MIDICNChannelAddress address) : GenericNoteValue<>{address, {}} {} }; using MIDINote[[deprecated("Use NoteValue instead")]] = NoteValue; template -class CCRange : public GenericNoteCCRange { +class CCRange : public GenericCCRange { public: CCRange(MIDICNChannelAddress address) - : GenericNoteCCRange{address, {}} {} + : GenericCCRange{address, {}} {} }; -class CCValue : public GenericNoteCCRange { +class CCValue : public GenericCCValue<> { public: - CCValue(MIDICNChannelAddress address) - : GenericNoteCCRange{address, {}} {} + CCValue(MIDICNChannelAddress address) : GenericCCValue<>{address, {}} {} }; // -------------------------------------------------------------------------- // @@ -197,40 +209,52 @@ class GenericNoteCCRange void onBankSettingChange() override { this->callback.updateAll(*this); } }; +template +using GenericNoteRange = + GenericNoteCCRange; + +template +using GenericCCRange = + GenericNoteCCRange; + +template +using GenericNoteValue = + GenericNoteCCRange; + +template +using GenericCCValue = + GenericNoteCCRange; + template -class NoteRange - : public GenericNoteCCRange { +class NoteRange : public GenericNoteRange { public: NoteRange(BankConfig config, MIDICNChannelAddress address) - : GenericNoteCCRange{ - config, address, {}} {} + : GenericNoteRange{config, address, {}} {} }; template -class NoteValue : public GenericNoteCCRange { +class NoteValue : public GenericNoteValue { public: NoteValue(BankConfig config, MIDICNChannelAddress address) - : GenericNoteCCRange{ - config, address, {}} {} + : GenericNoteValue{config, address, {}} {} }; template using MIDINote[[deprecated("Use NoteValue instead")]] = NoteValue; template -class CCRange - : public GenericNoteCCRange { +class CCRange : public GenericCCRange { public: CCRange(BankConfig config, MIDICNChannelAddress address) - : GenericNoteCCRange{ - config, address, {}} {} + : GenericCCRange{config, address, {}} {} }; template -class CCValue : public GenericNoteCCRange { +class CCValue : public GenericCCValue { public: CCValue(BankConfig config, MIDICNChannelAddress address) - : GenericNoteCCRange{ - config, address, {}} {} + : GenericCCValue{config, address, {}} {} }; } // namespace Bankable