Control Surface  1.2.0
MIDI Control Surface library for Arduino
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Control_Surface_ Class Reference

This class ensures initialization, updating, and interaction between all other classes, it's the glue that holds everything together. More...

#include <Control_Surface/Control_Surface_Class.hpp>

+ Inheritance diagram for Control_Surface_:
+ Collaboration diagram for Control_Surface_:

Public Member Functions

void begin ()
 Initialize the Control_Surface. More...
 
void loop ()
 Update all MIDI elements, send MIDI events and read MIDI input. More...
 
bool connectDefaultMIDI_Interface ()
 Connect Control Surface to the default MIDI interface. More...
 
void disconnectMIDI_Interfaces ()
 Disconnect Control Surface from the MIDI interfaces it's connected to. More...
 
MIDI_Sender< Control_Surface_ > & MIDI ()
 Get a reference to the MIDI sender. More...
 
void updateMidiInput ()
 Update all MIDI interfaces to receive new MIDI events. More...
 
void updateInputs ()
 Update all MIDIInputElements. More...
 
void updateDisplays ()
 Clear, draw and display all displays. More...
 

Protected Attributes

MIDI_PipesourcePipe = nullptr
 
MIDI_PipesinkPipe = nullptr
 

Private Member Functions

void sendImpl (uint8_t header, uint8_t d1, uint8_t d2, uint8_t cn)
 Low-level function for sending a 3-byte MIDI message. More...
 
void sendImpl (uint8_t header, uint8_t d1, uint8_t cn)
 Low-level function for sending a 2-byte MIDI message. More...
 
void sendImpl (const uint8_t *data, size_t length, uint8_t cn)
 Low-level function for sending a system exclusive MIDI message. More...
 
void sendImpl (uint8_t rt, uint8_t cn)
 Low-level function for sending a single-byte MIDI message. More...
 
void sinkMIDIfromPipe (ChannelMessage msg) override
 Accept an incoming MIDI Channel message. More...
 
void sinkMIDIfromPipe (SysExMessage msg) override
 Accept an incoming MIDI System Exclusive message. More...
 
void sinkMIDIfromPipe (RealTimeMessage msg) override
 Accept an incoming MIDI Real-Time message. More...
 
virtual void lockDownstream (cn_t cn, bool lock)
 Base case for recursive lock function. More...
 
virtual MIDI_SinkgetFinalSink ()
 Base case for recursive function. More...
 
void disconnectSourcePipesShallow ()
 Disconnect only the first pipe connected to this sink. More...
 
virtual MIDI_SourcegetInitialSource ()
 Base case for recursive function. More...
 
void disconnectSinkPipesShallow ()
 Disconnect only the first pipe connected to this source. More...
 

Private Attributes

Timer< micros > potentiometerTimer = {AH::FILTERED_INPUT_UPDATE_INTERVAL}
 A timer to know when to update the analog inputs. More...
 
Timer< micros > displayTimer = {1000000UL / MAX_FPS}
 A timer to know when to refresh the displays. More...
 
ChannelMessageCallback channelMessageCallback = nullptr
 
SysExMessageCallback sysExMessageCallback = nullptr
 
RealTimeMessageCallback realTimeMessageCallback = nullptr
 
MIDI_Pipe inpipe
 
MIDI_Pipe outpipe
 

Singleton boilerplate

 Control_Surface_ (Control_Surface_ const &)=delete
 Copying is not allowed. More...
 
Control_Surface_operator= (Control_Surface_ const &)=delete
 Copying is not allowed. More...
 
static Control_Surface_getInstance ()
 Return the static Control_Surface_ instance. More...
 
 Control_Surface_ ()=default
 Control_Surface_ is a singleton, so the constructor is private. More...
 

MIDI Input Callbacks

using ChannelMessageCallback = bool(*)(ChannelMessage)
 Callback function type for channel messages. More...
 
using SysExMessageCallback = bool(*)(SysExMessage)
 Callback function type for SysEx messages. More...
 
using RealTimeMessageCallback = bool(*)(RealTimeMessage)
 Callback function type for Real-Time messages. More...
 
void setMIDIInputCallbacks (ChannelMessageCallback channelMessageCallback, SysExMessageCallback sysExMessageCallback, RealTimeMessageCallback realTimeMessageCallback)
 Set the MIDI input callbacks. More...
 

Sending MIDI

void send (MIDIMessageType m, Channel c, uint8_t d1, uint8_t d2, Cable cable=CABLE_1)
 Send a 3-byte MIDI packet. More...
 
void send (MIDIMessageType m, Channel c, uint8_t d1, Cable cable=CABLE_1)
 Send a 2-byte MIDI packet. More...
 
void send (ChannelMessage message)
 Send a MIDI Channel Message. More...
 
void send (SysExMessage message)
 Send a MIDI System Exclusive message. More...
 
void send (const uint8_t(&sysexdata)[N], Cable cable=CABLE_1)
 Send a MIDI System Exclusive message. More...
 
void send (RealTimeMessage message)
 Send a MIDI Real-Time message. More...
 
void send (MIDIMessageType rt, Cable cable=CABLE_1)
 Send a single-byte MIDI message. More...
 
void sendOnCable (MIDIMessageType m, Channel c, uint8_t d1, uint8_t d2, Cable cable)
 Send a 3-byte MIDI packet with cable number. More...
 
void sendOnCable (MIDIMessageType m, Channel c, uint8_t d1, Cable cable)
 Send a 2-byte MIDI packet with cable number. More...
 
void sendOnCable (MIDIMessageType rt, Cable cable)
 Send a single-byte MIDI packet with cable number. More...
 
void sendNoteOn (MIDIAddress address, uint8_t velocity)
 Send a MIDI Note On event. More...
 
void sendNoteOff (MIDIAddress address, uint8_t velocity)
 Send a MIDI Note Off event. More...
 
void sendKP (MIDIAddress address, uint8_t pressure)
 Send a MIDI Key Pressure event. More...
 
void sendCC (MIDIAddress address, uint8_t value)
 Send a MIDI Control Change event. More...
 
void sendPC (MIDIAddress address)
 Send a MIDI Program Change event. More...
 
void sendPC (MIDIChannelCN address, uint8_t value)
 Send a MIDI Program Change event. More...
 
void sendCP (MIDIChannelCN address, uint8_t pressure)
 Send a MIDI Channel Pressure event. More...
 
void sendPB (MIDIChannelCN address, uint16_t value)
 Send a MIDI Pitch Bend event. More...
 

Connecting and disconnecting MIDI Pipes

void connectSourcePipe (MIDI_Pipe *source)
 Fully connect a source pipe to this sink. More...
 
void disconnectSourcePipes ()
 Disconnect all source pipes that sink to this sink (recursively). More...
 
bool disconnect (TrueMIDI_Source &source)
 Disconnect the given source from this sink. More...
 
bool hasSourcePipe () const
 Check if this sink is connected to a source pipe. More...
 

Sending data over a MIDI Pipe

void sourceMIDItoPipe (ChannelMessage)
 Send a MIDI Channel Message. More...
 
void sourceMIDItoPipe (SysExMessage)
 Send a MIDI System Exclusive message. More...
 
void sourceMIDItoPipe (RealTimeMessage)
 Send a MIDI Real-Time message. More...
 
void exclusive (cn_t cn, bool exclusive=true)
 Enter or exit exclusive mode for the given cable number. More...
 
bool canWrite (cn_t cn) const
 Check if this source can write to the sinks it connects to. More...
 

Connecting and disconnecting MIDI Pipes

bool disconnect (TrueMIDI_Sink &sink)
 Disconnect the given sink from this source. More...
 
void connectSinkPipe (MIDI_Pipe *sink)
 Fully connect a sink pipe to this source. More...
 
void disconnectSinkPipes ()
 Disconnect all sink pipes that this source sinks to (recursively). More...
 
bool hasSinkPipe () const
 Check if this source is connected to a sink pipe. More...
 

Detailed Description

This class ensures initialization, updating, and interaction between all other classes, it's the glue that holds everything together.

Definition at line 26 of file Control_Surface_Class.hpp.

Member Typedef Documentation

◆ ChannelMessageCallback

Callback function type for channel messages.

Return true if handling is done in the user-provided callback, false if Control_Surface should handle the message.

Definition at line 141 of file Control_Surface_Class.hpp.

◆ SysExMessageCallback

Callback function type for SysEx messages.

Return true if handling is done in the user-provided callback, false if Control_Surface should handle the message.

Definition at line 145 of file Control_Surface_Class.hpp.

◆ RealTimeMessageCallback

Callback function type for Real-Time messages.

Return true if handling is done in the user-provided callback, false if Control_Surface should handle the message.

Definition at line 149 of file Control_Surface_Class.hpp.

Constructor & Destructor Documentation

◆ Control_Surface_() [1/2]

Control_Surface_ ( Control_Surface_ const &  )
delete

Copying is not allowed.

◆ Control_Surface_() [2/2]

Control_Surface_ ( )
privatedefault

Control_Surface_ is a singleton, so the constructor is private.

Member Function Documentation

◆ operator=()

Control_Surface_& operator= ( Control_Surface_ const &  )
delete

Copying is not allowed.

◆ getInstance()

Control_Surface_ & getInstance ( )
static

Return the static Control_Surface_ instance.

(Control_Surface_ is a singleton.)

Definition at line 20 of file Control_Surface_Class.cpp.

◆ begin()

void begin ( )

◆ loop()

void loop ( )

◆ connectDefaultMIDI_Interface()

bool connectDefaultMIDI_Interface ( )

Connect Control Surface to the default MIDI interface.

Definition at line 50 of file Control_Surface_Class.cpp.

◆ disconnectMIDI_Interfaces()

void disconnectMIDI_Interfaces ( )

Disconnect Control Surface from the MIDI interfaces it's connected to.

Definition at line 63 of file Control_Surface_Class.cpp.

◆ MIDI()

MIDI_Sender<Control_Surface_>& MIDI ( )
inline

Get a reference to the MIDI sender.

Deprecated:
Use Control_Surface.send(...) directly instead of Control_Surface.MIDI().send(...).

Definition at line 85 of file Control_Surface_Class.hpp.

◆ updateMidiInput()

void updateMidiInput ( )

Update all MIDI interfaces to receive new MIDI events.

Definition at line 80 of file Control_Surface_Class.cpp.

◆ updateInputs()

void updateInputs ( )

Update all MIDIInputElements.

Definition at line 177 of file Control_Surface_Class.cpp.

◆ updateDisplays()

void updateDisplays ( )

Clear, draw and display all displays.

Examples
2.VU-Meter-OLED-USB-DAC.ino.

Definition at line 185 of file Control_Surface_Class.cpp.

◆ sendImpl() [1/4]

void sendImpl ( uint8_t  header,
uint8_t  d1,
uint8_t  d2,
uint8_t  cn 
)
private

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

Definition at line 84 of file Control_Surface_Class.cpp.

◆ sendImpl() [2/4]

void sendImpl ( uint8_t  header,
uint8_t  d1,
uint8_t  cn 
)
private

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

Definition at line 88 of file Control_Surface_Class.cpp.

◆ sendImpl() [3/4]

void sendImpl ( const uint8_t *  data,
size_t  length,
uint8_t  cn 
)
private

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

Definition at line 91 of file Control_Surface_Class.cpp.

◆ sendImpl() [4/4]

void sendImpl ( uint8_t  rt,
uint8_t  cn 
)
private

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

Definition at line 95 of file Control_Surface_Class.cpp.

◆ sinkMIDIfromPipe() [1/3]

void sinkMIDIfromPipe ( ChannelMessage  )
overrideprivatevirtual

Accept an incoming MIDI Channel message.

Implements MIDI_Sink.

Definition at line 99 of file Control_Surface_Class.cpp.

◆ sinkMIDIfromPipe() [2/3]

void sinkMIDIfromPipe ( SysExMessage  )
overrideprivatevirtual

Accept an incoming MIDI System Exclusive message.

Implements MIDI_Sink.

Definition at line 151 of file Control_Surface_Class.cpp.

◆ sinkMIDIfromPipe() [3/3]

void sinkMIDIfromPipe ( RealTimeMessage  )
overrideprivatevirtual

Accept an incoming MIDI Real-Time message.

Implements MIDI_Sink.

Definition at line 169 of file Control_Surface_Class.cpp.

◆ setMIDIInputCallbacks()

void setMIDIInputCallbacks ( ChannelMessageCallback  channelMessageCallback,
SysExMessageCallback  sysExMessageCallback,
RealTimeMessageCallback  realTimeMessageCallback 
)
inline

Set the MIDI input callbacks.

Examples
Mackie-Control-Universal-Reverse-Engineering.ino, and MIDI-Input-Callback.ino.

Definition at line 153 of file Control_Surface_Class.hpp.

◆ send() [1/7]

void send ( MIDIMessageType  m,
Channel  c,
uint8_t  d1,
uint8_t  d2,
Cable  cable = CABLE_1 
)
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]
cableThe MIDI Cable Number. [1, 16]

Definition at line 38 of file MIDI_Interface.ipp.

◆ send() [2/7]

void send ( MIDIMessageType  m,
Channel  c,
uint8_t  d1,
Cable  cable = CABLE_1 
)
inherited

Send a 2-byte MIDI packet.

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

Definition at line 53 of file MIDI_Interface.ipp.

◆ send() [3/7]

void send ( ChannelMessage  message)
inherited

Send a MIDI Channel Message.

Definition at line 113 of file MIDI_Interface.ipp.

◆ send() [4/7]

void send ( SysExMessage  message)
inherited

Send a MIDI System Exclusive message.

Definition at line 115 of file MIDI_Interface.ipp.

◆ send() [5/7]

void send ( const uint8_t(&)  sysexdata[N],
Cable  cable = CABLE_1 
)
inlineinherited

Send a MIDI System Exclusive message.

Definition at line 118 of file MIDI_Interface.hpp.

◆ send() [6/7]

void send ( RealTimeMessage  message)
inherited

Send a MIDI Real-Time message.

Definition at line 122 of file MIDI_Interface.ipp.

◆ send() [7/7]

void send ( MIDIMessageType  rt,
Cable  cable = CABLE_1 
)
inherited

Send a single-byte MIDI message.

Definition at line 124 of file MIDI_Interface.ipp.

◆ sendOnCable() [1/3]

void sendOnCable ( MIDIMessageType  m,
Channel  c,
uint8_t  d1,
uint8_t  d2,
Cable  cable 
)
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]
cableThe MIDI Cable Number. [1, 16]

Definition at line 69 of file MIDI_Interface.ipp.

◆ sendOnCable() [2/3]

void sendOnCable ( MIDIMessageType  m,
Channel  c,
uint8_t  d1,
Cable  cable 
)
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]
cableThe MIDI Cable Number. [1, 16]

Definition at line 84 of file MIDI_Interface.ipp.

◆ sendOnCable() [3/3]

void sendOnCable ( MIDIMessageType  rt,
Cable  cable 
)
inherited

Send a single-byte MIDI packet with cable number.

Parameters
rtThe MIDI byte to send.
cableThe MIDI Cable Number. [1, 16]

Definition at line 94 of file MIDI_Interface.ipp.

◆ sendNoteOn()

void sendNoteOn ( MIDIAddress  address,
uint8_t  velocity 
)
inherited

Send a MIDI Note On event.

Examples
Custom-MIDI-Output-Element.ino, and Custom-MIDI-Sender.ino.

Definition at line 97 of file MIDI_Interface.ipp.

◆ sendNoteOff()

void sendNoteOff ( MIDIAddress  address,
uint8_t  velocity 
)
inherited

Send a MIDI Note Off event.

Examples
Custom-MIDI-Output-Element.ino, and Custom-MIDI-Sender.ino.

Definition at line 99 of file MIDI_Interface.ipp.

◆ sendKP()

void sendKP ( MIDIAddress  address,
uint8_t  pressure 
)
inherited

Send a MIDI Key Pressure event.

Definition at line 101 of file MIDI_Interface.ipp.

◆ sendCC()

void sendCC ( MIDIAddress  address,
uint8_t  value 
)
inherited

Send a MIDI Control Change event.

Definition at line 103 of file MIDI_Interface.ipp.

◆ sendPC() [1/2]

void sendPC ( MIDIAddress  address)
inherited

Send a MIDI Program Change event.

Definition at line 105 of file MIDI_Interface.ipp.

◆ sendPC() [2/2]

void sendPC ( MIDIChannelCN  address,
uint8_t  value 
)
inherited

Send a MIDI Program Change event.

Definition at line 107 of file MIDI_Interface.ipp.

◆ sendCP()

void sendCP ( MIDIChannelCN  address,
uint8_t  pressure 
)
inherited

Send a MIDI Channel Pressure event.

Definition at line 109 of file MIDI_Interface.ipp.

◆ sendPB()

void sendPB ( MIDIChannelCN  address,
uint16_t  value 
)
inherited

Send a MIDI Pitch Bend event.

Definition at line 111 of file MIDI_Interface.ipp.

◆ connectSourcePipe()

void connectSourcePipe ( MIDI_Pipe source)
inherited

Fully connect a source pipe to this sink.

Definition at line 15 of file MIDI_Pipes.cpp.

◆ disconnectSourcePipes()

void disconnectSourcePipes ( )
inherited

Disconnect all source pipes that sink to this sink (recursively).

Definition at line 24 of file MIDI_Pipes.cpp.

◆ disconnect() [1/2]

bool disconnect ( TrueMIDI_Source source)
inherited

Disconnect the given source from this sink.

Leaves other sources connected. Returns true if the source was found and disconnected, false if the given source was not a direct or indirect source to this sink.

Definition at line 39 of file MIDI_Pipes.cpp.

◆ disconnect() [2/2]

bool disconnect ( TrueMIDI_Sink sink)
inherited

Disconnect the given sink from this source.

Leaves other sinks connected. Returns true if the sink was found and disconnected, false if the given sink was not a direct or indirect sink of this source.

Definition at line 94 of file MIDI_Pipes.cpp.

◆ hasSourcePipe()

bool hasSourcePipe ( ) const
inlineinherited

Check if this sink is connected to a source pipe.

Definition at line 94 of file MIDI_Pipes.hpp.

◆ lockDownstream()

virtual void lockDownstream ( cn_t  cn,
bool  lock 
)
inlineprivatevirtualinherited

Base case for recursive lock function.

See also
MIDI_Pipe::lockDownstream

Reimplemented in MIDI_Pipe.

Definition at line 105 of file MIDI_Pipes.hpp.

◆ getFinalSink()

virtual MIDI_Sink* getFinalSink ( )
inlineprivatevirtualinherited

Base case for recursive function.

See also
MIDI_Pipe::getFinalSink

Reimplemented in MIDI_Pipe.

Definition at line 108 of file MIDI_Pipes.hpp.

◆ disconnectSourcePipesShallow()

void disconnectSourcePipesShallow ( )
privateinherited

Disconnect only the first pipe connected to this sink.

Leaves the other pipes connected to the original pipe, which doesn't have a sink anymore when this function finishes. Used to disconnect a MIDI_Pipe while preserving the connections of its "through" inputs.

Definition at line 32 of file MIDI_Pipes.cpp.

◆ sourceMIDItoPipe() [1/3]

void sourceMIDItoPipe ( ChannelMessage  msg)
inherited

Send a MIDI Channel Message.

Definition at line 132 of file MIDI_Pipes.cpp.

◆ sourceMIDItoPipe() [2/3]

void sourceMIDItoPipe ( SysExMessage  msg)
inherited

Send a MIDI System Exclusive message.

Definition at line 137 of file MIDI_Pipes.cpp.

◆ sourceMIDItoPipe() [3/3]

void sourceMIDItoPipe ( RealTimeMessage  msg)
inherited

Send a MIDI Real-Time message.

Definition at line 142 of file MIDI_Pipes.cpp.

◆ exclusive()

void exclusive ( cn_t  cn,
bool  exclusive = true 
)
inherited

Enter or exit exclusive mode for the given cable number.

This means that this becomes the only source that can sink to the sinks connected to this source. Other sources have to wait until this source exits exclusive mode until they can send again.

Parameters
cnCable number to set the exclusive mode for [0, 15].
exclusiveTrue to enable exclusive mode, false to disable.

Definition at line 123 of file MIDI_Pipes.cpp.

◆ canWrite()

bool canWrite ( cn_t  cn) const
inherited

Check if this source can write to the sinks it connects to.

Returns false if any of the sinks have another source that is in exclusive mode.

Parameters
cnCable number to check [0, 15].

Definition at line 128 of file MIDI_Pipes.cpp.

◆ connectSinkPipe()

void connectSinkPipe ( MIDI_Pipe sink)
inherited

Fully connect a sink pipe to this source.

Definition at line 70 of file MIDI_Pipes.cpp.

◆ disconnectSinkPipes()

void disconnectSinkPipes ( )
inherited

Disconnect all sink pipes that this source sinks to (recursively).

Definition at line 79 of file MIDI_Pipes.cpp.

◆ hasSinkPipe()

bool hasSinkPipe ( ) const
inlineinherited

Check if this source is connected to a sink pipe.

Definition at line 189 of file MIDI_Pipes.hpp.

◆ getInitialSource()

virtual MIDI_Source* getInitialSource ( )
inlineprivatevirtualinherited

Base case for recursive function.

See also
MIDI_Pipe::getInitialSource

Reimplemented in MIDI_Pipe.

Definition at line 200 of file MIDI_Pipes.hpp.

◆ disconnectSinkPipesShallow()

void disconnectSinkPipesShallow ( )
privateinherited

Disconnect only the first pipe connected to this source.

Leaves the other pipes connected to the original pipe, which doesn't have a source anymore when this function finishes. Used to disconnect a MIDI_Pipe while preserving the connections of its "through" outputs.

Definition at line 87 of file MIDI_Pipes.cpp.

Member Data Documentation

◆ potentiometerTimer

Timer<micros> potentiometerTimer = {AH::FILTERED_INPUT_UPDATE_INTERVAL}
private

A timer to know when to update the analog inputs.

Definition at line 130 of file Control_Surface_Class.hpp.

◆ displayTimer

Timer<micros> displayTimer = {1000000UL / MAX_FPS}
private

A timer to know when to refresh the displays.

Definition at line 132 of file Control_Surface_Class.hpp.

◆ channelMessageCallback

ChannelMessageCallback channelMessageCallback = nullptr
private

Definition at line 164 of file Control_Surface_Class.hpp.

◆ sysExMessageCallback

SysExMessageCallback sysExMessageCallback = nullptr
private

Definition at line 165 of file Control_Surface_Class.hpp.

◆ realTimeMessageCallback

RealTimeMessageCallback realTimeMessageCallback = nullptr
private

Definition at line 166 of file Control_Surface_Class.hpp.

◆ inpipe

MIDI_Pipe inpipe
private

Definition at line 167 of file Control_Surface_Class.hpp.

◆ outpipe

MIDI_Pipe outpipe
private

Definition at line 167 of file Control_Surface_Class.hpp.

◆ sourcePipe

MIDI_Pipe* sourcePipe = nullptr
protectedinherited

Definition at line 117 of file MIDI_Pipes.hpp.

◆ sinkPipe

MIDI_Pipe* sinkPipe = nullptr
protectedinherited

Definition at line 209 of file MIDI_Pipes.hpp.


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