Control Surface  1.2.0
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButtonLatched.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <AH/Hardware/Button.hpp>
6 #include <Def/Def.hpp>
8 
10 
11 namespace Bankable {
12 
21 template <uint8_t NumBanks, class BankAddress, class Sender>
23  protected:
36  MIDIButtonLatched(BankAddress bankAddress, pin_t pin,
37  const Sender &sender)
38  : address{bankAddress}, button{pin}, sender{sender} {}
39 
40  public:
41  void begin() override { button.begin(); }
42 
43  void update() override {
45  if (state == AH::Button::Falling)
46  toggleState();
47  }
48 
49  bool toggleState() {
50  bool newstate = !getState();
51  setState(newstate);
52  return newstate;
53  }
54 
55  bool getState() const { return states.get(address.getSelection()); }
56 
57  void setState(bool state) {
58  states.set(address.getSelection(), state);
59  if (state) {
60  sender.sendOn(address.getActiveAddress());
61  } else {
62  sender.sendOff(address.getActiveAddress());
63  }
64  }
65 
67 
68  private:
69  BankAddress address;
72 
73  public:
74  Sender sender;
75 };
76 
77 } // namespace Bankable
78 
AH::Updatable<>
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
@ Falling
Input went from high to low (1,0)
Definition: Button.hpp:56
Bankable::MIDIButtonLatched::sender
Sender sender
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:74
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:49
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:43
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:57
Def.hpp
BitArray.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
AH::BitArray::set
void set(uint8_t bitIndex)
Set the value of the given bit to 1.
Definition: BitArray.hpp:43
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
AH::BitArray::get
bool get(uint8_t bitIndex) const
Get the value of the given bit.
Definition: BitArray.hpp:33
Bankable::MIDIButtonLatched::getState
bool getState() const
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:55
Bankable::MIDIButtonLatched::states
AH::BitArray< NumBanks > states
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:71
Bankable::MIDIButtonLatched::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:41
Bankable::MIDIButtonLatched::address
BankAddress address
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:69
BankableAddresses.hpp
Bankable::MIDIButtonLatched::button
AH::Button button
Definition: Bankable/Abstract/MIDIButtonLatched.hpp:70
AH::BitArray< NumBanks >
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:22
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:66
Bankable::MIDIButtonLatched::MIDIButtonLatched
MIDIButtonLatched(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:36