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

#include <Control_Surface/Control_Surface_Class.hpp>

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.

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

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 SysCommonMessageCallback = bool(*)(SysCommonMessage)
 Callback function type for System Common messages. More...
 
using RealTimeMessageCallback = bool(*)(RealTimeMessage)
 Callback function type for Real-Time messages. More...
 
void setMIDIInputCallbacks (ChannelMessageCallback channelMessageCallback, SysExMessageCallback sysExMessageCallback, SysCommonMessageCallback sysCommonMessageCallback, RealTimeMessageCallback realTimeMessageCallback)
 Set the MIDI input callbacks.
 

Singleton boilerplate

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

Sending MIDI Channel Voice messages

void send (ChannelMessage message)
 Send a MIDI Channel Voice message.
 
void sendChannelMessage (MIDIMessageType m, Channel c, uint8_t d1, uint8_t d2, Cable cable=CABLE_1)
 Send a 3-byte MIDI Channel Voice message. More...
 
void sendChannelMessage (MIDIMessageType m, Channel c, uint8_t d1, Cable cable=CABLE_1)
 Send a 2-byte MIDI Channel Voice message. More...
 
void sendNoteOn (MIDIAddress address, uint8_t velocity)
 Send a MIDI Note On event.
 
void sendNoteOff (MIDIAddress address, uint8_t velocity)
 Send a MIDI Note Off event.
 
void sendKeyPressure (MIDIAddress address, uint8_t pressure)
 Send a MIDI Key Pressure event.
 
void sendControlChange (MIDIAddress address, uint8_t value)
 Send a MIDI Control Change event.
 
void sendProgramChange (MIDIAddress address)
 Send a MIDI Program Change event.
 
void sendProgramChange (MIDIChannelCable address, uint8_t value)
 Send a MIDI Program Change event.
 
void sendChannelPressure (MIDIChannelCable address, uint8_t pressure)
 Send a MIDI Channel Pressure event.
 
void sendPitchBend (MIDIChannelCable address, uint16_t value)
 Send a MIDI Pitch Bend event.
 

Sending MIDI System Common messages

void send (SysCommonMessage message)
 Send a MIDI System Common message.
 
void sendSysCommon (MIDIMessageType m, Cable cable=CABLE_1)
 Send a MIDI System Common message.
 
void sendSysCommon (MIDIMessageType m, uint8_t data1, Cable cable=CABLE_1)
 Send a MIDI System Common message.
 
void sendSysCommon (MIDIMessageType m, uint8_t data1, uint8_t data2, Cable cable=CABLE_1)
 Send a MIDI System Common message.
 
void sendMTCQuarterFrame (uint8_t data, Cable cable=CABLE_1)
 Send a MIDI Time Code Quarter Frame.
 
void sendMTCQuarterFrame (uint8_t messageType, uint8_t values, Cable cable=CABLE_1)
 Send a MIDI Time Code Quarter Frame.
 
void sendSongPositionPointer (uint16_t spp, Cable cable=CABLE_1)
 Send a MIDI Song Position Pointer message.
 
void sendSongSelect (uint8_t song, Cable cable=CABLE_1)
 Send a MIDI Song Select message.
 
void sendTuneRequest (Cable cable=CABLE_1)
 Send a MIDI Tune Request.
 

Sending MIDI System Exclusive messages

void send (SysExMessage message)
 Send a MIDI System Exclusive message.
 
void sendSysEx (const uint8_t(&sysexdata)[N], Cable cable=CABLE_1)
 Send a MIDI System Exclusive message.
 
void sendSysEx (const uint8_t *data, uint16_t length, Cable cable=CABLE_1)
 Send a MIDI System Exclusive message.
 

Sending MIDI Real-Time messages

void send (RealTimeMessage message)
 Send a MIDI Real-Time message.
 
void sendRealTime (MIDIMessageType rt, Cable cable=CABLE_1)
 Send a MIDI Real-Time message.
 
void sendRealTime (uint8_t rt, Cable cable=CABLE_1)
 Send a MIDI Real-Time message.
 
void sendTimingClock (Cable cable=CABLE_1)
 Send a MIDI Timing Clock message.
 
void sendStart (Cable cable=CABLE_1)
 Send a MIDI Start message.
 
void sendContinue (Cable cable=CABLE_1)
 Send a MIDI Continue message.
 
void sendStop (Cable cable=CABLE_1)
 Send a MIDI Stop message.
 
void sendActiveSensing (Cable cable=CABLE_1)
 Send a MIDI Active Sensing message.
 
void sendSystemReset (Cable cable=CABLE_1)
 Send a MIDI System Reset message.
 

Flusing the MIDI send buffer

void sendNow ()
 Causes all buffered messages to be sent immediately. More...
 

Deprecated

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 (MIDIChannelCable address, uint8_t value)
 Send a MIDI Program Change event. More...
 
void sendCP (MIDIChannelCable address, uint8_t pressure)
 Send a MIDI Channel Pressure event. More...
 
void sendPB (MIDIChannelCable 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.
 
void disconnectSourcePipes ()
 Disconnect all source pipes that sink to this sink (recursively).
 
bool disconnect (TrueMIDI_Source &source)
 Disconnect the given source from this sink. More...
 
bool disconnect (MIDI_Pipe &)=delete
 
bool hasSourcePipe () const
 Check if this sink is connected to a source pipe.
 
MIDI_PipegetSourcePipe ()
 Get a pointer to the pipe this sink is connected to, or nullptr if not connected.
 

Connecting and disconnecting MIDI Pipes

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

Sending data over a MIDI Pipe

void sourceMIDItoPipe (ChannelMessage)
 Send a MIDI Channel Message down the pipe.
 
void sourceMIDItoPipe (SysExMessage)
 Send a MIDI System Exclusive message down the pipe.
 
void sourceMIDItoPipe (SysCommonMessage)
 Send a MIDI System Common message down the pipe.
 
void sourceMIDItoPipe (RealTimeMessage)
 Send a MIDI Real-Time message down the pipe.
 

Stalling the sink pipes and exclusive access

void stall (MIDIStaller *cause=eternal_stall)
 Stall this MIDI source. More...
 
void unstall (MIDIStaller *cause=eternal_stall)
 Un-stall the pipes connected to this source, so other sources are allowed to send again. More...
 
bool isStalled () const
 Check if this source can write to the sinks it connects to.
 
MIDIStallergetStaller () const
 Get a pointer to whatever is causing this MIDI source to be stalled. More...
 
const char * getStallerName () const
 Get the name of whatever is causing this MIDI source to be stalled. More...
 
void handleStallers () const
 Give the code that is stalling the MIDI sink pipes the opportunity to do its job and un-stall the pipes.
 

Public Member Functions

void begin ()
 Initialize the Control_Surface.
 
void loop ()
 Update all MIDI elements, send MIDI events and read MIDI input.
 
bool connectDefaultMIDI_Interface ()
 Connect Control Surface to the default MIDI interface.
 
void disconnectMIDI_Interfaces ()
 Disconnect Control Surface from the MIDI interfaces it's connected to.
 
void updateMidiInput ()
 Update all MIDI interfaces to receive new MIDI events.
 
void updateInputs ()
 Update all MIDIInputElements.
 
void beginDisplays ()
 Initialize all displays that have at least one display element.
 
void updateDisplays ()
 Clear, draw and display all displays that contain display elements that have changed.
 

Static Public Member Functions

static void swap (MIDI_Sink &a, MIDI_Sink &b)
 
static void swap (MIDI_Source &a, MIDI_Source &b)
 

Protected Attributes

MIDI_PipesourcePipe = nullptr
 
MIDI_PipesinkPipe = nullptr
 

Private Member Functions

void sendChannelMessageImpl (ChannelMessage)
 Low-level function for sending a MIDI channel voice message.
 
void sendSysCommonImpl (SysCommonMessage)
 Low-level function for sending a MIDI system common message.
 
void sendSysExImpl (SysExMessage)
 Low-level function for sending a system exclusive MIDI message.
 
void sendRealTimeImpl (RealTimeMessage)
 Low-level function for sending a MIDI real-time message.
 
void sendNowImpl ()
 Low-level function for sending any buffered outgoing MIDI messages. 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 (SysCommonMessage msg) override
 Accept an incoming MIDI System Common message. More...
 
void sinkMIDIfromPipe (RealTimeMessage msg) override
 Accept an incoming MIDI Real-Time message. More...
 
virtual void stallDownstream (MIDIStaller *, MIDI_Source *)
 Base case for recursive stall function. More...
 
virtual void unstallDownstream (MIDIStaller *, MIDI_Source *)
 Base case for recursive un-stall function. More...
 
virtual MIDI_SinkgetFinalSink ()
 Base case for recursive function. More...
 
void disconnectSourcePipesShallow ()
 Disconnect only the first pipe connected to this sink. More...
 
virtual void stallUpstream (MIDIStaller *, MIDI_Sink *)
 Base case for recursive stall function. More...
 
virtual void unstallUpstream (MIDIStaller *, MIDI_Sink *)
 Base case for recursive un-stall function. 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.
 
Timer< micros > displayTimer = {1000000UL / MAX_FPS}
 A timer to know when to refresh the displays.
 
ChannelMessageCallback channelMessageCallback = nullptr
 
SysExMessageCallback sysExMessageCallback = nullptr
 
SysCommonMessageCallback sysCommonMessageCallback = nullptr
 
RealTimeMessageCallback realTimeMessageCallback = nullptr
 
MIDI_Pipe inpipe
 
MIDI_Pipe outpipe
 

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 105 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 109 of file Control_Surface_Class.hpp.

◆ SysCommonMessageCallback

Callback function type for System Common messages.

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

Definition at line 113 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 117 of file Control_Surface_Class.hpp.

Member Function Documentation

◆ sendNowImpl()

void sendNowImpl ( )
inlineprivate

Low-level function for sending any buffered outgoing MIDI messages.

Definition at line 84 of file Control_Surface_Class.hpp.

◆ sinkMIDIfromPipe() [1/4]

void sinkMIDIfromPipe ( ChannelMessage  )
overrideprivatevirtual

Accept an incoming MIDI Channel message.

Implements MIDI_Sink.

Definition at line 95 of file Control_Surface_Class.cpp.

◆ sinkMIDIfromPipe() [2/4]

void sinkMIDIfromPipe ( SysExMessage  )
overrideprivatevirtual

Accept an incoming MIDI System Exclusive message.

Implements MIDI_Sink.

Definition at line 182 of file Control_Surface_Class.cpp.

◆ sinkMIDIfromPipe() [3/4]

void sinkMIDIfromPipe ( SysCommonMessage  )
overrideprivatevirtual

Accept an incoming MIDI System Common message.

Implements MIDI_Sink.

Definition at line 198 of file Control_Surface_Class.cpp.

◆ sinkMIDIfromPipe() [4/4]

void sinkMIDIfromPipe ( RealTimeMessage  )
overrideprivatevirtual

Accept an incoming MIDI Real-Time message.

Implements MIDI_Sink.

Definition at line 210 of file Control_Surface_Class.cpp.

◆ sendChannelMessage() [1/2]

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

Send a 3-byte MIDI Channel Voice message.

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. [CABLE_1, CABLE_16]

Definition at line 33 of file MIDI_Sender.ipp.

◆ sendChannelMessage() [2/2]

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

Send a 2-byte MIDI Channel Voice message.

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 48 of file MIDI_Sender.ipp.

◆ sendNow()

void sendNow
inherited

Causes all buffered messages to be sent immediately.

Note
Doesn't necessarily wait until all data has been sent, it just triggers the transmission, so everything will be transmitted as soon as possible.

Definition at line 142 of file MIDI_Sender.ipp.

◆ sendKP()

void sendKP ( MIDIAddress  address,
uint8_t  pressure 
)
inherited

Send a MIDI Key Pressure event.

Definition at line 152 of file MIDI_Sender.ipp.

◆ sendCC()

void sendCC ( MIDIAddress  address,
uint8_t  value 
)
inherited

Send a MIDI Control Change event.

Definition at line 156 of file MIDI_Sender.ipp.

◆ sendPC() [1/2]

void sendPC ( MIDIAddress  address)
inherited

Send a MIDI Program Change event.

Definition at line 160 of file MIDI_Sender.ipp.

◆ sendPC() [2/2]

void sendPC ( MIDIChannelCable  address,
uint8_t  value 
)
inherited

Send a MIDI Program Change event.

Definition at line 164 of file MIDI_Sender.ipp.

◆ sendCP()

void sendCP ( MIDIChannelCable  address,
uint8_t  pressure 
)
inherited

Send a MIDI Channel Pressure event.

Definition at line 168 of file MIDI_Sender.ipp.

◆ sendPB()

void sendPB ( MIDIChannelCable  address,
uint16_t  value 
)
inherited

Send a MIDI Pitch Bend event.

Definition at line 172 of file MIDI_Sender.ipp.

◆ 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 40 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 99 of file MIDI_Pipes.cpp.

◆ stallDownstream()

virtual void stallDownstream ( MIDIStaller ,
MIDI_Source  
)
inlineprivatevirtualinherited

Base case for recursive stall function.

See also
MIDI_Pipe::stallDownstream

Reimplemented in MIDI_Pipe.

Definition at line 127 of file MIDI_Pipes.hpp.

◆ unstallDownstream()

virtual void unstallDownstream ( MIDIStaller ,
MIDI_Source  
)
inlineprivatevirtualinherited

Base case for recursive un-stall function.

See also
MIDI_Pipe::unstallDownstream

Reimplemented in MIDI_Pipe.

Definition at line 130 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 133 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 33 of file MIDI_Pipes.cpp.

◆ stall()

void stall ( MIDIStaller cause = eternal_stall)
inherited

Stall this MIDI source.

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 un-stalls the pipe before they can send again.

Parameters
causePointer to the reason for this stall, can be called back to un-stall the pipes.

Definition at line 157 of file MIDI_Pipes.cpp.

◆ unstall()

void unstall ( MIDIStaller cause = eternal_stall)
inherited

Un-stall the pipes connected to this source, so other sources are allowed to send again.

Parameters
causePointer to the reason for the stall (this has to be the same one that was used to stall).

Definition at line 162 of file MIDI_Pipes.cpp.

◆ getStaller()

MIDIStaller * getStaller ( ) const
inherited

Get a pointer to whatever is causing this MIDI source to be stalled.

There could be multiple stallers, this function just returns one.

Definition at line 173 of file MIDI_Pipes.cpp.

◆ getStallerName()

const char * getStallerName ( ) const
inherited

Get the name of whatever is causing this MIDI source to be stalled.

There could be multiple stallers, this function just returns one.

Definition at line 179 of file MIDI_Pipes.cpp.

◆ stallUpstream()

virtual void stallUpstream ( MIDIStaller ,
MIDI_Sink  
)
inlineprivatevirtualinherited

Base case for recursive stall function.

See also
MIDI_Pipe::stallUpstream

Reimplemented in MIDI_Pipe.

Definition at line 241 of file MIDI_Pipes.hpp.

◆ unstallUpstream()

virtual void unstallUpstream ( MIDIStaller ,
MIDI_Sink  
)
inlineprivatevirtualinherited

Base case for recursive un-stall function.

See also
MIDI_Pipe::unstallUpstream

Reimplemented in MIDI_Pipe.

Definition at line 244 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 247 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 92 of file MIDI_Pipes.cpp.


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