LCOV - code coverage report
Current view: top level - src/MIDI_Interfaces - MIDI_Sender.ipp (source / functions) Hit Total Coverage
Test: b8a30b4b7040ae1abf162fd0a258beaa2de43626 Lines: 98 98 100.0 %
Date: 2024-12-21 21:28:55 Functions: 34 35 97.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "MIDI_Sender.hpp"
       2             : #include <AH/Containers/CRTP.hpp>
       3             : 
       4             : BEGIN_CS_NAMESPACE
       5             : 
       6             : template <class Derived>
       7           2 : void MIDI_Sender<Derived>::sendChannelMessage(MIDIMessageType m, Channel c,
       8             :                                               uint8_t d1, uint8_t d2,
       9             :                                               Cable cable) {
      10           2 :     send(ChannelMessage(m, c, d1, d2, cable));
      11           2 : }
      12             : 
      13             : template <class Derived>
      14           2 : void MIDI_Sender<Derived>::sendChannelMessage(MIDIMessageType m, Channel c,
      15             :                                               uint8_t d1, Cable cable) {
      16           2 :     send(ChannelMessage(m, c, d1, 0, cable));
      17           2 : }
      18             : 
      19             : template <class Derived>
      20          27 : void MIDI_Sender<Derived>::sendNoteOn(MIDIAddress address, uint8_t velocity) {
      21          27 :     if (address)
      22          54 :         CRTP(Derived).sendChannelMessageImpl({
      23             :             MIDIMessageType::NoteOn,
      24          27 :             address.getChannel(),
      25          27 :             address.getAddress(),
      26          27 :             uint8_t(velocity & 0x7F),
      27             :             address.getCableNumber(),
      28             :         });
      29          27 : }
      30             : template <class Derived>
      31          22 : void MIDI_Sender<Derived>::sendNoteOff(MIDIAddress address, uint8_t velocity) {
      32          22 :     if (address)
      33          44 :         CRTP(Derived).sendChannelMessageImpl({
      34             :             MIDIMessageType::NoteOff,
      35          22 :             address.getChannel(),
      36          22 :             address.getAddress(),
      37          22 :             uint8_t(velocity & 0x7F),
      38             :             address.getCableNumber(),
      39             :         });
      40          22 : }
      41             : template <class Derived>
      42           2 : void MIDI_Sender<Derived>::sendKeyPressure(MIDIAddress address,
      43             :                                            uint8_t pressure) {
      44           2 :     if (address)
      45           4 :         CRTP(Derived).sendChannelMessageImpl({
      46             :             MIDIMessageType::KeyPressure,
      47           2 :             address.getChannel(),
      48           2 :             address.getAddress(),
      49           2 :             uint8_t(pressure & 0x7F),
      50             :             address.getCableNumber(),
      51             :         });
      52           2 : }
      53             : template <class Derived>
      54          81 : void MIDI_Sender<Derived>::sendControlChange(MIDIAddress address,
      55             :                                              uint8_t value) {
      56          81 :     if (address)
      57         162 :         CRTP(Derived).sendChannelMessageImpl({
      58             :             MIDIMessageType::ControlChange,
      59          81 :             address.getChannel(),
      60          81 :             address.getAddress(),
      61          81 :             uint8_t(value & 0x7F),
      62             :             address.getCableNumber(),
      63             :         });
      64          81 : }
      65             : template <class Derived>
      66           7 : void MIDI_Sender<Derived>::sendProgramChange(MIDIChannelCable address,
      67             :                                              uint8_t value) {
      68           7 :     if (address)
      69          14 :         CRTP(Derived).sendChannelMessageImpl({
      70             :             MIDIMessageType::ProgramChange,
      71           7 :             address.getChannel(),
      72           7 :             uint8_t(value & 0x7F),
      73             :             uint8_t(0x00),
      74             :             address.getCableNumber(),
      75             :         });
      76           7 : }
      77             : template <class Derived>
      78           2 : void MIDI_Sender<Derived>::sendProgramChange(MIDIAddress address) {
      79           2 :     if (address)
      80           4 :         CRTP(Derived).sendChannelMessageImpl({
      81             :             MIDIMessageType::ProgramChange,
      82           2 :             address.getChannel(),
      83           2 :             address.getAddress(),
      84             :             uint8_t(0x00),
      85             :             address.getCableNumber(),
      86             :         });
      87           2 : }
      88             : template <class Derived>
      89           2 : void MIDI_Sender<Derived>::sendChannelPressure(MIDIChannelCable address,
      90             :                                                uint8_t pressure) {
      91           2 :     if (address)
      92           4 :         CRTP(Derived).sendChannelMessageImpl({
      93             :             MIDIMessageType::ChannelPressure,
      94           2 :             address.getChannel(),
      95           2 :             uint8_t(pressure & 0x7F),
      96             :             uint8_t(0x00),
      97             :             address.getCableNumber(),
      98             :         });
      99           2 : }
     100             : template <class Derived>
     101          11 : void MIDI_Sender<Derived>::sendPitchBend(MIDIChannelCable address,
     102             :                                          uint16_t value) {
     103          11 :     if (address)
     104          22 :         CRTP(Derived).sendChannelMessageImpl({
     105             :             MIDIMessageType::PitchBend,
     106          11 :             address.getChannel(),
     107          11 :             uint8_t((value >> 0) & 0x7F),
     108          11 :             uint8_t((value >> 7) & 0x7F),
     109             :             address.getCableNumber(),
     110             :         });
     111          11 : }
     112             : template <class Derived>
     113          35 : void MIDI_Sender<Derived>::send(SysExMessage message) {
     114          35 :     if (message.length > 0)
     115          32 :         CRTP(Derived).sendSysExImpl(message);
     116          35 : }
     117             : 
     118             : template <class Derived>
     119          10 : void MIDI_Sender<Derived>::send(RealTimeMessage message) {
     120          10 :     if (message.isValid())
     121          10 :         CRTP(Derived).sendRealTimeImpl(message);
     122          10 : }
     123             : 
     124             : template <class Derived>
     125         136 : void MIDI_Sender<Derived>::send(ChannelMessage message) {
     126         136 :     if (message.hasValidChannelMessageHeader()) {
     127         136 :         message.sanitize();
     128         136 :         CRTP(Derived).sendChannelMessageImpl(message);
     129             :     }
     130         136 : }
     131             : 
     132             : template <class Derived>
     133           7 : void MIDI_Sender<Derived>::send(SysCommonMessage message) {
     134           7 :     if (message.hasValidSystemCommonHeader()) {
     135           7 :         message.sanitize();
     136           7 :         CRTP(Derived).sendSysCommonImpl(message);
     137             :     }
     138           7 : }
     139             : 
     140             : template <class Derived>
     141             : template <uint16_t N>
     142           9 : void MIDI_Sender<Derived>::sendSysEx(const uint8_t (&sysexdata)[N],
     143             :                                      Cable cable) {
     144           9 :     send(SysExMessage(sysexdata, N, cable));
     145           9 : }
     146             : template <class Derived>
     147           1 : void MIDI_Sender<Derived>::sendSysEx(const uint8_t *data, uint16_t length,
     148             :                                      Cable cable) {
     149           1 :     send(SysExMessage(data, length, cable));
     150           1 : }
     151             : 
     152             : template <class Derived>
     153             : void MIDI_Sender<Derived>::sendSysCommon(MIDIMessageType m, Cable cable) {
     154             :     send(SysCommonMessage(m, cable));
     155             : }
     156             : template <class Derived>
     157           1 : void MIDI_Sender<Derived>::sendSysCommon(MIDIMessageType m, uint8_t data1,
     158             :                                          Cable cable) {
     159           1 :     send(SysCommonMessage(m, data1, cable));
     160           1 : }
     161             : template <class Derived>
     162           2 : void MIDI_Sender<Derived>::sendSysCommon(MIDIMessageType m, uint8_t data1,
     163             :                                          uint8_t data2, Cable cable) {
     164           2 :     send(SysCommonMessage(m, data1, data2, cable));
     165           2 : }
     166             : 
     167             : template <class Derived>
     168             : void MIDI_Sender<Derived>::sendMTCQuarterFrame(uint8_t data, Cable cable) {
     169             :     send(SysCommonMessage(MIDIMessageType::MTCQuarterFrame, data, cable));
     170             : }
     171             : template <class Derived>
     172             : void MIDI_Sender<Derived>::sendMTCQuarterFrame(uint8_t messageType,
     173             :                                                uint8_t values, Cable cable) {
     174             :     sendMTCQuarterFrame((messageType << 4) | values, cable);
     175             : }
     176             : template <class Derived>
     177             : void MIDI_Sender<Derived>::sendSongPositionPointer(uint16_t spp, Cable cable) {
     178             :     SysCommonMessage msg(MIDIMessageType::SongPositionPointer, cable);
     179             :     msg.setData14bit(spp);
     180             :     send(msg);
     181             : }
     182             : template <class Derived>
     183             : void MIDI_Sender<Derived>::sendSongSelect(uint8_t song, Cable cable) {
     184             :     send(SysCommonMessage(MIDIMessageType::SongSelect, song, cable));
     185             : }
     186             : template <class Derived>
     187             : void MIDI_Sender<Derived>::sendTuneRequest(Cable cable) {
     188             :     send(SysCommonMessage(MIDIMessageType::TuneRequest, cable));
     189             : }
     190             : 
     191             : template <class Derived>
     192           2 : void MIDI_Sender<Derived>::sendRealTime(MIDIMessageType rt, Cable cable) {
     193           2 :     send(RealTimeMessage(rt, cable));
     194           2 : }
     195             : template <class Derived>
     196           4 : void MIDI_Sender<Derived>::sendRealTime(uint8_t rt, Cable cable) {
     197           4 :     send(RealTimeMessage(rt, cable));
     198           4 : }
     199             : 
     200             : template <class Derived>
     201             : void MIDI_Sender<Derived>::sendTimingClock(Cable cable) {
     202             :     sendRealTime(MIDIMessageType::TimingClock, cable);
     203             : }
     204             : template <class Derived>
     205             : void MIDI_Sender<Derived>::sendStart(Cable cable) {
     206             :     sendRealTime(MIDIMessageType::Start, cable);
     207             : }
     208             : template <class Derived>
     209             : void MIDI_Sender<Derived>::sendContinue(Cable cable) {
     210             :     sendRealTime(MIDIMessageType::Continue, cable);
     211             : }
     212             : template <class Derived>
     213             : void MIDI_Sender<Derived>::sendStop(Cable cable) {
     214             :     sendRealTime(MIDIMessageType::Stop, cable);
     215             : }
     216             : template <class Derived>
     217             : void MIDI_Sender<Derived>::sendActiveSensing(Cable cable) {
     218             :     sendRealTime(MIDIMessageType::ActiveSensing, cable);
     219             : }
     220             : template <class Derived>
     221             : void MIDI_Sender<Derived>::sendSystemReset(Cable cable) {
     222             :     sendRealTime(MIDIMessageType::SystemReset, cable);
     223             : }
     224             : 
     225             : template <class Derived>
     226          12 : void MIDI_Sender<Derived>::sendNow() {
     227          12 :     CRTP(Derived).sendNowImpl();
     228          12 : }
     229             : 
     230             : template <class Derived>
     231             : void MIDI_Sender<Derived>::sendKP(MIDIAddress address, uint8_t pressure) {
     232             :     sendKeyPressure(address, pressure);
     233             : }
     234             : template <class Derived>
     235             : void MIDI_Sender<Derived>::sendCC(MIDIAddress address, uint8_t value) {
     236             :     sendControlChange(address, value);
     237             : }
     238             : template <class Derived>
     239             : void MIDI_Sender<Derived>::sendPC(MIDIAddress address) {
     240             :     sendProgramChange(address);
     241             : }
     242             : template <class Derived>
     243             : void MIDI_Sender<Derived>::sendPC(MIDIChannelCable address, uint8_t value) {
     244             :     sendProgramChange(address, value);
     245             : }
     246             : template <class Derived>
     247             : void MIDI_Sender<Derived>::sendCP(MIDIChannelCable address, uint8_t pressure) {
     248             :     sendChannelPressure(address, pressure);
     249             : }
     250             : template <class Derived>
     251             : void MIDI_Sender<Derived>::sendPB(MIDIChannelCable address, uint16_t value) {
     252             :     sendPitchBend(address, value);
     253             : }
     254             : 
     255             : END_CS_NAMESPACE

Generated by: LCOV version 1.15