Control Surface new-input
MIDI Control Surface library for Arduino
DebugMIDI_Interface.cpp
Go to the documentation of this file.
3 
5 
7 
8 #ifdef PROGMEM
9 
10 const static char NoteOff[] PROGMEM = "Note Off ";
11 const static char NoteOn[] PROGMEM = "Note On ";
12 const static char KeyPressure[] PROGMEM = "Key Pressure ";
13 const static char ControlChange[] PROGMEM = "Control Change ";
14 const static char ProgramChange[] PROGMEM = "Program Change ";
15 const static char ChannelPressure[] PROGMEM = "Channel Pressure ";
16 const static char PitchBend[] PROGMEM = "Pitch Bend ";
17 
19  reinterpret_cast<FlashString_t>(NoteOff),
20  reinterpret_cast<FlashString_t>(NoteOn),
21  reinterpret_cast<FlashString_t>(KeyPressure),
22  reinterpret_cast<FlashString_t>(ControlChange),
23  reinterpret_cast<FlashString_t>(ProgramChange),
24  reinterpret_cast<FlashString_t>(ChannelPressure),
25  reinterpret_cast<FlashString_t>(PitchBend),
26 };
27 
28 #else
29 
30 const static char *MIDIStatusTypeNames[] = {
31  "Note Off ", "Note On ", "Key Pressure ",
32  "Control Change ", "Program Change ", "Channel Pressure ",
33  "Pitch Bend ",
34 };
35 
36 #endif
37 
38 } // namespace DebugMIDIMessageNames
39 
41  return parser.pull(hexstream);
42 }
43 
46 }
47 
50 }
51 
53  uint8_t messageType = (msg.header >> 4) - 8;
54  if (messageType >= 7)
55  return;
56 
58  auto &stream = getStream();
59  if (prefix != nullptr)
60  stream << prefix << ' ';
61  if (msg.hasTwoDataBytes())
62  stream << DebugMIDIMessageNames::MIDIStatusTypeNames[messageType]
63  << F("Channel: ") << msg.getChannel().getOneBased()
64  << F("\tData 1: 0x") << hex << msg.getData1()
65  << F("\tData 2: 0x") << msg.getData2() << dec;
66  else
67  stream << DebugMIDIMessageNames::MIDIStatusTypeNames[messageType]
68  << F("Channel: ") << msg.getChannel().getOneBased()
69  << F("\tData 1: 0x") << hex << msg.getData1() << dec;
70  if (msg.getMessageType() == msg.PITCH_BEND)
71  stream << " (" << msg.getData14bit() << ')';
72  if (msg.getCable() != CABLE_1)
73  stream << F("\tCable: ") << msg.getCable().getOneBased();
74  stream << "\r\n";
75 }
76 
79  auto &stream = getStream();
80  if (prefix != nullptr)
81  stream << prefix << ' ';
82  stream << F("System Exclusive [") << msg.length
83  << (msg.isLastChunk() ? "]\t" : "+]\t")
84  << AH::HexDump(msg.data, msg.length);
85  if (msg.getCable() != CABLE_1)
86  stream << F("\tCable: ") << msg.getCable().getOneBased();
87  stream << "\r\n";
88 }
89 
92  auto &stream = getStream();
93  if (prefix != nullptr)
94  stream << prefix << ' ';
95  stream << F("System Common ") << msg.getMessageType() << hex;
96  if (msg.getNumberOfDataBytes() >= 1)
97  stream << F("\tData 1: 0x") << msg.getData1();
98  if (msg.getNumberOfDataBytes() >= 2)
99  stream << F("\tData 2: 0x") << msg.getData2() << dec << " ("
100  << msg.getData14bit() << ')';
101  else
102  stream << dec;
103  if (msg.getCable() != CABLE_1)
104  stream << F("\tCable: ") << msg.getCable().getOneBased();
105  stream << "\r\n";
106 }
107 
110  auto &stream = getStream();
111  if (prefix != nullptr)
112  stream << prefix << ' ';
113  stream << F("Real-Time ") << msg.getMessageType();
114  if (msg.getCable() != CABLE_1)
115  stream << F("\tCable: ") << msg.getCable().getOneBased();
116  stream << "\r\n";
117 }
118 
std::remove_reference< decltype(*F(""))>::type * FlashString_t
constexpr Cable CABLE_1
Definition: Cable.hpp:118
#define DEBUG_LOCK_MUTEX
Definition: Debug.hpp:84
MIDIReadEvent
Values returned by the MIDI reading functions.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
constexpr uint8_t getOneBased() const
Get the cable as an integer.
Definition: Cable.hpp:36
constexpr uint8_t getOneBased() const
Get the channel as an integer.
Definition: Channel.hpp:36
static void updateIncoming(MIDIInterface_t *iface)
Read, parse and dispatch incoming MIDI messages on the given interface.
MIDIReadEvent pull(BytePuller &&puller)
Parse one incoming MIDI message.
void sendChannelMessageImpl(ChannelMessage) override
Low-level function for sending a MIDI channel voice message.
void handleStall() override
Call back that should finish any MIDI messages that are in progress, and un-stall the pipe or MIDI so...
void update() override
Read the MIDI interface and call the callback if a message was received.
void sendRealTimeImpl(RealTimeMessage) override
Low-level function for sending a MIDI real-time message.
HexPuller< StreamPuller > hexstream
void sendSysExImpl(SysExMessage) override
Low-level function for sending a system exclusive MIDI message.
void sendSysCommonImpl(SysCommonMessage) override
Low-level function for sending a MIDI system common message.
MIDIReadEvent read()
Try reading and parsing a single incoming MIDI message.
Print & hex(Print &printer)
Definition: PrintStream.cpp:62
Print & dec(Print &printer)
Definition: PrintStream.cpp:77
static const char ChannelPressure[]
static const char KeyPressure[]
static const FlashString_t MIDIStatusTypeNames[]
static const char NoteOff[]
static const char ProgramChange[]
static const char PitchBend[]
static const char NoteOn[]
static const char ControlChange[]
MIDIMessageType getMessageType() const
Get the MIDI message type.
constexpr static auto PITCH_BEND
Channel getChannel() const
Get the MIDI channel of the message.
bool hasTwoDataBytes() const
Check whether this message has one or two data bytes.
uint8_t header
MIDI status byte (message type and channel).
Cable getCable() const
Get the MIDI USB cable number of the message.
uint8_t getData1() const
Get the first data byte.
uint16_t getData14bit() const
If Data 1 and Data 2 represent a single 14-bit number, you can use this method to retrieve that numbe...
uint8_t getData2() const
Get the second data byte.
virtual void handleStall()=0
Call back that should finish any MIDI messages that are in progress, and un-stall the pipe or MIDI so...
Cable getCable() const
Get the MIDI USB cable number of the message.
MIDIMessageType getMessageType() const
Get the MIDI message type.
uint8_t getNumberOfDataBytes() const
Get the number of data bytes of this type of System Common message.
MIDIMessageType getMessageType() const
Get the MIDI message type.
const uint8_t * data
Cable getCable() const
Get the MIDI USB cable number of the message.
bool isLastChunk() const