LCOV - code coverage report
Current view: top level - src/MIDI_Interfaces - DebugMIDI_Interface.cpp (source / functions) Coverage Total Hit
Test: 73449d9b107c772cf65493691543348214e5d5eb Lines: 67.7 % 93 63
Test Date: 2026-06-06 17:44:35 Functions: 56.2 % 16 9
Legend: Lines:     hit not hit

            Line data    Source code
       1              : #include "DebugMIDI_Interface.hpp"
       2              : #include <AH/PrintStream/PrintStream.hpp>
       3              : 
       4              : #include "PicoUSBInit.hpp"
       5              : 
       6              : BEGIN_CS_NAMESPACE
       7              : 
       8              : namespace DebugMIDIMessageNames {
       9              : 
      10              : #ifdef PROGMEM
      11              : 
      12              : const static char NoteOff[] PROGMEM = "Note Off         ";
      13              : const static char NoteOn[] PROGMEM = "Note On          ";
      14              : const static char KeyPressure[] PROGMEM = "Key Pressure     ";
      15              : const static char ControlChange[] PROGMEM = "Control Change   ";
      16              : const static char ProgramChange[] PROGMEM = "Program Change   ";
      17              : const static char ChannelPressure[] PROGMEM = "Channel Pressure ";
      18              : const static char PitchBend[] PROGMEM = "Pitch Bend       ";
      19              : 
      20              : const static FlashString_t MIDIStatusTypeNames[] = {
      21              :     reinterpret_cast<FlashString_t>(NoteOff),
      22              :     reinterpret_cast<FlashString_t>(NoteOn),
      23              :     reinterpret_cast<FlashString_t>(KeyPressure),
      24              :     reinterpret_cast<FlashString_t>(ControlChange),
      25              :     reinterpret_cast<FlashString_t>(ProgramChange),
      26              :     reinterpret_cast<FlashString_t>(ChannelPressure),
      27              :     reinterpret_cast<FlashString_t>(PitchBend),
      28              : };
      29              : 
      30              : #else
      31              : 
      32              : const static char *MIDIStatusTypeNames[] = {
      33              :     "Note Off         ", "Note On          ", "Key Pressure     ",
      34              :     "Control Change   ", "Program Change   ", "Channel Pressure ",
      35              :     "Pitch Bend       ",
      36              : };
      37              : 
      38              : #endif
      39              : 
      40              : } // namespace DebugMIDIMessageNames
      41              : 
      42            6 : MIDIReadEvent StreamDebugMIDI_Interface::read() {
      43            6 :     if (!ensure_usb_init(getStream()))
      44            0 :         return MIDIReadEvent::NO_MESSAGE;
      45            6 :     return parser.pull(hexstream);
      46              : }
      47              : 
      48            0 : void StreamDebugMIDI_Interface::update() {
      49            0 :     MIDI_Interface::updateIncoming(this);
      50            0 : }
      51              : 
      52           10 : void PrintDebugMIDI_Base::sendChannelMessageImpl(Print &stream,
      53              :                                                  ChannelMessage msg) {
      54           10 :     if (!ensure_usb_init(stream))
      55            0 :         return;
      56           10 :     uint8_t messageType = (msg.header >> 4) - 8;
      57           10 :     if (messageType >= 7)
      58            0 :         return;
      59              : 
      60              :     DEBUG_LOCK_MUTEX
      61           10 :     if (prefix != nullptr)
      62            0 :         stream << prefix << ' ';
      63           10 :     if (msg.hasTwoDataBytes())
      64            6 :         stream << DebugMIDIMessageNames::MIDIStatusTypeNames[messageType]
      65           12 :                << F("Channel: ") << msg.getChannel().getOneBased()
      66            6 :                << F("\tData 1: 0x") << hex << msg.getData1()
      67           12 :                << F("\tData 2: 0x") << msg.getData2() << dec;
      68              :     else
      69            4 :         stream << DebugMIDIMessageNames::MIDIStatusTypeNames[messageType]
      70            8 :                << F("Channel: ") << msg.getChannel().getOneBased()
      71            8 :                << F("\tData 1: 0x") << hex << msg.getData1() << dec;
      72           10 :     if (msg.getMessageType() == msg.PitchBend)
      73            1 :         stream << " (" << msg.getData14bit() << ')';
      74           10 :     if (msg.getCable() != Cable_1)
      75           10 :         stream << F("\tCable: ") << msg.getCable().getOneBased();
      76           10 :     stream << "\r\n";
      77              : }
      78              : 
      79            1 : void PrintDebugMIDI_Base::sendSysExImpl(Print &stream, SysExMessage msg) {
      80            1 :     if (!ensure_usb_init(stream))
      81            0 :         return;
      82              :     DEBUG_LOCK_MUTEX
      83            1 :     if (prefix != nullptr)
      84            0 :         stream << prefix << ' ';
      85            1 :     stream << F("System Exclusive [") << msg.length
      86            1 :            << (msg.isLastChunk() ? "]\t" : "+]\t")
      87            1 :            << AH::HexDump(msg.data, msg.length);
      88            1 :     if (msg.getCable() != Cable_1)
      89            1 :         stream << F("\tCable: ") << msg.getCable().getOneBased();
      90            1 :     stream << "\r\n";
      91              : }
      92              : 
      93            4 : void PrintDebugMIDI_Base::sendSysCommonImpl(Print &stream,
      94              :                                             SysCommonMessage msg) {
      95            4 :     if (!ensure_usb_init(stream))
      96            0 :         return;
      97              :     DEBUG_LOCK_MUTEX
      98            4 :     if (prefix != nullptr)
      99            0 :         stream << prefix << ' ';
     100            4 :     stream << F("System Common    ") << msg.getMessageType() << hex;
     101            4 :     if (msg.getNumberOfDataBytes() >= 1)
     102            3 :         stream << F("\tData 1: 0x") << msg.getData1();
     103            4 :     if (msg.getNumberOfDataBytes() >= 2)
     104            1 :         stream << F("\tData 2: 0x") << msg.getData2() << dec << " ("
     105            1 :                << msg.getData14bit() << ')';
     106              :     else
     107            3 :         stream << dec;
     108            4 :     if (msg.getCable() != Cable_1)
     109            4 :         stream << F("\tCable: ") << msg.getCable().getOneBased();
     110            4 :     stream << "\r\n";
     111              : }
     112              : 
     113            2 : void PrintDebugMIDI_Base::sendRealTimeImpl(Print &stream, RealTimeMessage msg) {
     114            2 :     if (!ensure_usb_init(stream))
     115            0 :         return;
     116              :     DEBUG_LOCK_MUTEX
     117            2 :     if (prefix != nullptr)
     118            1 :         stream << prefix << ' ';
     119            2 :     stream << F("Real-Time        ") << msg.getMessageType();
     120            2 :     if (msg.getCable() != Cable_1)
     121            2 :         stream << F("\tCable: ") << msg.getCable().getOneBased();
     122            2 :     stream << "\r\n";
     123              : }
     124              : 
     125            0 : void StreamDebugMIDI_Output::sendChannelMessageImpl(ChannelMessage m) {
     126            0 :     PrintDebugMIDI_Base::sendChannelMessageImpl(getStream(), m);
     127            0 : }
     128            0 : void StreamDebugMIDI_Output::sendSysCommonImpl(SysCommonMessage m) {
     129            0 :     PrintDebugMIDI_Base::sendSysCommonImpl(getStream(), m);
     130            0 : }
     131            0 : void StreamDebugMIDI_Output::sendSysExImpl(SysExMessage m) {
     132            0 :     PrintDebugMIDI_Base::sendSysExImpl(getStream(), m);
     133            0 : }
     134            0 : void StreamDebugMIDI_Output::sendRealTimeImpl(RealTimeMessage m) {
     135            0 :     PrintDebugMIDI_Base::sendRealTimeImpl(getStream(), m);
     136            0 : }
     137            0 : void StreamDebugMIDI_Output::sendNowImpl() {
     138            0 :     PrintDebugMIDI_Base::sendNowImpl(getStream());
     139            0 : }
     140              : 
     141           10 : void StreamDebugMIDI_Interface::sendChannelMessageImpl(ChannelMessage m) {
     142           10 :     PrintDebugMIDI_Base::sendChannelMessageImpl(getStream(), m);
     143           10 : }
     144            4 : void StreamDebugMIDI_Interface::sendSysCommonImpl(SysCommonMessage m) {
     145            4 :     PrintDebugMIDI_Base::sendSysCommonImpl(getStream(), m);
     146            4 : }
     147            1 : void StreamDebugMIDI_Interface::sendSysExImpl(SysExMessage m) {
     148            1 :     PrintDebugMIDI_Base::sendSysExImpl(getStream(), m);
     149            1 : }
     150            2 : void StreamDebugMIDI_Interface::sendRealTimeImpl(RealTimeMessage m) {
     151            2 :     PrintDebugMIDI_Base::sendRealTimeImpl(getStream(), m);
     152            2 : }
     153            0 : void StreamDebugMIDI_Interface::sendNowImpl() {
     154            0 :     PrintDebugMIDI_Base::sendNowImpl(getStream());
     155            0 : }
     156              : 
     157              : END_CS_NAMESPACE
        

Generated by: LCOV version 2.4-beta