This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
USBMIDI_Parser.hpp
Go to the documentation of this file.
1 #include "MIDI_Parser.hpp"
2 #include "SysExBuffer.hpp"
3 #include <Helpers/Array.hpp>
4 
5 #ifdef MIDI_NUM_CABLES
6 #define USB_MIDI_NUMBER_OF_CABLES MIDI_NUM_CABLES
7 #elif defined(USB_MIDI4_SERIAL) || defined(USB_MIDI4)
8 #define USB_MIDI_NUMBER_OF_CABLES 4
9 #elif defined(USB_MIDI16_AUDIO_SERIAL) || defined(USB_MIDI16_SERIAL) || \
10  defined(USB_MIDI16)
11 // TODO: || defined(USB_EVERYTHING)
12 #define USB_MIDI_NUMBER_OF_CABLES 16
13 #else
14 #define USB_MIDI_NUMBER_OF_CABLES 1
15 #endif
16 
18 
19 class USBMIDI_Parser : public MIDI_Parser {
20  public:
21  MIDI_read_t parse(uint8_t *packet);
22 
23 #if !IGNORE_SYSEX
24  SysExMessage getSysEx() const override {
25  return {sysexbuffers[CN].getBuffer(), sysexbuffers[CN].getLength(), CN};
26  }
27 #endif
28 
29  uint8_t getCN() const override { return CN; }
30 
31  protected:
32 #if !IGNORE_SYSEX
33  void startSysEx(uint8_t CN) { sysexbuffers[CN].start(); }
34  void endSysEx(uint8_t CN) { sysexbuffers[CN].end(); }
35  bool addSysExByte(uint8_t CN, uint8_t data) {
36  return sysexbuffers[CN].add(data);
37  }
38  bool receivingSysEx(uint8_t CN) const {
39  return sysexbuffers[CN].isReceiving();
40  }
41 #endif
42 
43  uint8_t CN = 0;
44 
45  private:
46 #if !IGNORE_SYSEX
48 #endif
49 };
50 
USBMIDI_Parser::addSysExByte
bool addSysExByte(uint8_t CN, uint8_t data)
Definition: USBMIDI_Parser.hpp:35
SysExMessage
Definition: MIDI_Parser.hpp:64
USBMIDI_Parser::sysexbuffers
Array< SysExBuffer, 1 > sysexbuffers
Definition: USBMIDI_Parser.hpp:47
MIDI_read_t
MIDI_read_t
Definition: MIDI_Parser.hpp:29
USBMIDI_Parser::getCN
uint8_t getCN() const override
Get the cable number of the latests MIDI message.
Definition: USBMIDI_Parser.hpp:29
MIDI_Parser
Definition: MIDI_Parser.hpp:84
SysExBuffer.hpp
Array
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:20
USBMIDI_Parser::getSysEx
SysExMessage getSysEx() const override
Get the latest SysEx message.
Definition: USBMIDI_Parser.hpp:24
Array.hpp
USBMIDI_Parser::endSysEx
void endSysEx(uint8_t CN)
Definition: USBMIDI_Parser.hpp:34
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
USBMIDI_Parser
Definition: USBMIDI_Parser.hpp:19
USBMIDI_Parser::parse
MIDI_read_t parse(uint8_t *packet)
Definition: USBMIDI_Parser.cpp:7
Array::end
T * end()
Get a pointer to the memory beyond the array.
Definition: Array.hpp:72
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
USBMIDI_Parser::startSysEx
void startSysEx(uint8_t CN)
Definition: USBMIDI_Parser.hpp:33
USBMIDI_Parser::receivingSysEx
bool receivingSysEx(uint8_t CN) const
Definition: USBMIDI_Parser.hpp:38
USBMIDI_Parser::CN
uint8_t CN
Definition: USBMIDI_Parser.hpp:43
MIDI_Parser.hpp