File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < MIDI.h>
2
+
3
+ using Message = midi::Message<midi::DefaultSettings::SysExMaxSize>;
4
+
5
+ MIDI_CREATE_DEFAULT_INSTANCE ();
6
+
7
+ /* *
8
+ * This example shows how to make MIDI processors.
9
+ *
10
+ * The `filter` function defines whether to forward an incoming
11
+ * MIDI message to the output.
12
+ *
13
+ * The `map` function transforms the forwarded message before
14
+ * it is sent, allowing to change things.
15
+ *
16
+ * Here we will transform NoteOn messages into Program Change,
17
+ * allowing to use a keyboard to change patches on a MIDI device.
18
+ */
19
+
20
+ bool filter (const Message& message)
21
+ {
22
+ if (message.type == midi::NoteOn)
23
+ {
24
+ // Only forward NoteOn messages
25
+ return true ;
26
+ }
27
+ return false ;
28
+ }
29
+
30
+ Message map (const Message& message)
31
+ {
32
+ // Make a copy of the message
33
+ Message output (message);
34
+ if (message.type == midi::NoteOn)
35
+ {
36
+ output.type = midi::ProgramChange;
37
+ output.data2 = 0 ; // Not needed in ProgramChange
38
+ }
39
+ return output;
40
+ }
41
+
42
+ void setup ()
43
+ {
44
+ MIDI.begin ();
45
+ MIDI.setThruFilter (filter);
46
+ MIDI.setThruMap (map);
47
+ }
48
+
49
+ void loop ()
50
+ {
51
+ MIDI.read ();
52
+ }
You can’t perform that action at this time.
0 commit comments