Control Surface  1.2.0
MIDI Control Surface library for Arduino
MIDI_Parser.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stddef.h>
4 #include <stdint.h>
5 #include <stdlib.h>
6 
7 #include <Def/Def.hpp>
8 #include <Settings/SettingsWrapper.hpp>
9 
10 #include "MIDI_MessageTypes.hpp"
11 
13 
15 enum class MIDIReadEvent : uint8_t {
16  NO_MESSAGE = 0,
17  CHANNEL_MESSAGE = 1,
18  SYSEX_MESSAGE = 2,
19  REALTIME_MESSAGE = 3,
20 };
21 
22 class MIDI_Parser {
23  public:
28 #if !IGNORE_SYSEX
29 
30  virtual SysExMessage getSysExMessage() const = 0;
31 #else
32  SysExMessage getSysExMessage() const { return {nullptr, 0, 0}; }
33 #endif
34 
35  const uint8_t *getSysExBuffer() const { return getSysExMessage().data; }
37  size_t getSysExLength() const { return getSysExMessage().length; }
38 
39  protected:
40  ChannelMessage midimsg = {0xFF, 0x00, 0x00, 0x0};
41  RealTimeMessage rtmsg = {0xFF, 0x0};
42 
43  public:
45  static bool isStatus(uint8_t data) { return data & (1 << 7); }
47  static bool isData(uint8_t data) { return (data & (1 << 7)) == 0; }
48 };
49 
MIDI_Parser::getChannelMessage
ChannelMessage getChannelMessage()
Get the latest MIDI channel message.
Definition: MIDI_Parser.hpp:25
SysExMessage
Definition: MIDI_MessageTypes.hpp:138
MIDI_Parser::isData
static bool isData(uint8_t data)
Check if the given byte is a MIDI data byte.
Definition: MIDI_Parser.hpp:47
SysExMessage::data
const uint8_t * data
Definition: MIDI_MessageTypes.hpp:156
MIDI_Parser
Definition: MIDI_Parser.hpp:22
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
MIDI_Parser::rtmsg
RealTimeMessage rtmsg
Definition: MIDI_Parser.hpp:41
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MIDIReadEvent::NO_MESSAGE
@ NO_MESSAGE
No new incoming methods.
RealTimeMessage
Definition: MIDI_MessageTypes.hpp:173
MIDI_Parser::midimsg
ChannelMessage midimsg
Definition: MIDI_Parser.hpp:40
MIDI_Parser::getRealTimeMessage
RealTimeMessage getRealTimeMessage()
Get the latest MIDI real-time message.
Definition: MIDI_Parser.hpp:27
MIDI_Parser::isStatus
static bool isStatus(uint8_t data)
Check if the given byte is a MIDI header byte.
Definition: MIDI_Parser.hpp:45
MIDI_Parser::getSysExLength
size_t getSysExLength() const
Get the length of the SysEx message.
Definition: MIDI_Parser.hpp:37
ChannelMessage
Definition: MIDI_MessageTypes.hpp:72
MIDIReadEvent
MIDIReadEvent
Result of the MIDI interface read methods.
Definition: MIDI_Parser.hpp:15
MIDI_MessageTypes.hpp
SysExMessage::length
uint8_t length
Definition: MIDI_MessageTypes.hpp:157
MIDI_Parser::getSysExMessage
virtual SysExMessage getSysExMessage() const =0
Get the latest SysEx message.
MIDI_Parser::getSysExBuffer
const uint8_t * getSysExBuffer() const
Get the pointer to the SysEx data.
Definition: MIDI_Parser.hpp:35