LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIRotaryEncoder.hpp (source / functions) Hit Total Coverage
Test: ffed98f648fe78e7aa7bdd228474317d40dadbec Lines: 8 9 88.9 %
Date: 2022-05-28 15:22:59 Functions: 3 6 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/STL/utility> // std::forward
       4             : #include <Banks/BankableAddresses.hpp>
       5             : #include <Def/Def.hpp>
       6             : #include <Def/TypeTraits.hpp>
       7             : #include <MIDI_Outputs/Abstract/EncoderState.hpp>
       8             : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>
       9             : 
      10             : #ifdef ARDUINO
      11             : #include <Submodules/Encoder/AHEncoder.hpp>
      12             : #else
      13             : #include <Encoder.h> // Mock
      14             : #endif
      15             : 
      16             : AH_DIAGNOSTIC_WERROR()
      17             : 
      18             : BEGIN_CS_NAMESPACE
      19             : 
      20             : namespace Bankable {
      21             : 
      22             : /**
      23             :  * @brief   An abstract class for rotary encoders that send MIDI events and that
      24             :  *          can be added to a Bank.
      25             :  */
      26             : template <class Enc, class BankAddress, class Sender>
      27             : class GenericMIDIRotaryEncoder : public MIDIOutputElement {
      28             :   protected:
      29             :     /**
      30             :      * @brief   Construct a new GenericMIDIRotaryEncoder.
      31             :      *
      32             :      * @todo    Documentation
      33             :      */
      34           3 :     GenericMIDIRotaryEncoder(BankAddress bankAddress, Enc &&encoder,
      35             :                              int16_t speedMultiply, uint8_t pulsesPerStep,
      36             :                              const Sender &sender)
      37           3 :         : address(bankAddress), encoder(std::forward<Enc>(encoder)),
      38           6 :           encstate(speedMultiply, pulsesPerStep), sender(sender) {}
      39             : 
      40             :   public:
      41           0 :     void begin() override { begin_if_possible(encoder); }
      42             : 
      43           2 :     void update() override {
      44           2 :         auto encval = encoder.read();
      45           2 :         if (int16_t delta = encstate.update(encval)) {
      46           2 :             sender.send(delta, address.getActiveAddress());
      47             :         }
      48           2 :     }
      49             : 
      50             :     void setSpeedMultiply(int16_t speedMultiply) {
      51             :         encstate.setSpeedMultiply(speedMultiply);
      52             :     }
      53             :     int16_t getSpeedMultiply() const { return encstate.getSpeedMultiply(); }
      54             : 
      55             :   protected:
      56             :     BankAddress address;
      57             :     Enc encoder;
      58             :     EncoderState<decltype(encoder.read())> encstate;
      59             : 
      60             :   public:
      61             :     Sender sender;
      62             : };
      63             : 
      64             : template <class BankAddress, class Sender>
      65             : using MIDIRotaryEncoder =
      66             :     GenericMIDIRotaryEncoder<AHEncoder, BankAddress, Sender>;
      67             : 
      68             : template <class BankAddress, class Sender>
      69             : using BorrowedMIDIRotaryEncoder =
      70             :     GenericMIDIRotaryEncoder<AHEncoder &, BankAddress, Sender>;
      71             : 
      72             : } // namespace Bankable
      73             : 
      74             : END_CS_NAMESPACE
      75             : 
      76             : AH_DIAGNOSTIC_POP()

Generated by: LCOV version 1.15