Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Dec 11, 2019
1 parent 791341e commit 19556f6
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* <https://forum.arduino.cc/index.php?topic=653004>
*
* 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 <Control_Surface.h>

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 &noteInput, 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();
}
13 changes: 13 additions & 0 deletions examples/examples.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,19 @@
* https://github.com/tttapa/Control-Surface
*/

/**
* @example "MIDI-Note-Callback-IR.ino"
*
* MIDI-Note-Callback-IR
* =====================
*
* <https://forum.arduino.cc/index.php?topic=653004>
*
* 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"
*
Expand Down
72 changes: 48 additions & 24 deletions src/MIDI_Inputs/NoteCCRange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ class GenericNoteCCRange
}
};

template <uint8_t RangeLen, class Callback = NoteCCRangeEmptyCallback>
using GenericNoteRange =
GenericNoteCCRange<MIDIInputElementNote, RangeLen, Callback>;

template <uint8_t RangeLen, class Callback = NoteCCRangeEmptyCallback>
using GenericCCRange =
GenericNoteCCRange<MIDIInputElementCC, RangeLen, Callback>;

template <class Callback = NoteCCRangeEmptyCallback>
using GenericNoteValue = GenericNoteCCRange<MIDIInputElementNote, 1, Callback>;

template <class Callback = NoteCCRangeEmptyCallback>
using GenericCCValue = GenericNoteCCRange<MIDIInputElementCC, 1, Callback>;

/**
* @brief MIDI Input Element that listens to a range of notes.
*
Expand All @@ -125,30 +139,28 @@ class GenericNoteCCRange
* The length of the range of notes to listen to.
*/
template <uint8_t RangeLen>
class NoteRange : public GenericNoteCCRange<MIDIInputElementNote, RangeLen> {
class NoteRange : public GenericNoteRange<RangeLen> {
public:
NoteRange(MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementNote, RangeLen>{address, {}} {}
: GenericNoteRange<RangeLen>{address, {}} {}
};

class NoteValue : public GenericNoteCCRange<MIDIInputElementNote, 1> {
class NoteValue : public GenericNoteValue<> {
public:
NoteValue(MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementNote, 1>{address, {}} {}
NoteValue(MIDICNChannelAddress address) : GenericNoteValue<>{address, {}} {}
};
using MIDINote[[deprecated("Use NoteValue instead")]] = NoteValue;

template <uint8_t RangeLen>
class CCRange : public GenericNoteCCRange<MIDIInputElementCC, RangeLen> {
class CCRange : public GenericCCRange<RangeLen> {
public:
CCRange(MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementCC, RangeLen>{address, {}} {}
: GenericCCRange<RangeLen>{address, {}} {}
};

class CCValue : public GenericNoteCCRange<MIDIInputElementCC, 1> {
class CCValue : public GenericCCValue<> {
public:
CCValue(MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementCC, 1>{address, {}} {}
CCValue(MIDICNChannelAddress address) : GenericCCValue<>{address, {}} {}
};

// -------------------------------------------------------------------------- //
Expand Down Expand Up @@ -197,40 +209,52 @@ class GenericNoteCCRange
void onBankSettingChange() override { this->callback.updateAll(*this); }
};

template <uint8_t RangeLen, uint8_t NumBanks,
class Callback = NoteCCRangeEmptyCallback>
using GenericNoteRange =
GenericNoteCCRange<MIDIInputElementNote, RangeLen, NumBanks, Callback>;

template <uint8_t RangeLen, uint8_t NumBanks,
class Callback = NoteCCRangeEmptyCallback>
using GenericCCRange =
GenericNoteCCRange<MIDIInputElementCC, RangeLen, NumBanks, Callback>;

template <uint8_t NumBanks, class Callback = NoteCCRangeEmptyCallback>
using GenericNoteValue =
GenericNoteCCRange<MIDIInputElementNote, 1, NumBanks, Callback>;

template <uint8_t NumBanks, class Callback = NoteCCRangeEmptyCallback>
using GenericCCValue =
GenericNoteCCRange<MIDIInputElementCC, 1, NumBanks, Callback>;

template <uint8_t RangeLen, uint8_t NumBanks>
class NoteRange
: public GenericNoteCCRange<MIDIInputElementNote, RangeLen, NumBanks> {
class NoteRange : public GenericNoteRange<RangeLen, NumBanks> {
public:
NoteRange(BankConfig<NumBanks> config, MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementNote, RangeLen, NumBanks>{
config, address, {}} {}
: GenericNoteRange<RangeLen, NumBanks>{config, address, {}} {}
};

template <uint8_t NumBanks>
class NoteValue : public GenericNoteCCRange<MIDIInputElementNote, 1, NumBanks> {
class NoteValue : public GenericNoteValue<NumBanks> {
public:
NoteValue(BankConfig<NumBanks> config, MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementNote, 1, NumBanks>{
config, address, {}} {}
: GenericNoteValue<NumBanks>{config, address, {}} {}
};
template <uint8_t NumBanks>
using MIDINote[[deprecated("Use NoteValue instead")]] = NoteValue<NumBanks>;

template <uint8_t RangeLen, uint8_t NumBanks>
class CCRange
: public GenericNoteCCRange<MIDIInputElementCC, RangeLen, NumBanks> {
class CCRange : public GenericCCRange<RangeLen, NumBanks> {
public:
CCRange(BankConfig<NumBanks> config, MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementCC, RangeLen, NumBanks>{
config, address, {}} {}
: GenericCCRange<RangeLen, NumBanks>{config, address, {}} {}
};

template <uint8_t NumBanks>
class CCValue : public GenericNoteCCRange<MIDIInputElementCC, 1, NumBanks> {
class CCValue : public GenericCCValue<NumBanks> {
public:
CCValue(BankConfig<NumBanks> config, MIDICNChannelAddress address)
: GenericNoteCCRange<MIDIInputElementCC, 1, NumBanks>{
config, address, {}} {}
: GenericCCValue<NumBanks>{config, address, {}} {}
};

} // namespace Bankable
Expand Down

0 comments on commit 19556f6

Please sign in to comment.