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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <Def/Def.hpp>
       4             : #include <Hardware/IncrementDecrementButtons.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           1 : class MIDIIncrementDecrementButtons : public MIDIOutputElement {
      16             :   protected:
      17             :     /**
      18             :      * @brief   Construct a new MIDIIncrementDecrementButtons.
      19             :      *
      20             :      * @todo    Documentation
      21             :      */
      22           1 :     MIDIIncrementDecrementButtons(const IncrementDecrementButtons &buttons,
      23             :                                   const MIDICNChannelAddress &address,
      24             :                                   uint8_t multiplier,
      25             :                                   const MIDICNChannelAddress &resetAddress,
      26             :                                   const RelativeSender &relativeSender,
      27             :                                   const ResetSender &resetSender)
      28           1 :         : buttons(buttons), address(address), multiplier(multiplier),
      29           1 :           resetAddress(resetAddress), relativeSender{relativeSender},
      30           3 :           resetSender{resetSender} {}
      31             : 
      32             :   public:
      33           0 :     void begin() override { buttons.begin(); }
      34             : 
      35           0 :     void update() override {
      36             :         using IncrDecrButtons = IncrementDecrementButtons;
      37           0 :         switch (buttons.update()) {
      38           0 :             case IncrDecrButtons::Increment: send(multiplier, address); break;
      39           0 :             case IncrDecrButtons::Decrement: send(-multiplier, address); break;
      40           0 :             case IncrDecrButtons::Reset: reset(); break;
      41           0 :             case IncrDecrButtons::Nothing: break;
      42           0 :             default: break;
      43             :         }
      44           0 :     }
      45             : 
      46           0 :     void send(long delta, const MIDICNChannelAddress &address) {
      47           0 :         relativeSender.send(delta, address);
      48           0 :     }
      49             : 
      50           0 :     void reset() {
      51           0 :         if (resetAddress) {
      52           0 :             resetSender.sendOn(resetAddress);
      53           0 :             resetSender.sendOff(resetAddress);
      54           0 :         }
      55           0 :     }
      56             : 
      57             : #ifdef INDIVIDUAL_BUTTON_INVERT
      58             :     void invert() { buttons.invert(); }
      59             : #endif
      60             : 
      61             :     IncrementDecrementButtons::State getButtonsState() const {
      62             :         return buttons.getState();
      63             :     }
      64             : 
      65             :   private:
      66             :     IncrementDecrementButtons buttons;
      67             :     const MIDICNChannelAddress address;
      68             :     const uint8_t multiplier;
      69             :     const MIDICNChannelAddress resetAddress;
      70             : 
      71             :   public:
      72             :     RelativeSender relativeSender;
      73             :     ResetSender resetSender;
      74             : };
      75             : 
      76             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6