Control Surface  1.2.0
MIDI Control Surface library for Arduino
MIDI-Input-Callback.ino

MIDI-Input-Callback

This is an example on how to attach your own callbacks for receiving MIDI input data.

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

Connections

None.

Behavior

Mapping

None.

Written by PieterP, 2019-08-07
https://github.com/tttapa/Control-Surface

#include <Control_Surface.h> // Include the Control Surface library
bool channelMessageCallback(ChannelMessage cm) {
Serial << F("Channel message: ") << hex << cm.header << ' ' << cm.data1 << ' '
<< cm.data2 << dec << F(" on cable ") << cm.CN << endl;
return true; // Return true to indicate that handling is done,
// and Control_Surface shouldn't handle it anymore.
// If you want Control_Surface to handle it as well,
// return false.
}
bool sysExMessageCallback(SysExMessage se) {
Serial << F("System Exclusive message: ") << hex;
for (size_t i = 0; i < se.length; ++i)
Serial << se.data[i] << ' ';
Serial << dec << F("on cable ") << se.CN << endl;
return true; // Return true to indicate that handling is done,
// and Control_Surface shouldn't handle it anymore.
// If you want Control_Surface to handle it as well,
// return false.
}
bool realTimeMessageCallback(RealTimeMessage rt) {
Serial << F("Real-Time message: ") << hex << rt.message << dec
<< F(" on cable ") << rt.CN << endl;
return true; // Return true to indicate that handling is done,
// and Control_Surface shouldn't handle it anymore.
// If you want Control_Surface to handle it as well,
// return false.
}
void setup() {
Serial.begin(115200);
Control_Surface.setMIDIInputCallbacks(channelMessageCallback, //
sysExMessageCallback, //
realTimeMessageCallback); //
// If you don't need all three callbacks, pass `nullptr` instead of a function
}
void loop() {
}
USBMIDI_Interface
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Definition: USBMIDI_Interface.hpp:41
SysExMessage
Definition: MIDI_MessageTypes.hpp:138
SysExMessage::data
const uint8_t * data
Definition: MIDI_MessageTypes.hpp:156
ChannelMessage::CN
uint8_t CN
USB MIDI cable number;.
Definition: MIDI_MessageTypes.hpp:87
AH::dec
Print & dec(Print &printer)
Definition: PrintStream.cpp:77
ChannelMessage::header
uint8_t header
MIDI status byte (message type and channel).
Definition: MIDI_MessageTypes.hpp:83
ChannelMessage::data2
uint8_t data2
First MIDI data byte.
Definition: MIDI_MessageTypes.hpp:85
Control_Surface.h
The main header file that includes all Control-Surface header files.
Control_Surface_::loop
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
Definition: Control_Surface_Class.cpp:68
Control_Surface
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
Definition: Control_Surface_Class.cpp:203
RealTimeMessage
Definition: MIDI_MessageTypes.hpp:173
AH::hex
Print & hex(Print &printer)
Definition: PrintStream.cpp:62
ChannelMessage::data1
uint8_t data1
First MIDI data byte.
Definition: MIDI_MessageTypes.hpp:84
SysExMessage::CN
uint8_t CN
Definition: MIDI_MessageTypes.hpp:158
Control_Surface_::setMIDIInputCallbacks
void setMIDIInputCallbacks(ChannelMessageCallback channelMessageCallback, SysExMessageCallback sysExMessageCallback, RealTimeMessageCallback realTimeMessageCallback)
Set the MIDI input callbacks.
Definition: Control_Surface_Class.hpp:153
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23
ChannelMessage
Definition: MIDI_MessageTypes.hpp:72
RealTimeMessage::CN
uint8_t CN
Definition: MIDI_MessageTypes.hpp:190
SysExMessage::length
uint8_t length
Definition: MIDI_MessageTypes.hpp:157
RealTimeMessage::message
uint8_t message
Definition: MIDI_MessageTypes.hpp:189
AH::endl
Print & endl(Print &printer)
Definition: PrintStream.cpp:27
Control_Surface_::begin
void begin()
Initialize the Control_Surface.
Definition: Control_Surface_Class.cpp:25