Control Surface  1.1.1
MIDI Control Surface library for Arduino
Abstract/MIDIChordButton.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <AH/Hardware/Button.hpp>
5 #include <Def/Def.hpp>
8 
10 
19 template <class Sender>
21  public:
40  template <uint8_t N>
42  const Chord<N> &chord, const Sender &sender)
43  : button{pin}, address(address),
45  // TODO: can I somehow get rid of the dynamic memory allocation here?
46 
47  void begin() final override { button.begin(); }
48  void update() final override {
50  MIDICNChannelAddress sendAddress = address;
51  if (state == AH::Button::Falling) {
52  if (newChord)
53  chord = std::move(newChord);
54  sender.sendOn(sendAddress);
55  for (int8_t offset : *chord)
56  sender.sendOn(sendAddress + offset);
57  } else if (state == AH::Button::Rising) {
58  sender.sendOff(sendAddress);
59  for (int8_t offset : *chord)
60  sender.sendOff(sendAddress + offset);
61  }
62  }
63 
64 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
65  void invert() { button.invert(); }
66 #endif
67 
69 
70  template <uint8_t N>
71  void setChord(const Chord<N> &chord) {
72  newChord = new Chord<N>(chord);
73  }
74 
75  private:
80 
81  public:
82  Sender sender;
83 };
84 
AH::Updatable<>
MIDIChordButton::begin
void begin() final override
Initialize this updatable.
Definition: Abstract/MIDIChordButton.hpp:47
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
Chord
Definition: Chords.hpp:16
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
MIDIChordButton::getButtonState
AH::Button::State getButtonState() const
Definition: Abstract/MIDIChordButton.hpp:68
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
MIDIChordButton::address
const MIDICNChannelAddress address
Definition: Abstract/MIDIChordButton.hpp:77
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
Chords.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
MIDIChordButton::MIDIChordButton
MIDIChordButton(pin_t pin, const MIDICNChannelAddress &address, const Chord< N > &chord, const Sender &sender)
Construct a new MIDIChordButton.
Definition: Abstract/MIDIChordButton.hpp:41
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MIDIChordButton::setChord
void setChord(const Chord< N > &chord)
Definition: Abstract/MIDIChordButton.hpp:71
MIDIChordButton::invert
void invert()
Definition: Abstract/MIDIChordButton.hpp:65
UniquePtr.hpp
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
MIDIChordButton::newChord
AH::UniquePtr< const IChord > newChord
Definition: Abstract/MIDIChordButton.hpp:79
AH::Button::Rising
Input went from low to high (0,1)
Definition: Button.hpp:57
MIDIChordButton::button
AH::Button button
Definition: Abstract/MIDIChordButton.hpp:76
MIDIChordButton::sender
Sender sender
Definition: Abstract/MIDIChordButton.hpp:82
MIDIChordButton::chord
AH::UniquePtr< const IChord > chord
Definition: Abstract/MIDIChordButton.hpp:78
AH::UniquePtr< const IChord >
MIDIChordButton
An abstract class for momentary push buttons that send multiple MIDI events.
Definition: Abstract/MIDIChordButton.hpp:20
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:11
AH::MakeUnique
UniquePtr< T > MakeUnique(Args &&... args)
Definition: UniquePtr.hpp:66
AH::Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:19
MIDIChordButton::update
void update() final override
Update this updatable.
Definition: Abstract/MIDIChordButton.hpp:48