-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <MIDI.h> | ||
|
||
using Message = midi::Message<midi::DefaultSettings::SysExMaxSize>; | ||
|
||
MIDI_CREATE_DEFAULT_INSTANCE(); | ||
|
||
/** | ||
* This example shows how to make MIDI processors. | ||
* | ||
* The `filter` function defines whether to forward an incoming | ||
* MIDI message to the output. | ||
* | ||
* The `map` function transforms the forwarded message before | ||
* it is sent, allowing to change things. | ||
* | ||
* Here we will transform NoteOn messages into Program Change, | ||
* allowing to use a keyboard to change patches on a MIDI device. | ||
*/ | ||
|
||
bool filter(const Message& message) | ||
{ | ||
if (message.type == midi::NoteOn) | ||
{ | ||
// Only forward NoteOn messages | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
Message map(const Message& message) | ||
{ | ||
// Make a copy of the message | ||
Message output(message); | ||
if (message.type == midi::NoteOn) | ||
{ | ||
output.type = midi::ProgramChange; | ||
output.data2 = 0; // Not needed in ProgramChange | ||
} | ||
return output; | ||
} | ||
|
||
void setup() | ||
{ | ||
MIDI.begin(); | ||
MIDI.setThruFilter(filter); | ||
MIDI.setThruMap(map); | ||
} | ||
|
||
void loop() | ||
{ | ||
MIDI.read(); | ||
} |