Control Surface  1.2.0
MIDI Control Surface library for Arduino
Abstract/MIDIButton.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <AH/Hardware/Button.hpp>
4 #include <Def/Def.hpp>
6 
8 
16 template <class Sender>
17 class MIDIButton : public MIDIOutputElement {
18  public:
31  const Sender &sender)
32  : button{pin}, address{address}, sender(sender) {}
33 
34  void begin() override { button.begin(); }
35  void update() override {
37  if (state == AH::Button::Falling) {
38  sender.sendOn(address);
39  } else if (state == AH::Button::Rising) {
40  sender.sendOff(address);
41  }
42  }
43 
44 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
45  void invert() { button.invert(); }
46 #endif
47 
49 
50  private:
53 
54  public:
55  Sender sender;
56 };
57 
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
AH::Updatable<>
MIDIButton::address
const MIDIAddress address
Definition: Abstract/MIDIButton.hpp:52
Button.hpp
AH::Button::Falling
@ 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
MIDIOutputElement.hpp
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MIDIButton
An abstract class for momentary push buttons that send MIDI events.
Definition: Abstract/MIDIButton.hpp:17
MIDIButton::MIDIButton
MIDIButton(pin_t pin, const MIDIAddress &address, const Sender &sender)
Construct a new MIDIButton.
Definition: Abstract/MIDIButton.hpp:30
MIDIButton::getButtonState
AH::Button::State getButtonState() const
Definition: Abstract/MIDIButton.hpp:48
AH::Button::Rising
@ Rising
Input went from low to high (0,1)
Definition: Button.hpp:57
MIDIButton::update
void update() override
Update this updatable.
Definition: Abstract/MIDIButton.hpp:35
MIDIButton::invert
void invert()
Definition: Abstract/MIDIButton.hpp:45
MIDIButton::begin
void begin() override
Initialize this updatable.
Definition: Abstract/MIDIButton.hpp:34
MIDIButton::sender
Sender sender
Definition: Abstract/MIDIButton.hpp:55
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:11
MIDIButton::button
AH::Button button
Definition: Abstract/MIDIButton.hpp:51
AH::Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:19