Control Surface  1.1.1
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 
22 template <class Sender>
24  public:
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 AH_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 
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
AH::Updatable<>
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
BankableMIDIOutput_Base::lock
void lock()
Lock the bank setting.
Definition: BankableMIDIOutput.hpp:44
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
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
BankableMIDIOutput_Base::unlock
void unlock()
Unlock the bank setting.
Definition: BankableMIDIOutput.hpp:55
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
BankAddresses.hpp
Bankable::MIDIChordButton::newChord
AH::UniquePtr< const IChord > newChord
Definition: Bankable/Abstract/MIDIChordButton.hpp:85
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Bankable::MIDIChordButton::chord
AH::UniquePtr< const IChord > chord
Definition: Bankable/Abstract/MIDIChordButton.hpp:84
Bankable::MIDIChordButton::button
AH::Button button
Definition: Bankable/Abstract/MIDIChordButton.hpp:83
UniquePtr.hpp
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
Bankable::MIDIChordButton::sender
Sender sender
Definition: Bankable/Abstract/MIDIChordButton.hpp:88
Bankable::MIDIChordButton
An abstract class for momentary push buttons that send multiple MIDI events.
Definition: Bankable/Abstract/MIDIChordButton.hpp:23
Bankable::SingleAddress::getActiveAddress
MIDICNChannelAddress getActiveAddress() const
Definition: BankAddresses.hpp:16
Bankable::MIDIChordButton::getButtonState
AH::Button::State getButtonState() const
Definition: Bankable/Abstract/MIDIChordButton.hpp:74
AH::Button::Rising
Input went from low to high (0,1)
Definition: Button.hpp:57
Bankable::MIDIChordButton::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIChordButton.hpp:50
Bankable::MIDIChordButton::setChord
void setChord(const Chord< N > &chord)
Definition: Bankable/Abstract/MIDIChordButton.hpp:77
Bankable::SingleAddress
Definition: BankAddresses.hpp:9
Bankable::MIDIChordButton::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIChordButton.hpp:51
AH::UniquePtr< const IChord >
OutputBankConfig
A struct for selecting the bank of BankableMIDIOutputs and the bank type.
Definition: BankConfig.hpp:50
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
Bankable::MIDIChordButton::invert
void invert()
Definition: Bankable/Abstract/MIDIChordButton.hpp:71
Bankable::MIDIChordButton::address
SingleAddress address
Definition: Bankable/Abstract/MIDIChordButton.hpp:82