LCOV - code coverage report
Current view: top level - src/Selectors - ProgramChangeSelector.hpp (source / functions) Hit Total Coverage
Test: ffed98f648fe78e7aa7bdd228474317d40dadbec Lines: 4 11 36.4 %
Date: 2022-05-28 15:22:59 Functions: 3 14 21.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <MIDI_Inputs/MIDIInputElement.hpp>
       4             : #include <MIDI_Inputs/MIDIInputElementMatchers.hpp>
       5             : #include <Selectors/Selector.hpp>
       6             : 
       7             : BEGIN_CS_NAMESPACE
       8             : 
       9             : template <setting_t N, class Callback = EmptySelectorCallback>
      10             : class GenericProgramChangeSelector
      11             :     : public GenericSelector<N, Callback>,
      12             :       public MatchingMIDIInputElement<MIDIMessageType::PROGRAM_CHANGE,
      13             :                                       OneByteMIDIMatcher> {
      14             :   public:
      15             :     using Matcher = OneByteMIDIMatcher;
      16             :     using Parent = MatchingMIDIInputElement<MIDIMessageType::PROGRAM_CHANGE,
      17             :                                             Matcher>;
      18             : 
      19           2 :     GenericProgramChangeSelector(Selectable<N> &selectable,
      20             :                                  const Callback &callback,
      21             :                                  MIDIChannelCable address)
      22             :         : GenericSelector<N, Callback>{selectable, callback},
      23           2 :           Parent(address) {}
      24             : 
      25           0 :     void begin() override { GenericSelector<N, Callback>::begin(); }
      26             : 
      27           0 :     void reset() override { GenericSelector<N, Callback>::reset(); }
      28             : 
      29           0 :     void handleUpdate(typename Matcher::Result match) override {
      30           0 :         uint8_t program = match.value;
      31           0 :         if (program < N) {
      32           0 :             this->set(program);
      33             :         } else {
      34             :             DEBUGFN(F("Warning: Received Program Change to program 0x")
      35             :                     << hex << program << dec
      36             :                     << F(", which is not smaller than the number of settings (")
      37             :                     << N << ')');
      38             :         }
      39           0 :     }
      40             : };
      41             : 
      42             : /**
      43             :  * @brief   Selector that listens for MIDI Program Change events on a given
      44             :  *          MIDI Channel, and uses the program number as its selection.
      45             :  * 
      46             :  * @tparam  N 
      47             :  *          The number of settings. The maximum program number is @f$ N - 1 @f$.
      48             :  * @ingroup Selectors
      49             :  */
      50             : template <setting_t N>
      51             : class ProgramChangeSelector : public GenericProgramChangeSelector<N> {
      52             :   public:
      53           1 :     ProgramChangeSelector(Selectable<N> &selectable,
      54             :                           MIDIChannelCable address)
      55           1 :         : GenericProgramChangeSelector<N>{selectable, {}, address} {}
      56             : };
      57             : 
      58             : END_CS_NAMESPACE

Generated by: LCOV version 1.15