Control Surface  1.2.0
MIDI Control Surface library for Arduino
IncrementSelector.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Selector.hpp"
5 
7 
8 template <setting_t N, class Callback = EmptySelectorCallback>
9 class GenericIncrementSelector : public GenericSelector<N, Callback> {
11 
12  public:
14  const Callback &callback,
16  : GenericSelector<N, Callback>{selectable, callback}, button{button} {}
17 
18  void begin() override {
19  Parent::begin();
20  button.begin();
21  }
22 
23  void update() override {
24  switch (button.update()) {
25  case AH::IncrementButton::Nothing: break;
26  case AH::IncrementButton::IncrementShort: // fallthrough
27  case AH::IncrementButton::IncrementLong: // fallthrough
29  this->increment(Wrap::Wrap);
30  break;
33  default: break;
34  }
35  }
36 
38  return button.getState();
39  }
40 
41 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
42  void invert() { button.invert(); }
43 #endif
44 
45  private:
47 };
48 
49 // -------------------------------------------------------------------------- //
50 
63 template <setting_t N>
64 class IncrementSelector : virtual public GenericIncrementSelector<N> {
65  public:
69 
72 };
73 
AH::IncrementButton::Nothing
@ Nothing
The counter must not be incremented.
Definition: IncrementButton.hpp:42
AH::IncrementButton::ReleasedShort
@ ReleasedShort
The button was released after a short press.
Definition: IncrementButton.hpp:46
GenericSelector::begin
void begin() override
Initialize this updatable.
Definition: Selector.hpp:73
GenericIncrementSelector::button
AH::IncrementButton button
Definition: IncrementSelector.hpp:46
GenericIncrementSelector::begin
void begin() override
Initialize this updatable.
Definition: IncrementSelector.hpp:18
IncrementSelector
Selector with one button that increments the selection.
Definition: IncrementSelector.hpp:64
AH::IncrementButton::begin
void begin()
Definition: IncrementButton.hpp:34
GenericIncrementSelector::invert
void invert()
Definition: IncrementSelector.hpp:42
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
AH::IncrementButton::State
State
An enumeration of the different actions to be performed by the counter.
Definition: IncrementButton.hpp:41
IncrementSelector::IncrementSelector
IncrementSelector(Selectable< N > &selectable, const AH::Button &button)
Definition: IncrementSelector.hpp:70
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Selectable
Definition: Selectable.hpp:11
GenericSelector< N, EmptySelectorCallback >::callback
EmptySelectorCallback callback
Definition: Selector.hpp:145
IncrementSelector::IncrementSelector
IncrementSelector(Selectable< N > &selectable, const AH::IncrementButton &button)
Definition: IncrementSelector.hpp:66
GenericSelector< N, EmptySelectorCallback >::increment
void increment(Wrap wrap)
Add one to the setting, wrap around or clamp, depending on the parameter, if the new setting would be...
Definition: Selector.hpp:110
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
GenericIncrementSelector::update
void update() override
Update this updatable.
Definition: IncrementSelector.hpp:23
GenericIncrementSelector::getButtonState
AH::IncrementButton::State getButtonState() const
Definition: IncrementSelector.hpp:37
Wrap
Wrap
An enumeration to set the behavior of selectors that are incremented (decremented) beyond their maxim...
Definition: Selector.hpp:14
GenericSelector
Definition: Selector.hpp:57
AH::IncrementButton::getState
State getState() const
Return the state of the increment button without updating it.
Definition: IncrementButton.hpp:60
GenericIncrementSelector
Definition: IncrementSelector.hpp:9
Selector.hpp
AH::IncrementButton::invert
void invert()
Definition: IncrementButton.hpp:64
AH::IncrementButton::update
State update()
Update and return the state of the increment button.
Definition: IncrementButton.hpp:53
IncrementButton.hpp
AH::IncrementButton::IncrementHold
@ IncrementHold
The counter must be incremented (still pressed).
Definition: IncrementButton.hpp:45
AH::IncrementButton
A class for buttons that increment some counter or setting.
Definition: IncrementButton.hpp:22
GenericSelector< N, EmptySelectorCallback >::selectable
Selectable< N > & selectable
Definition: Selector.hpp:142
AH::IncrementButton::ReleasedLong
@ ReleasedLong
The button was released after a long press.
Definition: IncrementButton.hpp:47
AH::IncrementButton::IncrementLong
@ IncrementLong
The counter must be incremented (after long press).
Definition: IncrementButton.hpp:44
GenericIncrementSelector::GenericIncrementSelector
GenericIncrementSelector(Selectable< N > &selectable, const Callback &callback, const AH::IncrementButton &button)
Definition: IncrementSelector.hpp:13
AH::IncrementButton::IncrementShort
@ IncrementShort
The counter must be incremented (after short press).
Definition: IncrementButton.hpp:43