Control Surface  1.1.1
MIDI Control Surface library for Arduino
Abstract/MIDIButtons.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, uint8_t NUMBER_OF_BUTTONS>
18  protected:
27  const Sender &sender)
30 
31  public:
32  void begin() final override {
33  for (auto &button : buttons)
34  button.begin();
35  }
36  void update() final override {
38  for (auto &button : buttons) {
39  AH::Button::State state = button.update();
40  if (state == AH::Button::Falling) {
41  sender.sendOn(address);
42  } else if (state == AH::Button::Rising) {
43  sender.sendOff(address);
44  }
45  address += incrementAddress;
46  }
47  }
48 
49  AH::Button::State getButtonState(size_t index) const {
50  return buttons[index].getState();
51  }
52 
53 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
54  void invert() {
55  for (auto &button : buttons)
56  button.invert();
57  }
58 #endif
59 
60  private:
64 
65  public:
66  Sender sender;
67 };
68 
MIDIButtons::incrementAddress
const RelativeMIDICNChannelAddress incrementAddress
Definition: Abstract/MIDIButtons.hpp:63
AH::Updatable<>
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
MIDIOutputElement.hpp
MIDIButtons::begin
void begin() final override
Initialize this updatable.
Definition: Abstract/MIDIButtons.hpp:32
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
RelativeMIDICNChannelAddress
A class for saving an offset to a MIDI address.
Definition: MIDICNChannelAddress.hpp:58
MIDIButtons::getButtonState
AH::Button::State getButtonState(size_t index) const
Definition: Abstract/MIDIButtons.hpp:49
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MIDIButtons
An abstract class for momentary push buttons that send MIDI events.
Definition: Abstract/MIDIButtons.hpp:17
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
AH::Array
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:36
MIDIButtons::MIDIButtons
MIDIButtons(const Array< AH::Button, NUMBER_OF_BUTTONS > &buttons, const MIDICNChannelAddress &baseAddress, const RelativeMIDICNChannelAddress &incrementAddress, const Sender &sender)
Construct a new MIDIButtons.
Definition: Abstract/MIDIButtons.hpp:24
MIDIButtons::sender
Sender sender
Definition: Abstract/MIDIButtons.hpp:66
AH::Button::Rising
Input went from low to high (0,1)
Definition: Button.hpp:57
MIDIButtons::invert
void invert()
Definition: Abstract/MIDIButtons.hpp:54
MIDIButtons::update
void update() final override
Update this updatable.
Definition: Abstract/MIDIButtons.hpp:36
MIDIButtons::buttons
Array< AH::Button, NUMBER_OF_BUTTONS > buttons
Definition: Abstract/MIDIButtons.hpp:61
MIDIButtons::baseAddress
const MIDICNChannelAddress baseAddress
Definition: Abstract/MIDIButtons.hpp:62