Control Surface  1.1.1
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, 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:35
SysExMessage
Definition: MIDI_Parser.hpp:64
SysExMessage::data
const uint8_t * data
Definition: MIDI_Parser.hpp:72
ChannelMessage::CN
uint8_t CN
Definition: MIDI_Parser.hpp:52
ChannelMessage::header
uint8_t header
Definition: MIDI_Parser.hpp:48
ChannelMessage::data2
uint8_t data2
Definition: MIDI_Parser.hpp:50
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:48
Control_Surface
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
Definition: Control_Surface_Class.cpp:176
RealTimeMessage
Definition: MIDI_Parser.hpp:77
ChannelMessage::data1
uint8_t data1
Definition: MIDI_Parser.hpp:49
SysExMessage::CN
uint8_t CN
Definition: MIDI_Parser.hpp:74
Control_Surface_::setMIDIInputCallbacks
void setMIDIInputCallbacks(ChannelMessageCallback channelMessageCallback, SysExMessageCallback sysExMessageCallback, RealTimeMessageCallback realTimeMessageCallback)
Set the MIDI input callbacks.
Definition: Control_Surface_Class.hpp:118
hex
Print & hex(Print &printer)
Definition: PrintStream.cpp:62
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23
endl
Print & endl(Print &printer)
Definition: PrintStream.cpp:27
ChannelMessage
Definition: MIDI_Parser.hpp:47
RealTimeMessage::CN
uint8_t CN
Definition: MIDI_Parser.hpp:79
SysExMessage::length
uint8_t length
Definition: MIDI_Parser.hpp:73
dec
Print & dec(Print &printer)
Definition: PrintStream.cpp:77
RealTimeMessage::message
uint8_t message
Definition: MIDI_Parser.hpp:78
Control_Surface_::begin
void begin()
Initialize the Control_Surface.
Definition: Control_Surface_Class.cpp:25