Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Abstract/MIDIChordButton.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <AH/STL/memory> // std::unique_ptr
5#include <Def/Def.hpp>
8
10
19template <class Sender>
21 public:
40 template <uint8_t N>
42 const Sender &sender)
43 : button(pin), address(address),
44 newChord(AH::make_unique<Chord<N>>(std::move(chord))),
45 sender(sender) {}
46 // TODO: can I somehow get rid of the dynamic memory allocation here?
47
48 void begin() final override { button.begin(); }
49 void update() final override {
50 AH::Button::State state = button.update();
51 MIDIAddress sendAddress = address;
52 if (state == AH::Button::Falling) {
53 if (newChord)
54 chord = std::move(newChord);
55 sender.sendOn(sendAddress);
56 for (int8_t offset : *chord)
57 sender.sendOn(sendAddress + offset);
58 } else if (state == AH::Button::Rising) {
59 sender.sendOff(sendAddress);
60 for (int8_t offset : *chord)
61 sender.sendOff(sendAddress + offset);
62 }
63 }
64
66 void invert() { button.invert(); }
67
68 AH::Button::State getButtonState() const { return button.getState(); }
69
71 template <uint8_t N>
73 newChord = AH::make_unique<Chord<N>>(std::move(chord));
74 }
75
77 MIDIAddress getAddress() const { return this->address; }
80 void setAddressUnsafe(MIDIAddress address) { this->address = address; }
81
82 private:
85 std::unique_ptr<const IChord> chord;
86 std::unique_ptr<const IChord> newChord;
87
88 public:
89 Sender sender;
90};
91
AH::Updatable<> MIDIOutputElement
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for reading and debouncing buttons and switches.
Definition Button.hpp:15
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
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
void setAddressUnsafe(MIDIAddress address)
Set the MIDI address.
AH::Button::State getButtonState() const
std::unique_ptr< const IChord > newChord
MIDIChordButton(pin_t pin, MIDIAddress address, Chord< N > chord, const Sender &sender)
Construct a new MIDIChordButton.
MIDIAddress getAddress() const
Get the MIDI address.
void begin() final override
Initialize this updatable.
std::unique_ptr< const IChord > chord
void setChord(Chord< N > chord)
Change the chord. Can be used safely while the push button is pressed.
void update() final override
Update this updatable.
PrintStream library
Definition Array.hpp:10
Type for storing pin numbers of Extended Input/Output elements.