Control Surface 2.1.2
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Abstract/MIDIButtonLatched.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
6#include <Def/Def.hpp>
8
10
19template <class Sender>
21 protected:
36
37 public:
38 void begin() final override { button.begin(); }
39 void update() final override {
43 }
44
47 bool toggleState() {
49 return getState();
50 }
51
53 bool getState() const { return state; }
54
57 void setState(bool state) {
58 this->state = state;
59 state ? sender.sendOn(address) : sender.sendOff(address);
60 }
61
63 void invert() { button.invert(); }
64
66 AH::Button::State getButtonState() const { return button.getState(); }
67
69 MIDIAddress getAddress() const { return this->address; }
72 void setAddressUnsafe(MIDIAddress address) { this->address = address; }
73
74 private:
77 bool state = false;
78
79 public:
80 Sender sender;
81};
82
AH::Updatable<> MIDIOutputElement
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for reading and debouncing buttons and switches.
Definition Button.hpp:15
State
An enumeration of the different states a button can be in.
Definition Button.hpp:47
@ Falling
Input went from high to low (1,0).
Definition Button.hpp:50
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
MIDIButtonLatched(pin_t pin, MIDIAddress address, const Sender &sender)
Create a new MIDIButtonLatched object on the given pin and address.
bool getState() const
Get the current state.
void setAddressUnsafe(MIDIAddress address)
Set the MIDI address.
AH::Button::State getButtonState() const
Get the state of the underlying button.
bool toggleState()
Flip the state (on → off or off → on).
MIDIAddress getAddress() const
Get the MIDI address.
void begin() final override
Initialize this updatable.
void setState(bool state)
Set the state to the given value.
void update() final override
Update this updatable.
Type for storing pin numbers of Extended Input/Output elements.