LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Abstract - MIDIButtons.hpp (source / functions) Hit Total Coverage
Test: e224b347cd670555e44f06608ac41bd1ace9d9d8 Lines: 20 20 100.0 %
Date: 2020-09-08 17:44:46 Functions: 8 15 53.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Hardware/Button.hpp>
       4             : #include <Def/Def.hpp>
       5             : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>
       6             : 
       7             : BEGIN_CS_NAMESPACE
       8             : 
       9             : /**
      10             :  * @brief   An abstract class for momentary push buttons that send MIDI events.
      11             :  *
      12             :  * The buttons are debounced.
      13             :  *
      14             :  * @see     Button
      15             :  */
      16             : template <class Sender, uint8_t NumButtons>
      17           3 : class MIDIButtons : public MIDIOutputElement {
      18             :   protected:
      19             :     /**
      20             :      * @brief   Construct a new MIDIButtons.
      21             :      *
      22             :      * @todo    Documentation
      23             :      */
      24           3 :     MIDIButtons(const Array<AH::Button, NumButtons> &buttons,
      25             :                 const MIDIAddress &baseAddress,
      26             :                 const RelativeMIDIAddress &incrementAddress,
      27             :                 const Sender &sender)
      28           3 :         : buttons{buttons}, baseAddress(baseAddress),
      29           9 :           incrementAddress(incrementAddress), sender{sender} {}
      30             : 
      31             :   public:
      32           1 :     void begin() final override {
      33           3 :         for (auto &button : buttons)
      34           2 :             button.begin();
      35           1 :     }
      36           7 :     void update() final override {
      37           7 :         MIDIAddress address = baseAddress;
      38          21 :         for (auto &button : buttons) {
      39          14 :             AH::Button::State state = button.update();
      40          14 :             if (state == AH::Button::Falling) {
      41           2 :                 sender.sendOn(address);
      42          14 :             } else if (state == AH::Button::Rising) {
      43           2 :                 sender.sendOff(address);
      44           2 :             }
      45          14 :             address += incrementAddress;
      46          14 :         }
      47           7 :     }
      48             : 
      49             :     AH::Button::State getButtonState(size_t index) const {
      50             :         return buttons[index].getState();
      51             :     }
      52             : 
      53             : #ifdef AH_INDIVIDUAL_BUTTON_INVERT
      54             :     void invert() {
      55             :         for (auto &button : buttons)
      56             :             button.invert();
      57             :     }
      58             : #endif
      59             : 
      60             :   private:
      61             :     Array<AH::Button, NumButtons> buttons;
      62             :     const MIDIAddress baseAddress;
      63             :     const RelativeMIDIAddress incrementAddress;
      64             : 
      65             :   public:
      66             :     Sender sender;
      67             : };
      68             : 
      69             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-6-g40580cd