This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Control_Surface_Class.cpp
Go to the documentation of this file.
11 #include <Selectors/Selector.hpp>
12 
13 #include <Arduino.h>
14 
16 
18  static Control_Surface_ instance;
19  return instance;
20 }
21 
23 #if defined(ARDUINO) && defined(DEBUG_OUT)
24  DEBUG_OUT.begin(defaultBaudRate);
25  delay(250);
26 #endif
29  MIDI().begin(); // initialize the MIDI interface
30  MIDI().setCallbacks(this);
31  DisplayInterface::beginAll(); // initialize all displays
43 }
44 
50  updateInputs();
51  if (displayTimer)
53 }
54 
57  if (midi == nullptr)
58  FATAL_ERROR(F("No default MIDI interface is selected."), 0xDEAD);
59 
60  return *midi;
61 }
62 
64  MIDI_Interface &midi = MIDI();
65  midi.update();
66 }
67 
69  ChannelMessage midichmsg = midi.getChannelMessage();
70  ChannelMessageMatcher midimsg = {midichmsg};
71 
72 #ifdef DEBUG_MIDI_PACKETS
73  // TODO: print CN
74  if (midimsg.type != PROGRAM_CHANGE && midimsg.type != CHANNEL_PRESSURE)
75  DEBUG(">>> " << hex << midichmsg.header << ' ' << midimsg.data1 << ' '
76  << midimsg.data2 << dec);
77  else
78  DEBUG(">>> " << hex << midichmsg.header << ' ' << midimsg.data1 << dec);
79 #endif
80 
81  // If the Channel Message callback exists, call it to see if we have to
82  // continue handling it.
84  return;
85 
86  if (midimsg.type == CC && midimsg.data1 == 0x79) {
87  // Reset All Controllers
88  DEBUG(F("Reset All Controllers"));
91  } else if (midimsg.type == CC && midimsg.data1 == MIDI_CC::All_Notes_Off) {
93  } else {
94  if (midimsg.type == CC) {
95  // Control Change
96  DEBUGFN(F("Updating CC elements with new MIDI message."));
98 
99  } else if (midimsg.type == NOTE_OFF || midimsg.type == NOTE_ON) {
100  // Note
101  DEBUGFN(F("Updating Note elements with new MIDI message."));
103 
104  } else if (midimsg.type == CHANNEL_PRESSURE) {
105  // Channel Pressure
106  DEBUGFN(F("Updating Channel Pressure elements with new "
107  "MIDI message."));
109  } else if (midimsg.type == PROGRAM_CHANGE) {
110  // Channel Pressure
111  DEBUGFN(F("Updating Program Change elements with new "
112  "MIDI message."));
114  }
115  }
116 }
117 
119  // System Exclusive
120  SysExMessage msg = midi.getSysExMessage();
121 #ifdef DEBUG_MIDI_PACKETS
122  const uint8_t *data = msg.data;
123  size_t len = msg.length;
124  // TODO: print CN
125  DEBUG_OUT << hex;
126  for (size_t i = 0; i < len; i++)
127  DEBUG_OUT << data[i] << ' ';
128  DEBUG_OUT << dec << endl;
129 #endif
130  // If the SysEx Message callback exists, call it to see if we have to
131  // continue handling it.
133  return;
135 }
136 
138  uint8_t message) {
139  RealTimeMessage rtMessage = {message, midi.getCN()};
140  // If the Real-Time Message callback exists, call it to see if we have to
141  // continue handling it.
143  return;
144  // TODO: handle Real-Time input
145 }
146 
153 }
154 
156  DisplayInterface *previousDisplay = nullptr;
157  for (DisplayElement &displayElement : DisplayElement::getAll()) {
158  DisplayInterface *thisDisplay = &displayElement.getDisplay();
159  if (thisDisplay != previousDisplay) {
160  if (previousDisplay)
161  previousDisplay->display();
162  thisDisplay->clearAndDrawBackground();
163  }
164  displayElement.draw();
165  previousDisplay = thisDisplay;
166  }
167  if (previousDisplay)
168  previousDisplay->display();
169 }
170 
172 
ExtendedIOElement.hpp
MIDIInputElementChannelPressure::resetAll
static void resetAll()
Reset all MIDIInputElementChannelPressure elements to their initial state.
Definition: MIDIInputElementChannelPressure.hpp:50
Parsing_MIDI_Interface::getCN
uint8_t getCN() const
Return the cable number of the received message.
Definition: MIDI_Interface.cpp:128
MIDI_Interface::getDefault
static MIDI_Interface * getDefault()
Return the default MIDI interface.
Definition: MIDI_Interface.cpp:18
MIDI_CC::All_Notes_Off
constexpr uint8_t All_Notes_Off
Definition: Control_Change.hpp:107
CHANNEL_PRESSURE
const uint8_t CHANNEL_PRESSURE
Definition: MIDI_Parser.hpp:21
DisplayElement
An interface for elements that draw to a display.
Definition: DisplayElement.hpp:11
DisplayInterface::beginAll
static void beginAll()
Initialize all displays.
Definition: DisplayInterface.cpp:61
Parsing_MIDI_Interface::getChannelMessage
ChannelMessage getChannelMessage()
Return the received channel message.
Definition: MIDI_Interface.cpp:120
SysExMessage
Definition: MIDI_Parser.hpp:64
MIDIInputElementSysEx.hpp
Control_Surface_::onSysExMessage
void onSysExMessage(Parsing_MIDI_Interface &midi) override
The callback to be called when a MIDI System Exclusive message is received.
Definition: Control_Surface_Class.cpp:118
SysExMessage::length
uint8_t length
Definition: MIDI_Parser.hpp:73
DisplayElement::getAll
static DoublyLinkedList< DisplayElement > & getAll()
Get the list of all DisplayElement instances.
Definition: DisplayElement.hpp:41
Parsing_MIDI_Interface
An abstract class for MIDI interfaces.
Definition: MIDI_Interface.hpp:188
DisplayInterface
An interface for displays.
Definition: DisplayInterface.hpp:14
MIDIInputElementNote::beginAll
static void beginAll()
Initialize all MIDIInputElementNote elements.
Definition: MIDIInputElementNote.hpp:48
MIDIInputElementCC::beginAll
static void beginAll()
Initialize all MIDIInputElementCC elements.
Definition: MIDIInputElementCC.hpp:50
Control_Surface_::updateInputs
void updateInputs()
Update all MIDIInputElements.
Definition: Control_Surface_Class.cpp:147
MIDIOutputElement.hpp
Control_Surface_::onChannelMessage
void onChannelMessage(Parsing_MIDI_Interface &midi) override
The callback to be called when a MIDI channel message is received.
Definition: Control_Surface_Class.cpp:68
MIDIInputElementCC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementCC elements with a new MIDI message.
Definition: MIDIInputElementCC.hpp:74
Timer::begin
void begin()
Initialize the timer.
Definition: MillisMicrosTimer.hpp:35
MIDIInputElementPC::updateAll
static void updateAll()
Update all MIDIInputElementPC elements.
Definition: MIDIInputElementPC.hpp:58
MIDIInputElementPC.hpp
ChannelMessageMatcher
Struct for easily matching MIDI messages.
Definition: ChannelMessageMatcher.hpp:10
MIDIInputElementSysEx::beginAll
static void beginAll()
Initialize all MIDIInputElementSysEx elements.
Definition: MIDIInputElementSysEx.hpp:56
Control_Change.hpp
Control_Surface_::MIDI
MIDI_Interface & MIDI()
Get the MIDI interface of the Control Surface.
Definition: Control_Surface_Class.cpp:55
DisplayInterface::clearAndDrawBackground
void clearAndDrawBackground()
Clear the frame buffer, and draw the custom background.
Definition: DisplayInterface.hpp:89
Control_Surface_::displayTimer
Timer< micros > displayTimer
A timer to know when to refresh the displays.
Definition: Control_Surface_Class.hpp:93
Updatable::updateAll
static void updateAll()
Update all enabled instances of this class.
Definition: Updatable.hpp:75
Control_Surface_::updateMidiInput
void updateMidiInput()
Update all MIDI interfaces to receive new MIDI events.
Definition: Control_Surface_Class.cpp:63
Control_Surface_::onRealtimeMessage
void onRealtimeMessage(Parsing_MIDI_Interface &midi, uint8_t message) override
The callback to be called when a MIDI Real-Time message is received.
Definition: Control_Surface_Class.cpp:137
Control_Surface_Class.hpp
MIDI_Interface::update
virtual void update()=0
Read the MIDI interface and call the callback if a message is received.
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
MIDIInputElementNote.hpp
Control_Surface_::channelMessageCallback
ChannelMessageCallback channelMessageCallback
Definition: Control_Surface_Class.hpp:120
Control_Surface
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
Definition: Control_Surface_Class.cpp:171
DEBUGFN
#define DEBUGFN(x)
Definition: Debug.hpp:164
RealTimeMessage
Definition: MIDI_Parser.hpp:77
MIDIInputElementCC.hpp
defaultBaudRate
constexpr unsigned long defaultBaudRate
The default baud rate for debug MIDI interfaces.
Definition: Settings.hpp:34
MIDIInputElementCC::resetAll
static void resetAll()
Reset all MIDIInputElementCC elements to their initial state.
Definition: MIDIInputElementCC.hpp:66
NOTE_ON
const uint8_t NOTE_ON
Definition: MIDI_Parser.hpp:17
PROGRAM_CHANGE
const uint8_t PROGRAM_CHANGE
Definition: MIDI_Parser.hpp:20
MIDIInputElementCC::updateAll
static void updateAll()
Update all MIDIInputElementCC elements.
Definition: MIDIInputElementCC.hpp:58
Selector.hpp
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
NOTE_OFF
const uint8_t NOTE_OFF
Definition: MIDI_Parser.hpp:16
ChannelMessageMatcher::type
uint8_t type
Definition: ChannelMessageMatcher.hpp:18
DEBUG
#define DEBUG(x)
Definition: Debug.hpp:158
ChannelMessageMatcher::data1
uint8_t data1
Definition: ChannelMessageMatcher.hpp:20
FATAL_ERROR
#define FATAL_ERROR(x, e)
Definition: Error.hpp:35
MIDIInputElementNote::updateAll
static void updateAll()
Update all MIDIInputElementNote elements.
Definition: MIDIInputElementNote.hpp:59
Control_Surface_::potentiometerTimer
Timer< micros > potentiometerTimer
A timer to know when to update the analog inputs.
Definition: Control_Surface_Class.hpp:91
Control_Surface_::sysExMessageCallback
SysExMessageCallback sysExMessageCallback
Definition: Control_Surface_Class.hpp:121
Control_Surface_::realTimeMessageCallback
RealTimeMessageCallback realTimeMessageCallback
Definition: Control_Surface_Class.hpp:122
MIDIInputElementChannelPressure::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementChannelPressure elements with a new MIDI message.
Definition: MIDIInputElementChannelPressure.hpp:71
dec
Print & dec(Print &printer)
Definition: PrintStream.cpp:77
MIDI_Interface::setCallbacks
virtual void setCallbacks(MIDI_Callbacks *cb)=0
Set the callbacks that will be called when a MIDI message is received.
Control_Surface_::begin
void begin()
Initialize the Control_Surface.
Definition: Control_Surface_Class.cpp:22
endl
Print & endl(Print &printer)
Definition: PrintStream.cpp:27
hex
Print & hex(Print &printer)
Definition: PrintStream.cpp:62
MIDIInputElementChannelPressure::updateAll
static void updateAll()
Update all MIDIInputElementChannelPressure elements.
Definition: MIDIInputElementChannelPressure.hpp:59
Control_Surface_::updateDisplays
void updateDisplays()
Clear, draw and display all displays.
Definition: Control_Surface_Class.cpp:155
DisplayInterface::display
virtual void display()=0
Write the frame buffer to the display.
Updatable::beginAll
static void beginAll()
Begin all enabled instances of this class.
Definition: Updatable.hpp:68
CC
const uint8_t CC
Definition: MIDI_Parser.hpp:19
ChannelMessage::header
uint8_t header
Definition: MIDI_Parser.hpp:48
ChannelMessage
Definition: MIDI_Parser.hpp:47
MIDIInputElementSysEx::updateAll
static void updateAll()
Update all MIDIInputElementSysEx elements.
Definition: MIDIInputElementSysEx.hpp:67
MIDI_Interface
An abstract class for MIDI interfaces.
Definition: MIDI_Interface.hpp:16
ExtendedIOElement::beginAll
static void beginAll()
Initialize all extended IO elements.
Definition: ExtendedIOElement.cpp:21
MIDIInputElementPC::beginAll
static void beginAll()
Definition: MIDIInputElementPC.hpp:37
FilteredAnalog.hpp
MIDIInputElementChannelPressure::beginAll
static void beginAll()
Definition: MIDIInputElementChannelPressure.hpp:38
Control_Surface_
This class ensures initialization, updating, and interaction between all other classes,...
Definition: Control_Surface_Class.hpp:19
MIDIInputElementPC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementPC elements with a new MIDI message.
Definition: MIDIInputElementPC.hpp:70
Parsing_MIDI_Interface::getSysExMessage
SysExMessage getSysExMessage() const
Return the received system exclusive message.
Definition: MIDI_Interface.cpp:124
MIDIInputElementChannelPressure.hpp
SysExMessage::data
const uint8_t * data
Definition: MIDI_Parser.hpp:72
Control_Surface_::loop
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
Definition: Control_Surface_Class.cpp:45
Control_Surface_::getInstance
static Control_Surface_ & getInstance()
Return the static Control_Surface_ instance.
Definition: Control_Surface_Class.cpp:17
ChannelMessageMatcher::data2
uint8_t data2
Definition: ChannelMessageMatcher.hpp:21
MIDIInputElementNote::resetAll
static void resetAll()
Reset all MIDIInputElementNote elements to their initial state.
Definition: MIDIInputElementNote.hpp:70
FilteredAnalog::setupADC
static void setupADC()
Definition: FilteredAnalog.hpp:135
MIDIInputElementSysEx::updateAllWith
static void updateAllWith(SysExMessage midimsg)
Update all MIDIInputElementSysEx elements with a new MIDI message.
Definition: MIDIInputElementSysEx.hpp:90
MIDI_Interface::begin
virtual void begin()
Initialize the MIDI Interface.
Definition: MIDI_Interface.hpp:32
MIDIInputElementNote::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementNote elements with a new MIDI message.
Definition: MIDIInputElementNote.hpp:82
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23