LCOV - code coverage report
Current view: top level - src/MIDI_Interfaces - DebugMIDI_Interface.cpp (source / functions) Hit Total Coverage
Test: ffed98f648fe78e7aa7bdd228474317d40dadbec Lines: 61 89 68.5 %
Date: 2022-05-28 15:22:59 Functions: 9 17 52.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.15