Control Surface  1.1.0
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIChordButton.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <AH/Hardware/Button.hpp>
6 #include <Def/Def.hpp>
9 
11 
12 namespace Bankable {
13 
14 /**
15  * @brief An abstract class for momentary push buttons that send multiple MIDI
16  * events.
17  *
18  * The button is debounced.
19  *
20  * @see AH::Button
21  */
22 template <class Sender>
24  public:
25  /**
26  * @brief Construct a new bankable MIDIChordButton.
27  *
28  * @param config
29  * The bank configuration to use: the bank to add this element to,
30  * and whether to change the address, channel or cable number.
31  * @param pin
32  * The digital input pin with the button connected.
33  * The internal pull-up resistor will be enabled.
34  * @param address
35  * The address of the base note, containing the note number
36  * [0, 127], the MIDI channel [CHANNEL_1, CHANNEL_16] and Cable
37  * Number [0, 15].
38  * @param chord
39  * The chord to play on top of the base notes.
40  * @param sender
41  * The MIDI sender to use.
42  */
43  template <uint8_t N>
46  const Sender &sender)
47  : address{config, address}, button{pin},
49 
50  void begin() override { button.begin(); }
51  void update() override {
53  if (state == AH::Button::Falling) {
54  if (newChord)
55  chord = std::move(newChord);
56  address.lock();
57  auto sendAddress = address.getActiveAddress();
58  sender.sendOn(sendAddress);
59  for (int8_t offset : *chord)
60  sender.sendOn(sendAddress + offset);
61  } else if (state == AH::Button::Rising) {
62  auto sendAddress = address.getActiveAddress();
63  sender.sendOff(sendAddress);
64  for (int8_t offset : *chord)
65  sender.sendOff(sendAddress + offset);
66  address.unlock();
67  }
68  }
69 
70 #ifdef INDIVIDUAL_BUTTON_INVERT
71  void invert() { button.invert(); }
72 #endif
73 
75 
76  template <uint8_t N>
77  void setChord(const Chord<N> &chord) {
78  newChord = new Chord<N>(chord);
79  }
80 
81  private:
86 
87  public:
88  Sender sender;
89 };
90 
91 } // namespace Bankable
92 
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
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
Bankable::SingleAddress::getActiveAddress
MIDICNChannelAddress getActiveAddress() const
Definition: BankAddresses.hpp:16
Bankable::MIDIChordButton::newChord
AH::UniquePtr< const IChord > newChord
Definition: Bankable/Abstract/MIDIChordButton.hpp:85
Chord
Definition: Chords.hpp:16
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
MIDIOutputElement.hpp
Bankable::MIDIChordButton::MIDIChordButton
MIDIChordButton(const OutputBankConfig &config, pin_t pin, const MIDICNChannelAddress &address, const Chord< N > &chord, const Sender &sender)
Construct a new bankable MIDIChordButton.
Definition: Bankable/Abstract/MIDIChordButton.hpp:44
BankableMIDIOutput_Base::lock
void lock()
Lock the bank setting.
Definition: BankableMIDIOutput.hpp:44
Def.hpp
Bankable::MIDIChordButton::setChord
void setChord(const Chord< N > &chord)
Definition: Bankable/Abstract/MIDIChordButton.hpp:77
Chords.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
BankAddresses.hpp
Bankable::MIDIChordButton::getButtonState
AH::Button::State getButtonState() const
Definition: Bankable/Abstract/MIDIChordButton.hpp:74
Bankable::MIDIChordButton::chord
AH::UniquePtr< const IChord > chord
Definition: Bankable/Abstract/MIDIChordButton.hpp:84
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
AH::Button::getState
State getState() const
Get the state of the button, without updating it.
Definition: Button.cpp:36
UniquePtr.hpp
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
Bankable::MIDIChordButton
An abstract class for momentary push buttons that send multiple MIDI events.
Definition: Bankable/Abstract/MIDIChordButton.hpp:23
Bankable::MIDIChordButton::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIChordButton.hpp:51
AH::Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:19
Bankable::MIDIChordButton::address
SingleAddress address
Definition: Bankable/Abstract/MIDIChordButton.hpp:82
BankableMIDIOutput_Base::unlock
void unlock()
Unlock the bank setting.
Definition: BankableMIDIOutput.hpp:55
Bankable::MIDIChordButton::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIChordButton.hpp:50
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
Bankable::SingleAddress
Definition: BankAddresses.hpp:9
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
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
Bankable::MIDIChordButton::button
AH::Button button
Definition: Bankable/Abstract/MIDIChordButton.hpp:83
Bankable::MIDIChordButton::sender
Sender sender
Definition: Bankable/Abstract/MIDIChordButton.hpp:88
AH::UniquePtr< const IChord >
OutputBankConfig
A struct for selecting the bank of BankableMIDIOutputs and the bank type.
Definition: BankConfig.hpp:50
AH::MakeUnique
UniquePtr< T > MakeUnique(Args &&... args)
Definition: UniquePtr.hpp:66
AH::Button::Falling
< Input went from high to high (1,1)
Definition: Button.hpp:56