Line data Source code
1 : #include "DebugMIDI_Interface.hpp" 2 : #include <AH/PrintStream/PrintStream.hpp> 3 : 4 : BEGIN_CS_NAMESPACE 5 : 6 : namespace DebugMIDIMessageNames { 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 : 18 : const static FlashString_t MIDIStatusTypeNames[] = { 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 : 40 6 : MIDIReadEvent StreamDebugMIDI_Interface::read() { 41 6 : return parser.pull(hexstream); 42 : } 43 : 44 0 : void StreamDebugMIDI_Interface::update() { 45 0 : MIDI_Interface::updateIncoming(this); 46 0 : } 47 : 48 10 : void StreamDebugMIDI_Base::sendChannelMessageImpl(Stream &stream, 49 : ChannelMessage msg) { 50 10 : uint8_t messageType = (msg.header >> 4) - 8; 51 10 : if (messageType >= 7) 52 0 : return; 53 : 54 : DEBUG_LOCK_MUTEX 55 10 : if (prefix != nullptr) 56 0 : stream << prefix << ' '; 57 10 : if (msg.hasTwoDataBytes()) 58 6 : stream << DebugMIDIMessageNames::MIDIStatusTypeNames[messageType] 59 12 : << F("Channel: ") << msg.getChannel().getOneBased() 60 6 : << F("\tData 1: 0x") << hex << msg.getData1() 61 18 : << F("\tData 2: 0x") << msg.getData2() << dec; 62 : else 63 4 : stream << DebugMIDIMessageNames::MIDIStatusTypeNames[messageType] 64 8 : << F("Channel: ") << msg.getChannel().getOneBased() 65 12 : << F("\tData 1: 0x") << hex << msg.getData1() << dec; 66 10 : if (msg.getMessageType() == msg.PITCH_BEND) 67 1 : stream << " (" << msg.getData14bit() << ')'; 68 10 : if (msg.getCable() != CABLE_1) 69 10 : stream << F("\tCable: ") << msg.getCable().getOneBased(); 70 10 : stream << "\r\n"; 71 : } 72 : 73 1 : void StreamDebugMIDI_Base::sendSysExImpl(Stream &stream, SysExMessage msg) { 74 : DEBUG_LOCK_MUTEX 75 1 : if (prefix != nullptr) 76 0 : stream << prefix << ' '; 77 1 : stream << F("System Exclusive [") << msg.length 78 1 : << (msg.isLastChunk() ? "]\t" : "+]\t") 79 1 : << AH::HexDump(msg.data, msg.length); 80 1 : if (msg.getCable() != CABLE_1) 81 1 : stream << F("\tCable: ") << msg.getCable().getOneBased(); 82 1 : stream << "\r\n"; 83 1 : } 84 : 85 4 : void StreamDebugMIDI_Base::sendSysCommonImpl(Stream &stream, 86 : SysCommonMessage msg) { 87 : DEBUG_LOCK_MUTEX 88 4 : if (prefix != nullptr) 89 0 : stream << prefix << ' '; 90 4 : stream << F("System Common ") << msg.getMessageType() << hex; 91 4 : if (msg.getNumberOfDataBytes() >= 1) 92 3 : stream << F("\tData 1: 0x") << msg.getData1(); 93 4 : if (msg.getNumberOfDataBytes() >= 2) 94 1 : stream << F("\tData 2: 0x") << msg.getData2() << dec << " (" 95 1 : << msg.getData14bit() << ')'; 96 : else 97 3 : stream << dec; 98 4 : if (msg.getCable() != CABLE_1) 99 4 : stream << F("\tCable: ") << msg.getCable().getOneBased(); 100 4 : stream << "\r\n"; 101 4 : } 102 : 103 2 : void StreamDebugMIDI_Base::sendRealTimeImpl(Stream &stream, 104 : RealTimeMessage msg) { 105 : DEBUG_LOCK_MUTEX 106 2 : if (prefix != nullptr) 107 1 : stream << prefix << ' '; 108 2 : stream << F("Real-Time ") << msg.getMessageType(); 109 2 : if (msg.getCable() != CABLE_1) 110 2 : stream << F("\tCable: ") << msg.getCable().getOneBased(); 111 2 : stream << "\r\n"; 112 2 : } 113 : 114 0 : void StreamDebugMIDI_Output::sendChannelMessageImpl(ChannelMessage m) { 115 0 : StreamDebugMIDI_Base::sendChannelMessageImpl(stream, m); 116 0 : } 117 0 : void StreamDebugMIDI_Output::sendSysCommonImpl(SysCommonMessage m) { 118 0 : StreamDebugMIDI_Base::sendSysCommonImpl(stream, m); 119 0 : } 120 0 : void StreamDebugMIDI_Output::sendSysExImpl(SysExMessage m) { 121 0 : StreamDebugMIDI_Base::sendSysExImpl(stream, m); 122 0 : } 123 0 : void StreamDebugMIDI_Output::sendRealTimeImpl(RealTimeMessage m) { 124 0 : StreamDebugMIDI_Base::sendRealTimeImpl(stream, m); 125 0 : } 126 0 : void StreamDebugMIDI_Output::sendNowImpl() { 127 0 : StreamDebugMIDI_Base::sendNowImpl(stream); 128 0 : } 129 : 130 10 : void StreamDebugMIDI_Interface::sendChannelMessageImpl(ChannelMessage m) { 131 10 : StreamDebugMIDI_Base::sendChannelMessageImpl(getStream(), m); 132 10 : } 133 4 : void StreamDebugMIDI_Interface::sendSysCommonImpl(SysCommonMessage m) { 134 4 : StreamDebugMIDI_Base::sendSysCommonImpl(getStream(), m); 135 4 : } 136 1 : void StreamDebugMIDI_Interface::sendSysExImpl(SysExMessage m) { 137 1 : StreamDebugMIDI_Base::sendSysExImpl(getStream(), m); 138 1 : } 139 2 : void StreamDebugMIDI_Interface::sendRealTimeImpl(RealTimeMessage m) { 140 2 : StreamDebugMIDI_Base::sendRealTimeImpl(getStream(), m); 141 2 : } 142 0 : void StreamDebugMIDI_Interface::sendNowImpl() { 143 0 : StreamDebugMIDI_Base::sendNowImpl(getStream()); 144 0 : } 145 : 146 : END_CS_NAMESPACE