Line data Source code
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 : 12 : BEGIN_CS_NAMESPACE 13 : 14 : /// Result of the MIDI interface read methods. 15 : enum class MIDIReadEvent : uint8_t { 16 : NO_MESSAGE = 0, ///< No new incoming methods. 17 : CHANNEL_MESSAGE = 1, ///< A MIDI channel message was received. 18 : SYSEX_MESSAGE = 2, ///< A MIDI system exclusive message was received. 19 : REALTIME_MESSAGE = 3, ///< A MIDI real-time message was received. 20 : }; 21 : 22 190 : class MIDI_Parser { 23 : public: 24 : /** Get the latest MIDI channel message. */ 25 49 : ChannelMessage getChannelMessage() { return midimsg; } 26 : /** Get the latest MIDI real-time message. */ 27 13 : RealTimeMessage getRealTimeMessage() { return rtmsg; } 28 : #if !IGNORE_SYSEX 29 : /** Get the latest SysEx message. */ 30 : virtual SysExMessage getSysExMessage() const = 0; 31 : #else 32 : SysExMessage getSysExMessage() const { return {nullptr, 0, 0}; } 33 : #endif 34 : /** Get the pointer to the SysEx data. */ 35 48 : const uint8_t *getSysExBuffer() const { return getSysExMessage().data; } 36 : /** Get the length of the SysEx message. */ 37 24 : size_t getSysExLength() const { return getSysExMessage().length; } 38 : 39 : protected: 40 95 : ChannelMessage midimsg = {0xFF, 0x00, 0x00, 0x0}; 41 95 : RealTimeMessage rtmsg = {0xFF, 0x0}; 42 : 43 : public: 44 : /** Check if the given byte is a MIDI header byte. */ 45 459 : static bool isStatus(uint8_t data) { return data & (1 << 7); } 46 : /** Check if the given byte is a MIDI data byte. */ 47 94 : static bool isData(uint8_t data) { return (data & (1 << 7)) == 0; } 48 : }; 49 : 50 : END_CS_NAMESPACE