Control Surface  1.1.1
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButton.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 
19 template <class BankAddress, class Sender>
20 class MIDIButton : public MIDIOutputElement {
21  public:
33  MIDIButton(const BankAddress &bankAddress, pin_t pin, const Sender &sender)
34  : address{bankAddress}, button{pin}, sender(sender) {}
35 
36  void begin() override { button.begin(); }
37  void update() override {
39  if (state == AH::Button::Falling) {
40  address.lock();
41  sender.sendOn(address.getActiveAddress());
42  } else if (state == AH::Button::Rising) {
43  sender.sendOff(address.getActiveAddress());
44  address.unlock();
45  }
46  }
47 
48 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
49  void invert() { button.invert(); }
50 #endif
51 
53 
54  private:
55  BankAddress address;
57 
58  public:
59  Sender sender;
60 };
61 
62 } // namespace Bankable
63 
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::Falling
Input went from high to low (1,0)
Definition: Button.hpp:56
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
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
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
AH::Button::invert
AH_INDIVIDUAL_BUTTON_INVERT_STATIC void invert()
Invert the state of all buttons, or of this specific button (button pressed is HIGH instead of LOW).
Definition: Button.cpp:13
Bankable::MIDIButton::button
AH::Button button
Definition: Bankable/Abstract/MIDIButton.hpp:56
MIDIOutputElement.hpp
Bankable::MIDIButton::invert
void invert()
Definition: Bankable/Abstract/MIDIButton.hpp:49
Def.hpp
Bankable::MIDIButton::sender
Sender sender
Definition: Bankable/Abstract/MIDIButton.hpp:59
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Bankable::MIDIButton
An abstract class for momentary push buttons that send MIDI events.
Definition: Bankable/Abstract/MIDIButton.hpp:20
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Bankable::MIDIButton::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIButton.hpp:37
AH::Button::Rising
Input went from low to high (0,1)
Definition: Button.hpp:57
Bankable::MIDIButton::MIDIButton
MIDIButton(const BankAddress &bankAddress, pin_t pin, const Sender &sender)
Construct a new bankable MIDIButton.
Definition: Bankable/Abstract/MIDIButton.hpp:33
Bankable::MIDIButton::getButtonState
AH::Button::State getButtonState() const
Definition: Bankable/Abstract/MIDIButton.hpp:52
Bankable::MIDIButton::address
BankAddress address
Definition: Bankable/Abstract/MIDIButton.hpp:55
Bankable::MIDIButton::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIButton.hpp:36
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:11
AH::Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:19