LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIIncrementDecrementButtons.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 4 24 16.7 %
Date: 2019-11-24 14:50:27 Functions: 4 14 28.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14-5-g4ff2ed6