LCOV - code coverage report
Current view: top level - src/MIDI_Interfaces - MIDI_Interface.ipp (source / functions) Hit Total Coverage
Test: e224b347cd670555e44f06608ac41bd1ace9d9d8 Lines: 83 85 97.6 %
Date: 2020-09-08 17:44:46 Functions: 21 23 91.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "MIDI_Interface.hpp"
       2             : #include <Def/CRTP.hpp>
       3             : 
       4             : BEGIN_CS_NAMESPACE
       5             : 
       6             : template <class Derived>
       7           2 : void MIDI_Sender<Derived>::send(MIDIMessageType m, Channel c, uint8_t d1,
       8             :                                 uint8_t d2, Cable cable) {
       9           2 :     sendOnCable(m, c, d1, d2, cable);
      10           2 : }
      11             : 
      12             : template <class Derived>
      13           2 : void MIDI_Sender<Derived>::send(MIDIMessageType m, Channel c, uint8_t d1,
      14             :                                 Cable cable) {
      15           2 :     sendOnCable(m, c, d1, cable);
      16           2 : }
      17             : 
      18             : template <class Derived>
      19         118 : void MIDI_Sender<Derived>::sendOnCable(MIDIMessageType m, Channel c, uint8_t d1,
      20             :                                        uint8_t d2, Cable cable) {
      21         118 :     uint8_t mm = static_cast<uint8_t>(m);
      22         118 :     uint8_t cc = c.getRaw();
      23         118 :     mm &= 0xF0;       // bitmask high nibble
      24         118 :     mm |= 0b10000000; // set msb
      25         118 :     d1 &= 0x7F;       // clear msb
      26         118 :     d2 &= 0x7F;       // clear msb
      27         118 :     CRTP(Derived).sendImpl(mm | cc, d1, d2, cable.getRaw());
      28         118 : }
      29             : 
      30             : template <class Derived>
      31          11 : void MIDI_Sender<Derived>::sendOnCable(MIDIMessageType m, Channel c, uint8_t d1,
      32             :                                        Cable cable) {
      33          11 :     uint8_t mm = static_cast<uint8_t>(m);
      34          11 :     uint8_t cc = c.getRaw();
      35          11 :     mm &= 0xF0;       // bitmask high nibble
      36          11 :     mm |= 0b10000000; // set msb
      37          11 :     d1 &= 0x7F;       // clear msb
      38          11 :     CRTP(Derived).sendImpl(mm | cc, d1, cable.getRaw());
      39          11 : }
      40             : 
      41             : template <class Derived>
      42           1 : void MIDI_Sender<Derived>::sendOnCable(MIDIMessageType r, Cable cable) {
      43           1 :     uint8_t rr = static_cast<uint8_t>(r);
      44           1 :     rr |= 0b10000000; // set msb
      45           1 :     CRTP(Derived).sendImpl(rr, cable.getRaw());
      46           1 : }
      47             : 
      48             : template <class Derived>
      49          21 : void MIDI_Sender<Derived>::sendNoteOn(MIDIAddress address, uint8_t velocity) {
      50          21 :     if (address)
      51          42 :         sendOnCable(MIDIMessageType::NOTE_ON, address.getChannel(),
      52          21 :                     address.getAddress(), velocity, address.getCableNumber());
      53          21 : }
      54             : template <class Derived>
      55          20 : void MIDI_Sender<Derived>::sendNoteOff(MIDIAddress address, uint8_t velocity) {
      56          20 :     if (address)
      57          40 :         sendOnCable(MIDIMessageType::NOTE_OFF, address.getChannel(),
      58          20 :                     address.getAddress(), velocity, address.getCableNumber());
      59          20 : }
      60             : template <class Derived>
      61           2 : void MIDI_Sender<Derived>::sendKP(MIDIAddress address, uint8_t pressure) {
      62           2 :     if (address)
      63           4 :         sendOnCable(MIDIMessageType::KEY_PRESSURE, address.getChannel(),
      64           2 :                     address.getAddress(), pressure, address.getCableNumber());
      65           2 : }
      66             : template <class Derived>
      67          60 : void MIDI_Sender<Derived>::sendCC(MIDIAddress address, uint8_t value) {
      68          60 :     if (address)
      69         120 :         sendOnCable(MIDIMessageType::CONTROL_CHANGE, address.getChannel(),
      70          60 :                     address.getAddress(), value, address.getCableNumber());
      71          60 : }
      72             : template <class Derived>
      73           3 : void MIDI_Sender<Derived>::sendPC(MIDIChannelCN address, uint8_t value) {
      74           3 :     if (address)
      75           6 :         sendOnCable(MIDIMessageType::PROGRAM_CHANGE, address.getChannel(),
      76           3 :                     value, address.getCableNumber());
      77           3 : }
      78             : template <class Derived>
      79           2 : void MIDI_Sender<Derived>::sendPC(MIDIAddress address) {
      80           2 :     if (address)
      81           4 :         sendOnCable(MIDIMessageType::PROGRAM_CHANGE, address.getChannel(),
      82           2 :                     address.getAddress(), address.getCableNumber());
      83           2 : }
      84             : template <class Derived>
      85           2 : void MIDI_Sender<Derived>::sendCP(MIDIChannelCN address, uint8_t pressure) {
      86           2 :     if (address)
      87           4 :         sendOnCable(MIDIMessageType::CHANNEL_PRESSURE, address.getChannel(),
      88           2 :                     pressure, address.getCableNumber());
      89           2 : }
      90             : template <class Derived>
      91          11 : void MIDI_Sender<Derived>::sendPB(MIDIChannelCN address, uint16_t value) {
      92          11 :     if (address)
      93          22 :         sendOnCable(MIDIMessageType::PITCH_BEND, address.getChannel(),
      94          11 :                     value & 0x7F, value >> 7, address.getCableNumber());
      95          11 : }
      96             : template <class Derived>
      97          21 : void MIDI_Sender<Derived>::send(SysExMessage message) {
      98          21 :     if (message.length) {
      99          18 :         if (message.length < 2) {
     100           3 :             ERROR(F("Error: invalid SysEx length"), 0x7F7F);
     101           0 :             return;
     102             :         }
     103          15 :         CRTP(Derived).sendImpl(message.data, message.length, message.CN);
     104          15 :     }
     105          21 : }
     106             : template <class Derived>
     107             : void MIDI_Sender<Derived>::send(MIDIMessageType rt, Cable cable) {
     108             :     CRTP(Derived).sendImpl(rt, cable.getRaw());
     109             : }
     110             : 
     111             : template <class Derived>
     112           2 : void MIDI_Sender<Derived>::send(RealTimeMessage message) {
     113           2 :     CRTP(Derived).sendImpl(message.message, message.CN);
     114           2 : }
     115             : 
     116             : template <class Derived>
     117         106 : void MIDI_Sender<Derived>::send(ChannelMessage message) {
     118         106 :     if (message.hasTwoDataBytes())
     119         212 :         CRTP(Derived).sendImpl(message.header, message.data1, message.data2,
     120         106 :                                message.CN);
     121             :     else
     122           0 :         CRTP(Derived).sendImpl(message.header, message.data1, message.CN);
     123         106 : }
     124             : 
     125             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-6-g40580cd