Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Bankable/Abstract/MIDIChordButton.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <AH/STL/memory> // std::unique_ptr
6#include <Def/Def.hpp>
9
11
12namespace Bankable {
13
22template <class Sender>
24 public:
43 template <uint8_t N>
45 Chord<N> chord, const Sender &sender)
46 : address {config, address}, button(pin),
47 newChord(AH::make_unique<Chord<N>>(std::move(chord))),
48 sender(sender) {}
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);
67 }
68 }
69
71 void invert() { button.invert(); }
72
74
75 template <uint8_t N>
79
80 private:
83 std::unique_ptr<const IChord> chord;
84 std::unique_ptr<const IChord> newChord;
85
86 public:
87 Sender sender;
88};
89
90} // namespace Bankable
91
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for reading and debouncing buttons and switches.
Definition Button.hpp:15
State update()
Read the button and return its new state.
Definition Button.cpp:11
State
An enumeration of the different states a button can be in.
Definition Button.hpp:47
@ Rising
Input went from low to high (0,1)
Definition Button.hpp:51
@ Falling
Input went from high to low (1,0)
Definition Button.hpp:50
void invert()
Invert the input state of this button (button pressed is HIGH instead of LOW).
Definition Button.cpp:9
State getState() const
Get the state of the button, without updating it.
Definition Button.cpp:32
void begin()
Initialize (enable the internal pull-up resistor).
Definition Button.cpp:7
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
A super class for object that have to be updated regularly.
An abstract class for momentary push buttons that send multiple MIDI events.
void update() override
Update this updatable.
std::unique_ptr< const IChord > newChord
void begin() override
Initialize this updatable.
MIDIChordButton(OutputBankConfig<> config, pin_t pin, MIDIAddress address, Chord< N > chord, const Sender &sender)
Construct a new bankable MIDIChordButton.
std::unique_ptr< const IChord > chord
MIDIAddress getActiveAddress() const
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
void unlock()
Unlock the bank setting.
void lock()
Lock the bank setting.
PrintStream library
Definition Array.hpp:10
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Type for storing pin numbers of Extended Input/Output elements.