Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
MIDI_Interfaces
SerialMIDI_Interface.cpp
Go to the documentation of this file.
1
#include "
SerialMIDI_Interface.hpp
"
2
#include <
MIDI_Parsers/StreamPuller.hpp
>
3
4
#include "
PicoUSBInit.hpp
"
5
6
BEGIN_CS_NAMESPACE
7
8
// -------------------------------------------------------------------------- //
9
10
// Reading MIDI
11
12
MIDIReadEvent
StreamMIDI_Interface::read
() {
13
if
(!ensure_usb_init(
stream
))
14
return
MIDIReadEvent::NO_MESSAGE
;
15
return
parser
.pull(
StreamPuller
(
stream
));
16
}
17
18
void
StreamMIDI_Interface::update
() {
MIDI_Interface::updateIncoming
(
this
); }
19
20
// -------------------------------------------------------------------------- //
21
22
// Retrieving the received messages
23
24
ChannelMessage
StreamMIDI_Interface::getChannelMessage
()
const
{
25
return
parser
.getChannelMessage();
26
}
27
28
SysCommonMessage
StreamMIDI_Interface::getSysCommonMessage
()
const
{
29
return
parser
.getSysCommonMessage();
30
}
31
32
RealTimeMessage
StreamMIDI_Interface::getRealTimeMessage
()
const
{
33
return
parser
.getRealTimeMessage();
34
}
35
36
SysExMessage
StreamMIDI_Interface::getSysExMessage
()
const
{
37
return
parser
.getSysExMessage();
38
}
39
40
// -------------------------------------------------------------------------- //
41
42
// Sending MIDI
43
44
void
StreamMIDI_Interface::sendChannelMessageImpl
(
ChannelMessage
msg) {
45
if
(!ensure_usb_init(
stream
))
46
return
;
47
stream
.write(msg.
header
);
48
stream
.write(msg.
data1
);
49
if
(msg.
hasTwoDataBytes
())
50
stream
.write(msg.
data2
);
51
}
52
53
void
StreamMIDI_Interface::sendSysCommonImpl
(
SysCommonMessage
msg) {
54
if
(!ensure_usb_init(
stream
))
55
return
;
56
stream
.write(msg.
header
);
57
if
(msg.
getNumberOfDataBytes
() >= 1)
58
stream
.write(msg.
data1
);
59
if
(msg.
getNumberOfDataBytes
() >= 2)
60
stream
.write(msg.
data2
);
61
}
62
63
void
StreamMIDI_Interface::sendSysExImpl
(
SysExMessage
msg) {
64
if
(!ensure_usb_init(
stream
))
65
return
;
66
stream
.write(msg.
data
, msg.
length
);
67
}
68
69
void
StreamMIDI_Interface::sendRealTimeImpl
(
RealTimeMessage
msg) {
70
if
(!ensure_usb_init(
stream
))
71
return
;
72
stream
.write(msg.
message
);
73
}
74
75
END_CS_NAMESPACE
MIDIReadEvent
MIDIReadEvent
Values returned by the MIDI reading functions.
Definition
MIDIReadEvent.hpp:11
MIDIReadEvent::NO_MESSAGE
@ NO_MESSAGE
No new messages were received.
Definition
MIDIReadEvent.hpp:12
PicoUSBInit.hpp
When using the earlephilhower/arduino-pico core with the TinyUSB backend, calling Serial....
SerialMIDI_Interface.hpp
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:11
StreamPuller.hpp
MIDI_Interface::updateIncoming
static void updateIncoming(MIDIInterface_t *iface)
Read, parse and dispatch incoming MIDI messages on the given interface.
Definition
MIDI_Interface.hpp:136
StreamMIDI_Interface::getChannelMessage
ChannelMessage getChannelMessage() const
Return the received channel voice message.
Definition
SerialMIDI_Interface.cpp:24
StreamMIDI_Interface::getRealTimeMessage
RealTimeMessage getRealTimeMessage() const
Return the received real-time message.
Definition
SerialMIDI_Interface.cpp:32
StreamMIDI_Interface::sendChannelMessageImpl
void sendChannelMessageImpl(ChannelMessage) override
Low-level function for sending a MIDI channel voice message.
Definition
SerialMIDI_Interface.cpp:44
StreamMIDI_Interface::update
void update() override
Read the MIDI interface and call the callback if a message was received.
Definition
SerialMIDI_Interface.cpp:18
StreamMIDI_Interface::stream
Stream & stream
Definition
SerialMIDI_Interface.hpp:58
StreamMIDI_Interface::getSysCommonMessage
SysCommonMessage getSysCommonMessage() const
Return the received system common message.
Definition
SerialMIDI_Interface.cpp:28
StreamMIDI_Interface::sendRealTimeImpl
void sendRealTimeImpl(RealTimeMessage) override
Low-level function for sending a MIDI real-time message.
Definition
SerialMIDI_Interface.cpp:69
StreamMIDI_Interface::sendSysExImpl
void sendSysExImpl(SysExMessage) override
Low-level function for sending a system exclusive MIDI message.
Definition
SerialMIDI_Interface.cpp:63
StreamMIDI_Interface::sendSysCommonImpl
void sendSysCommonImpl(SysCommonMessage) override
Low-level function for sending a MIDI system common message.
Definition
SerialMIDI_Interface.cpp:53
StreamMIDI_Interface::read
MIDIReadEvent read()
Try reading and parsing a single incoming MIDI message.
Definition
SerialMIDI_Interface.cpp:12
StreamMIDI_Interface::getSysExMessage
SysExMessage getSysExMessage() const
Return the received system exclusive message.
Definition
SerialMIDI_Interface.cpp:36
StreamMIDI_Interface::parser
SerialMIDI_Parser parser
Definition
SerialMIDI_Interface.hpp:59
StreamPuller
Helper that pulls bytes out of an Arduino stream.
Definition
StreamPuller.hpp:13
ChannelMessage
Definition
MIDI_MessageTypes.hpp:205
ChannelMessage::hasTwoDataBytes
bool hasTwoDataBytes() const
Check whether this message has one or two data bytes.
Definition
MIDI_MessageTypes.hpp:248
MIDIMessage::data2
uint8_t data2
First MIDI data byte.
Definition
MIDI_MessageTypes.hpp:128
MIDIMessage::header
uint8_t header
MIDI status byte (message type and channel).
Definition
MIDI_MessageTypes.hpp:126
MIDIMessage::data1
uint8_t data1
First MIDI data byte.
Definition
MIDI_MessageTypes.hpp:127
RealTimeMessage
Definition
MIDI_MessageTypes.hpp:354
RealTimeMessage::message
uint8_t message
Definition
MIDI_MessageTypes.hpp:363
SysCommonMessage
Definition
MIDI_MessageTypes.hpp:263
SysCommonMessage::getNumberOfDataBytes
uint8_t getNumberOfDataBytes() const
Get the number of data bytes of this type of System Common message.
Definition
MIDI_MessageTypes.hpp:285
SysExMessage
Definition
MIDI_MessageTypes.hpp:305
SysExMessage::length
uint16_t length
Definition
MIDI_MessageTypes.hpp:323
SysExMessage::data
const uint8_t * data
Definition
MIDI_MessageTypes.hpp:322
Generated by
1.17.0