LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Abstract - MIDIButtons.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 19 19 100.0 %
Date: 2019-11-24 14:50:27 Functions: 8 15 53.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14-5-g4ff2ed6