LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIIncrementDecrementButtons.hpp (source / functions) Hit Total Coverage
Test: 169c36a3797bc662d84b5726f34a3f37d3c58247 Lines: 3 26 11.5 %
Date: 2024-11-09 15:32:27 Functions: 2 10 20.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.15