Control Surface master
MIDI Control Surface library for Arduino
MIDI-Input-Fine-Grained.ino

MIDI-Input-Fine-Grained

This is an example on how to attach your own callbacks for receiving MIDI input. This example has fine-grained callbacks, i.e. one for each message type (Note On, Note Off, Control Change, System Exclusive ...).

Boards:
AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, Teensy 3.x, ESP32

Connections

None.

Behavior

Mapping

None.

See also
MIDI-Input.ino
MIDI-Input-Fine-Grained-All-Callbacks.ino for a list of all callbacks for all message types

Written by PieterP, 2021-06-26
https://github.com/tttapa/Control-Surface

#include <Control_Surface.h> // Include the Control Surface library
// The MIDI over USB interface to use
// Custom MIDI callback that prints incoming messages.
struct MyMIDI_Callbacks : FineGrainedMIDI_Callbacks<MyMIDI_Callbacks> {
// Note how this ^ name is identical to the argument used here ^
// Function that is called whenever a MIDI Note Off message is received.
void onNoteOff(Channel channel, uint8_t note, uint8_t velocity, Cable cable) {
Serial << "Note Off: " << channel << ", note " << note << ", velocity "
<< velocity << ", " << cable << endl;
}
// Function that is called whenever a MIDI Note On message is received.
void onNoteOn(Channel channel, uint8_t note, uint8_t velocity, Cable cable) {
Serial << "Note On: " << channel << ", note " << note << ", velocity "
<< velocity << ", " << cable << endl;
}
} callback;
void setup() {
Serial.begin(115200); // For printing the messages
midi.begin(); // Initialize the MIDI interface
midi.setCallbacks(callback); // Attach the custom callback
}
void loop() {
midi.update(); // Continuously handle MIDI input
}
The main header file that includes all Control-Surface header files.
A type-safe class for MIDI USB Cable numbers.
Definition: Cable.hpp:13
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
void onNoteOff(Channel channel, uint8_t note, uint8_t velocity, Cable cable)
void onNoteOn(Channel channel, uint8_t note, uint8_t velocity, Cable cable)
void update() override
Read the MIDI interface and call the callback if a message was received.
void begin() override
Initialize the MIDI Interface.
void setCallbacks(MIDI_Callbacks *cb)
Set the callbacks that will be called when a MIDI message is received.
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Print & endl(Print &printer)
Definition: PrintStream.cpp:27
constexpr int8_t note(Note note, int8_t numOctave)
Get the MIDI note in the given octave.
Definition: Notes.hpp:56