LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Abstract - MIDIIncrementDecrementButtons.hpp (source / functions) Hit Total Coverage
Test: 3a807a259ebe0769dd942f7f612dca5273937539 Lines: 4 25 16.0 %
Date: 2024-03-24 17:16:54 Functions: 1 5 20.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Hardware/IncrementDecrementButtons.hpp>
       4             : #include <Def/Def.hpp>
       5             : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>
       6             : 
       7             : #include <MIDI_Senders/DigitalNoteSender.hpp>
       8             : 
       9             : BEGIN_CS_NAMESPACE
      10             : 
      11             : /**
      12             :  * @brief   An abstract class for two buttons that send incremental MIDI events.
      13             :  */
      14             : template <class RelativeSender, class ResetSender>
      15             : class MIDIIncrementDecrementButtons : public MIDIOutputElement {
      16             :   protected:
      17             :     /**
      18             :      * @brief   Construct a new MIDIIncrementDecrementButtons.
      19             :      *
      20             :      * @todo    Documentation
      21             :      */
      22           1 :     MIDIIncrementDecrementButtons(const AH::IncrementDecrementButtons &buttons,
      23             :                                   MIDIAddress address, uint8_t multiplier,
      24             :                                   MIDIAddress resetAddress,
      25             :                                   const RelativeSender &relativeSender,
      26             :                                   const ResetSender &resetSender)
      27           1 :         : buttons(buttons), address(address), multiplier(multiplier),
      28           1 :           resetAddress(resetAddress), relativeSender(relativeSender),
      29           2 :           resetSender(resetSender) {}
      30             : 
      31             :   public:
      32           0 :     void begin() override { buttons.begin(); }
      33             : 
      34           0 :     void update() override {
      35             :         using IncrDecrButtons = AH::IncrementDecrementButtons;
      36           0 :         switch (buttons.update()) {
      37           0 :             case IncrDecrButtons::Nothing: break;
      38           0 :             case IncrDecrButtons::IncrementShort: // fallthrough
      39             :             case IncrDecrButtons::IncrementLong:  // fallthrough
      40             :             case IncrDecrButtons::IncrementHold:
      41           0 :                 send(multiplier, address);
      42           0 :                 break;
      43           0 :             case IncrDecrButtons::DecrementShort: // fallthrough
      44             :             case IncrDecrButtons::DecrementLong:  // fallthrough
      45             :             case IncrDecrButtons::DecrementHold:
      46           0 :                 send(-multiplier, address);
      47           0 :                 break;
      48           0 :             case IncrDecrButtons::Reset: reset(); break;
      49           0 :             default: break;
      50             :         }
      51           0 :     }
      52             : 
      53           0 :     void send(long delta, MIDIAddress address) {
      54           0 :         relativeSender.send(delta, address);
      55           0 :     }
      56             : 
      57           0 :     void reset() {
      58           0 :         if (resetAddress) {
      59           0 :             resetSender.sendOn(resetAddress);
      60           0 :             resetSender.sendOff(resetAddress);
      61             :         }
      62           0 :     }
      63             : 
      64             :     /// @see @ref AH::Button::invert()
      65             :     void invert() { buttons.invert(); }
      66             : 
      67             :     AH::IncrementDecrementButtons::State getButtonsState() const {
      68             :         return buttons.getState();
      69             :     }
      70             : 
      71             :     /// Get the MIDI address.
      72             :     MIDIAddress getAddress() const { return this->address; }
      73             :     /// Set the MIDI address.
      74             :     void setAddress(MIDIAddress address) { this->address = address; }
      75             : 
      76             :     /// Get the MIDI address of the reset action.
      77             :     MIDIAddress getResetAddress() const { return this->resetAddress; }
      78             :     /// Set the MIDI address of the reset action.
      79             :     void setResetAddress(MIDIAddress address) { this->resetAddress = address; }
      80             : 
      81             :   private:
      82             :     AH::IncrementDecrementButtons buttons;
      83             :     MIDIAddress address;
      84             :     uint8_t multiplier;
      85             :     MIDIAddress resetAddress;
      86             : 
      87             :   public:
      88             :     RelativeSender relativeSender;
      89             :     ResetSender resetSender;
      90             : };
      91             : 
      92             : END_CS_NAMESPACE

Generated by: LCOV version 1.15