Control Surface new-input
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 {
25  switch (button.update()) {
26  case AH::IncrementButton::Nothing: break;
27  case AH::IncrementButton::IncrementShort: // fallthrough
28  case AH::IncrementButton::IncrementLong: // fallthrough
30  this->increment(Wrap::Wrap);
31  break;
34  default: break;
35  }
36  }
37 
39  return button.getState();
40  }
41 
42 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
43  void invert() { button.invert(); }
44 #endif
45 
46  private:
48 };
49 
50 // -------------------------------------------------------------------------- //
51 
64 template <setting_t N>
65 class IncrementSelector : virtual public GenericIncrementSelector<N> {
66  public:
70 
73 };
74 
@ Wrap
When the maximum (minimum) setting is reached, wrap around to the minimum (maximum) setting.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
A class for buttons that increment some counter or setting.
State
An enumeration of the different actions to be performed by the counter.
@ Nothing
The counter must not be incremented.
@ IncrementShort
The counter must be incremented (after short press).
@ IncrementHold
The counter must be incremented (still pressed).
@ ReleasedLong
The button was released after a long press.
@ IncrementLong
The counter must be incremented (after long press).
@ ReleasedShort
The button was released after a short press.
State getState() const
Return the state of the increment button without updating it.
State update()
Update and return the state of the increment button.
AH::IncrementButton::State getButtonState() const
AH::IncrementButton button
void update() override
Update this updatable.
void begin() override
Initialize this updatable.
GenericIncrementSelector(Selectable< N > &selectable, const Callback &callback, const AH::IncrementButton &button)
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:109
void update() override
Update this updatable.
Definition: Selector.hpp:77
void begin() override
Initialize this updatable.
Definition: Selector.hpp:72
Selector with one button that increments the selection.
IncrementSelector(Selectable< N > &selectable, const AH::Button &button)
IncrementSelector(Selectable< N > &selectable, const AH::IncrementButton &button)