Control Surface  1.1.1
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButtonLatched.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <AH/Hardware/Button.hpp>
5 #include <Def/Def.hpp>
7 
9 
10 namespace Bankable {
11 
20 template <class BankAddress, class Sender>
22  protected:
35  MIDIButtonLatched(const BankAddress &bankAddress, pin_t pin,
36  const Sender &sender)
37  : address{bankAddress}, button{pin}, sender{sender} {}
38 
39  public:
40  void begin() override { button.begin(); }
41  void update() override {
44  toggleState();
45  }
46 
47  bool toggleState() {
48  setState(!getState());
49  return getState();
50  }
51  bool getState() const { return state; }
52  void setState(bool state) {
53  this->state = state;
54  if (state) {
55  address.lock();
56  sender.sendOn(address.getActiveAddress());
57  } else {
58  sender.sendOff(address.getActiveAddress());
59  address.unlock();
60  }
61  }
62 
64 
65  private:
66  BankAddress address;
68  bool state = false;
69 
70  public:
71  Sender sender;
72 };
73 
74 } // namespace Bankable
75 
AH::Updatable<>
BankableMIDIOutput.hpp
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition: BankAddresses.hpp:7
Button.hpp
AH::Button::Falling
Input went from high to low (1,0)
Definition: Button.hpp:56
Bankable::MIDIButtonLatched::sender
Sender sender
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:71
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
Bankable::MIDIButtonLatched::toggleState
bool toggleState()
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:47
AH::Button::getState
State getState() const
Get the state of the button, without updating it.
Definition: Button.cpp:36
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
Bankable::MIDIButtonLatched::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:41
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
MIDIOutputElement.hpp
Bankable::MIDIButtonLatched::setState
void setState(bool state)
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:52
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Bankable::MIDIButtonLatched::MIDIButtonLatched
MIDIButtonLatched(const BankAddress &bankAddress, pin_t pin, const Sender &sender)
Create a new bankable MIDIButtonLatched object on the given pin and address.
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:35
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Bankable::MIDIButtonLatched::state
bool state
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:68
Bankable::MIDIButtonLatched::getState
bool getState() const
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:51
Bankable::MIDIButtonLatched::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:40
Bankable::MIDIButtonLatched::address
BankAddress address
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:66
Bankable::MIDIButtonLatched::button
AH::Button button
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:67
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:11
Bankable::MIDIButtonLatched
A class for momentary buttons and switches that send MIDI events.
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:21
AH::Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:19
Bankable::MIDIButtonLatched::getButtonState
AH::Button::State getButtonState() const
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:63