Control Surface  1.1.0
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButtonLatching.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 
12 /**
13  * @brief A class for latching buttons and switches that send MIDI events.
14  *
15  * The button is debounced.
16  *
17  * @see AH::Button
18  */
19 template <class BankAddress, class Sender>
21  protected:
22  /**
23  * @brief Construct a new MIDIButtonLatching.
24  *
25  * @param bankAddress
26  * The bankable MIDI address to send to.
27  * @param pin
28  * The digital input pin with the button connected.
29  * The internal pull-up resistor will be enabled.
30  * @param sender
31  * The MIDI sender to use.
32  */
33  MIDIButtonLatching(const BankAddress &bankAddress, pin_t pin,
34  const Sender &sender)
35  : address{bankAddress}, button{pin}, sender{sender} {}
36 
37  public:
38  void begin() override { button.begin(); }
39  void update() override {
41  if (state == AH::Button::Falling || state == AH::Button::Rising) {
42  MIDICNChannelAddress sendAddress = address.getActiveAddress();
43  sender.sendOn(sendAddress);
44  sender.sendOff(sendAddress);
45  }
46  }
47 
49 
50  private:
51  BankAddress address;
53 
54  public:
55  Sender sender;
56 };
57 
58 } // namespace Bankable
59 
Bankable::MIDIButtonLatching::button
AH::Button button
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:52
AH::Button::Rising
< Input went from high to low (1,0)
Definition: Button.hpp:57
AH::Updatable
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:25
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
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
MIDIOutputElement.hpp
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Bankable::MIDIButtonLatching::MIDIButtonLatching
MIDIButtonLatching(const BankAddress &bankAddress, pin_t pin, const Sender &sender)
Construct a new MIDIButtonLatching.
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:33
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Bankable::MIDIButtonLatching::sender
Sender sender
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:55
Bankable::MIDIButtonLatching::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:39
AH::Button::getState
State getState() const
Get the state of the button, without updating it.
Definition: Button.cpp:36
Bankable::MIDIButtonLatching::address
BankAddress address
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:51
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:11
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
AH::Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:19
Bankable::MIDIButtonLatching::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:38
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
Bankable::MIDIButtonLatching::getButtonState
AH::Button::State getButtonState() const
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:48
Bankable::MIDIButtonLatching
A class for latching buttons and switches that send MIDI events.
Definition: Bankable/Abstract/MIDIButtonLatching.hpp:20
AH::Button::Falling
< Input went from high to high (1,1)
Definition: Button.hpp:56