This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
BluetoothMIDI_Interface Class Reference

Bluetooth Low Energy MIDI Interface for the ESP32. More...

#include <BluetoothMIDI_Interface.hpp>

Inheritance diagram for BluetoothMIDI_Interface:
Collaboration diagram for BluetoothMIDI_Interface:

Public Member Functions

 BluetoothMIDI_Interface ()
 
void begin () override
 Initialize the MIDI Interface. More...
 
void publish ()
 
MIDI_read_t read () override
 
template<size_t N>
void addToBuffer (const uint8_t(&data)[N])
 
void addToBuffer (const uint8_t *data, size_t len)
 
void update () override
 Read the MIDI interface and call the callback if a message is received. More...
 
void sendImpl (uint8_t m, uint8_t c, uint8_t d1, uint8_t d2, uint8_t cn) override
 Low-level function for sending a 3-byte MIDI message. More...
 
void sendImpl (uint8_t m, uint8_t c, uint8_t d1, uint8_t cn) override
 Low-level function for sending a 2-byte MIDI message. More...
 
void sendImpl (const uint8_t *data, size_t length, uint8_t cn) override
 Low-level function for sending a system exclusive MIDI message. More...
 
void sendImpl (uint8_t rt, uint8_t cn) override
 Low-level function for sending a single-byte MIDI message. More...
 
void parse (const uint8_t *const data, const size_t len)
 
void parse (uint8_t data)
 
BLEMIDIgetBLEMIDI ()
 
MIDI_ParsergetParser ()
 
ChannelMessage getChannelMessage ()
 Return the received channel message. More...
 
SysExMessage getSysExMessage () const
 Return the received system exclusive message. More...
 
uint8_t getCN () const
 Return the cable number of the received message. More...
 
void setCallbacks (MIDI_Callbacks *cb) override
 Set the callbacks that will be called when a MIDI message is received. More...
 
virtual void setCallbacks (MIDI_Callbacks *cb)=0
 Set the callbacks that will be called when a MIDI message is received. More...
 
void setCallbacks (MIDI_Callbacks &cb)
 Set the callbacks that will be called when a MIDI message is received. More...
 
void setCallbacks (MIDI_Callbacks &cb)
 Set the callbacks that will be called when a MIDI message is received. More...
 
void send (uint8_t m, uint8_t c, uint8_t d1, uint8_t d2)
 Send a 3-byte MIDI packet. More...
 
void send (uint8_t m, uint8_t c, uint8_t d1)
 Send a 2-byte MIDI packet. More...
 
void send (SysExMessage message)
 Send a MIDI System Exclusive message. More...
 
template<size_t N>
void send (const uint8_t(&sysexdata)[N], uint8_t cn=0)
 Send a MIDI System Exclusive message. More...
 
void send (uint8_t rt, uint8_t cn=0)
 Send a single-byte MIDI message. More...
 
void sendOnCable (uint8_t m, uint8_t c, uint8_t d1, uint8_t d2, uint8_t cn)
 Send a 3-byte MIDI packet with cable number. More...
 
void sendOnCable (uint8_t m, uint8_t c, uint8_t d1, uint8_t cn)
 Send a 2-byte MIDI packet with cable number. More...
 
void sendOnCable (uint8_t r, uint8_t cn)
 Send a single-byte MIDI packet with cable number. More...
 
void sendNoteOn (MIDICNChannelAddress address, uint8_t velocity)
 Send a MIDI Note On event. More...
 
void sendNoteOff (MIDICNChannelAddress address, uint8_t velocity)
 Send a MIDI Note Off event. More...
 
void sendKP (MIDICNChannelAddress address, uint8_t pressure)
 Send a MIDI Key Pressure event. More...
 
void sendCC (MIDICNChannelAddress address, uint8_t value)
 Send a MIDI Control Change event. More...
 
void sendPC (MIDICNChannelAddress address)
 Send a MIDI Program Change event. More...
 
void sendPC (MIDICNChannel address, uint8_t value)
 Send a MIDI Program Change event. More...
 
void sendCP (MIDICNChannel address, uint8_t pressure)
 Send a MIDI Channel Pressure event. More...
 
void sendPB (MIDICNChannel address, uint16_t value)
 Send a MIDI Pitch Bend event. More...
 
void setAsDefault ()
 Set this MIDI interface as the default interface. More...
 

Static Public Member Functions

static MIDI_InterfacegetDefault ()
 Return the default MIDI interface. More...
 

Protected Member Functions

bool dispatchMIDIEvent (MIDI_read_t event)
 

Private Member Functions

void onConnect (UNUSED_PARAM BLEServer *pServer) override
 
void onDisconnect (UNUSED_PARAM BLEServer *pServer) override
 
void onRead (BLECharacteristic *pCharacteristic) override
 
void onWrite (BLECharacteristic *pCharacteristic) override
 
bool hasSpaceFor (size_t bytes)
 
void onRealtimeMessage (uint8_t message)
 
void onChannelMessage ()
 
void onSysExMessage ()
 

Private Attributes

unsigned long startTime = 0
 
uint8_t buffer [BUFFER_LENGTH] = {}
 
size_t index = 0
 
SerialMIDI_Parser parser
 
BLEMIDI bleMidi
 
uint8_t connected = 0
 
MIDI_Callbackscallbacks = nullptr
 

Static Private Attributes

constexpr static unsigned long MAX_MESSAGE_TIME = 10000
 
constexpr static size_t BUFFER_LENGTH = 1024
 
static MIDI_InterfaceDefaultMIDI_Interface = nullptr
 

Detailed Description

Bluetooth Low Energy MIDI Interface for the ESP32.

Examples
VU-Meter-Bridge.ino.

Definition at line 15 of file BluetoothMIDI_Interface.hpp.

Constructor & Destructor Documentation

◆ BluetoothMIDI_Interface()

BluetoothMIDI_Interface::BluetoothMIDI_Interface ( )
inline

Definition at line 70 of file BluetoothMIDI_Interface.hpp.

Member Function Documentation

◆ onConnect()

void BluetoothMIDI_Interface::onConnect ( UNUSED_PARAM BLEServer *  pServer)
inlineoverrideprivate

Definition at line 21 of file BluetoothMIDI_Interface.hpp.

◆ onDisconnect()

void BluetoothMIDI_Interface::onDisconnect ( UNUSED_PARAM BLEServer *  pServer)
inlineoverrideprivate

Definition at line 25 of file BluetoothMIDI_Interface.hpp.

◆ onRead()

void BluetoothMIDI_Interface::onRead ( BLECharacteristic *  pCharacteristic)
inlineoverrideprivate

Definition at line 34 of file BluetoothMIDI_Interface.hpp.

◆ onWrite()

void BluetoothMIDI_Interface::onWrite ( BLECharacteristic *  pCharacteristic)
inlineoverrideprivate

Definition at line 38 of file BluetoothMIDI_Interface.hpp.

◆ hasSpaceFor()

bool BluetoothMIDI_Interface::hasSpaceFor ( size_t  bytes)
inlineprivate

Definition at line 67 of file BluetoothMIDI_Interface.hpp.

◆ begin()

void BluetoothMIDI_Interface::begin ( )
inlineoverridevirtual

Initialize the MIDI Interface.

Reimplemented from MIDI_Interface.

Definition at line 72 of file BluetoothMIDI_Interface.hpp.

◆ publish()

void BluetoothMIDI_Interface::publish ( )
inline

Definition at line 74 of file BluetoothMIDI_Interface.hpp.

◆ read()

MIDI_read_t BluetoothMIDI_Interface::read ( )
inlineoverridevirtual
Todo:
Documentation

Implements Parsing_MIDI_Interface.

Definition at line 85 of file BluetoothMIDI_Interface.hpp.

◆ addToBuffer() [1/2]

template<size_t N>
void BluetoothMIDI_Interface::addToBuffer ( const uint8_t(&)  data[N])
inline

Definition at line 91 of file BluetoothMIDI_Interface.hpp.

◆ addToBuffer() [2/2]

void BluetoothMIDI_Interface::addToBuffer ( const uint8_t *  data,
size_t  len 
)
inline

Definition at line 95 of file BluetoothMIDI_Interface.hpp.

◆ update()

void BluetoothMIDI_Interface::update ( )
inlineoverridevirtual

Read the MIDI interface and call the callback if a message is received.

Implements MIDI_Interface.

Definition at line 118 of file BluetoothMIDI_Interface.hpp.

◆ sendImpl() [1/4]

void BluetoothMIDI_Interface::sendImpl ( uint8_t  m,
uint8_t  c,
uint8_t  d1,
uint8_t  d2,
uint8_t  cn 
)
inlineoverridevirtual

Low-level function for sending a 3-byte MIDI message.

Implements MIDI_Interface.

Definition at line 123 of file BluetoothMIDI_Interface.hpp.

◆ sendImpl() [2/4]

void BluetoothMIDI_Interface::sendImpl ( uint8_t  m,
uint8_t  c,
uint8_t  d1,
uint8_t  cn 
)
inlineoverridevirtual

Low-level function for sending a 2-byte MIDI message.

Implements MIDI_Interface.

Definition at line 129 of file BluetoothMIDI_Interface.hpp.

◆ sendImpl() [3/4]

void BluetoothMIDI_Interface::sendImpl ( const uint8_t *  data,
size_t  length,
uint8_t  cn 
)
inlineoverridevirtual

Low-level function for sending a system exclusive MIDI message.

Implements MIDI_Interface.

Definition at line 135 of file BluetoothMIDI_Interface.hpp.

◆ sendImpl() [4/4]

void BluetoothMIDI_Interface::sendImpl ( uint8_t  rt,
uint8_t  cn 
)
inlineoverridevirtual

Low-level function for sending a single-byte MIDI message.

Implements MIDI_Interface.

Definition at line 141 of file BluetoothMIDI_Interface.hpp.

◆ parse() [1/2]

void BluetoothMIDI_Interface::parse ( const uint8_t *const  data,
const size_t  len 
)
inline

Definition at line 146 of file BluetoothMIDI_Interface.hpp.

◆ parse() [2/2]

void BluetoothMIDI_Interface::parse ( uint8_t  data)
inline

Definition at line 166 of file BluetoothMIDI_Interface.hpp.

◆ getBLEMIDI()

BLEMIDI& BluetoothMIDI_Interface::getBLEMIDI ( )
inline

Definition at line 171 of file BluetoothMIDI_Interface.hpp.

◆ getParser()

MIDI_Parser& Parsing_MIDI_Interface::getParser ( )
inlineinherited

Definition at line 201 of file MIDI_Interface.hpp.

◆ getChannelMessage()

ChannelMessage Parsing_MIDI_Interface::getChannelMessage ( )
inherited

Return the received channel message.

Definition at line 120 of file MIDI_Interface.cpp.

◆ getSysExMessage()

SysExMessage Parsing_MIDI_Interface::getSysExMessage ( ) const
inherited

Return the received system exclusive message.

Examples
SysEx-Send-Receive.ino.

Definition at line 124 of file MIDI_Interface.cpp.

◆ getCN()

uint8_t Parsing_MIDI_Interface::getCN ( ) const
inherited

Return the cable number of the received message.

Definition at line 128 of file MIDI_Interface.cpp.

◆ setCallbacks() [1/4]

void Parsing_MIDI_Interface::setCallbacks ( MIDI_Callbacks cb)
inlineoverridevirtualinherited

Set the callbacks that will be called when a MIDI message is received.

Parameters
cbA pointer to an object that implements the MIDI_Callbacks class.

Implements MIDI_Interface.

Examples
SysEx-Send-Receive.ino.

Definition at line 220 of file MIDI_Interface.hpp.

◆ setCallbacks() [2/4]

virtual void MIDI_Interface::setCallbacks
inherited

Set the callbacks that will be called when a MIDI message is received.

Parameters
cbA pointer to an object that implements the MIDI_Callbacks class.

◆ setCallbacks() [3/4]

void MIDI_Interface::setCallbacks
inlineinherited

Set the callbacks that will be called when a MIDI message is received.

Parameters
cbA reference to an object that implements the MIDI_Callbacks class.

Definition at line 159 of file MIDI_Interface.hpp.

◆ setCallbacks() [4/4]

void MIDI_Interface::setCallbacks ( MIDI_Callbacks cb)
inlineinherited

Set the callbacks that will be called when a MIDI message is received.

Parameters
cbA reference to an object that implements the MIDI_Callbacks class.

Definition at line 159 of file MIDI_Interface.hpp.

◆ dispatchMIDIEvent()

bool Parsing_MIDI_Interface::dispatchMIDIEvent ( MIDI_read_t  event)
protectedinherited

Definition at line 143 of file MIDI_Interface.cpp.

◆ onRealtimeMessage()

void Parsing_MIDI_Interface::onRealtimeMessage ( uint8_t  message)
privateinherited

Definition at line 154 of file MIDI_Interface.cpp.

◆ onChannelMessage()

void Parsing_MIDI_Interface::onChannelMessage ( )
privateinherited

Definition at line 159 of file MIDI_Interface.cpp.

◆ onSysExMessage()

void Parsing_MIDI_Interface::onSysExMessage ( )
privateinherited

Definition at line 164 of file MIDI_Interface.cpp.

◆ send() [1/5]

void MIDI_Interface::send ( uint8_t  m,
uint8_t  c,
uint8_t  d1,
uint8_t  d2 
)
inherited

Send a 3-byte MIDI packet.

Parameters
mMIDI message type. [0x80, 0xE0]
cThe MIDI channel. [1, 16]
d1The first data byte. [0, 127]
d2The second data byte. [0, 127]
Examples
SysEx-Send-Receive.ino.

Definition at line 22 of file MIDI_Interface.cpp.

◆ send() [2/5]

void MIDI_Interface::send ( uint8_t  m,
uint8_t  c,
uint8_t  d1 
)
inherited

Send a 2-byte MIDI packet.

Parameters
mMIDI message type. [0x80, 0xE0]
cThe MIDI channel. [1, 16]
d1The first data byte. [0, 127]

Definition at line 26 of file MIDI_Interface.cpp.

◆ send() [3/5]

void MIDI_Interface::send ( SysExMessage  message)
inherited

Send a MIDI System Exclusive message.

Definition at line 100 of file MIDI_Interface.cpp.

◆ send() [4/5]

template<size_t N>
void MIDI_Interface::send ( const uint8_t(&)  sysexdata[N],
uint8_t  cn = 0 
)
inlineinherited

Send a MIDI System Exclusive message.

Definition at line 120 of file MIDI_Interface.hpp.

◆ send() [5/5]

void MIDI_Interface::send ( uint8_t  rt,
uint8_t  cn = 0 
)
inherited

Send a single-byte MIDI message.

Definition at line 109 of file MIDI_Interface.cpp.

◆ sendOnCable() [1/3]

void MIDI_Interface::sendOnCable ( uint8_t  m,
uint8_t  c,
uint8_t  d1,
uint8_t  d2,
uint8_t  cn 
)
inherited

Send a 3-byte MIDI packet with cable number.

Parameters
mMIDI message type. [0x80, 0xE0]
cThe MIDI channel. [1, 16]
d1The first data byte. [0, 127]
d2The second data byte. [0, 127]
cnThe MIDI Cable Number. [0, 15]

Definition at line 30 of file MIDI_Interface.cpp.

◆ sendOnCable() [2/3]

void MIDI_Interface::sendOnCable ( uint8_t  m,
uint8_t  c,
uint8_t  d1,
uint8_t  cn 
)
inherited

Send a 2-byte MIDI packet with cable number.

Parameters
mMIDI message type. [0x80, 0xE0]
cThe MIDI channel. [1, 16]
d1The first data byte. [0, 127]
cnThe MIDI Cable Number. [0, 15]

Definition at line 42 of file MIDI_Interface.cpp.

◆ sendOnCable() [3/3]

void MIDI_Interface::sendOnCable ( uint8_t  r,
uint8_t  cn 
)
inherited

Send a single-byte MIDI packet with cable number.

Parameters
rThe MIDI byte to send.
cnThe MIDI Cable Number. [0, 15]

Definition at line 52 of file MIDI_Interface.cpp.

◆ sendNoteOn()

void MIDI_Interface::sendNoteOn ( MIDICNChannelAddress  address,
uint8_t  velocity 
)
inherited

Send a MIDI Note On event.

Definition at line 58 of file MIDI_Interface.cpp.

◆ sendNoteOff()

void MIDI_Interface::sendNoteOff ( MIDICNChannelAddress  address,
uint8_t  velocity 
)
inherited

Send a MIDI Note Off event.

Definition at line 64 of file MIDI_Interface.cpp.

◆ sendKP()

void MIDI_Interface::sendKP ( MIDICNChannelAddress  address,
uint8_t  pressure 
)
inherited

Send a MIDI Key Pressure event.

Definition at line 70 of file MIDI_Interface.cpp.

◆ sendCC()

void MIDI_Interface::sendCC ( MIDICNChannelAddress  address,
uint8_t  value 
)
inherited

Send a MIDI Control Change event.

Definition at line 75 of file MIDI_Interface.cpp.

◆ sendPC() [1/2]

void MIDI_Interface::sendPC ( MIDICNChannelAddress  address)
inherited

Send a MIDI Program Change event.

Definition at line 85 of file MIDI_Interface.cpp.

◆ sendPC() [2/2]

void MIDI_Interface::sendPC ( MIDICNChannel  address,
uint8_t  value 
)
inherited

Send a MIDI Program Change event.

Definition at line 80 of file MIDI_Interface.cpp.

◆ sendCP()

void MIDI_Interface::sendCP ( MIDICNChannel  address,
uint8_t  pressure 
)
inherited

Send a MIDI Channel Pressure event.

Definition at line 90 of file MIDI_Interface.cpp.

◆ sendPB()

void MIDI_Interface::sendPB ( MIDICNChannel  address,
uint16_t  value 
)
inherited

Send a MIDI Pitch Bend event.

Definition at line 95 of file MIDI_Interface.cpp.

◆ getDefault()

MIDI_Interface * MIDI_Interface::getDefault ( )
staticinherited

Return the default MIDI interface.

Definition at line 18 of file MIDI_Interface.cpp.

◆ setAsDefault()

void MIDI_Interface::setAsDefault ( )
inherited

Set this MIDI interface as the default interface.

Definition at line 16 of file MIDI_Interface.cpp.

Member Data Documentation

◆ MAX_MESSAGE_TIME

constexpr static unsigned long BluetoothMIDI_Interface::MAX_MESSAGE_TIME = 10000
staticconstexprprivate

Definition at line 52 of file BluetoothMIDI_Interface.hpp.

◆ startTime

unsigned long BluetoothMIDI_Interface::startTime = 0
private

Definition at line 54 of file BluetoothMIDI_Interface.hpp.

◆ BUFFER_LENGTH

constexpr static size_t BluetoothMIDI_Interface::BUFFER_LENGTH = 1024
staticconstexprprivate

Definition at line 56 of file BluetoothMIDI_Interface.hpp.

◆ buffer

uint8_t BluetoothMIDI_Interface::buffer[BUFFER_LENGTH] = {}
private

Definition at line 58 of file BluetoothMIDI_Interface.hpp.

◆ index

size_t BluetoothMIDI_Interface::index = 0
private

Definition at line 59 of file BluetoothMIDI_Interface.hpp.

◆ parser

SerialMIDI_Parser BluetoothMIDI_Interface::parser
private

Definition at line 61 of file BluetoothMIDI_Interface.hpp.

◆ bleMidi

BLEMIDI BluetoothMIDI_Interface::bleMidi
private

Definition at line 63 of file BluetoothMIDI_Interface.hpp.

◆ connected

uint8_t BluetoothMIDI_Interface::connected = 0
private

Definition at line 65 of file BluetoothMIDI_Interface.hpp.

◆ callbacks

MIDI_Callbacks* Parsing_MIDI_Interface::callbacks = nullptr
privateinherited

Definition at line 240 of file MIDI_Interface.hpp.

◆ DefaultMIDI_Interface

MIDI_Interface * MIDI_Interface::DefaultMIDI_Interface = nullptr
staticprivateinherited

Definition at line 182 of file MIDI_Interface.hpp.


The documentation for this class was generated from the following file: