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 {
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
69
71 template <uint8_t N>
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
#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.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
An abstract class for momentary push buttons that send multiple MIDI events.
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.