Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
MIDI_Outputs
Abstract
Abstract/MIDIChordButton.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
AH/Hardware/Button.hpp
>
4
#include <AH/STL/memory>
// std::unique_ptr
5
#include <
Def/Def.hpp
>
6
#include <
MIDI_Constants/Chords/Chords.hpp
>
7
#include <
MIDI_Outputs/Abstract/MIDIOutputElement.hpp
>
8
9
BEGIN_CS_NAMESPACE
10
19
template
<
class
Sender>
20
class
MIDIChordButton
:
public
MIDIOutputElement
{
21
public
:
40
template
<u
int
8_t N>
41
MIDIChordButton
(
pin_t
pin,
MIDIAddress
address
,
Chord<N>
chord
,
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
<u
int
8_t N>
72
void
setChord
(
Chord<N>
chord
) {
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
:
83
AH::Button
button
;
84
MIDIAddress
address
;
85
std::unique_ptr<const IChord>
chord
;
86
std::unique_ptr<const IChord>
newChord
;
87
88
public
:
89
Sender
sender
;
90
};
91
92
END_CS_NAMESPACE
Button.hpp
Chords.hpp
Def.hpp
MIDIOutputElement.hpp
MIDIOutputElement
AH::Updatable<> MIDIOutputElement
Definition
MIDIOutputElement.hpp:9
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:11
AH::Button
A class for reading and debouncing buttons and switches.
Definition
Button.hpp:15
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition
Button.hpp:47
AH::Button::Rising
@ Rising
Input went from low to high (0,1).
Definition
Button.hpp:51
AH::Button::Falling
@ Falling
Input went from high to low (1,0).
Definition
Button.hpp:50
Chord
Definition
Chords.hpp:16
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition
MIDIAddress.hpp:145
MIDIChordButton::address
MIDIAddress address
Definition
Abstract/MIDIChordButton.hpp:84
MIDIChordButton::button
AH::Button button
Definition
Abstract/MIDIChordButton.hpp:83
MIDIChordButton::setAddressUnsafe
void setAddressUnsafe(MIDIAddress address)
Set the MIDI address.
Definition
Abstract/MIDIChordButton.hpp:80
MIDIChordButton::getButtonState
AH::Button::State getButtonState() const
Definition
Abstract/MIDIChordButton.hpp:68
MIDIChordButton::sender
Sender sender
Definition
Abstract/MIDIChordButton.hpp:89
MIDIChordButton::newChord
std::unique_ptr< const IChord > newChord
Definition
Abstract/MIDIChordButton.hpp:86
MIDIChordButton::invert
void invert()
Definition
Abstract/MIDIChordButton.hpp:66
MIDIChordButton::MIDIChordButton
MIDIChordButton(pin_t pin, MIDIAddress address, Chord< N > chord, const Sender &sender)
Construct a new MIDIChordButton.
Definition
Abstract/MIDIChordButton.hpp:41
MIDIChordButton::getAddress
MIDIAddress getAddress() const
Get the MIDI address.
Definition
Abstract/MIDIChordButton.hpp:77
MIDIChordButton::begin
void begin() final override
Initialize this updatable.
Definition
Abstract/MIDIChordButton.hpp:48
MIDIChordButton::chord
std::unique_ptr< const IChord > chord
Definition
Abstract/MIDIChordButton.hpp:85
MIDIChordButton::setChord
void setChord(Chord< N > chord)
Change the chord. Can be used safely while the push button is pressed.
Definition
Abstract/MIDIChordButton.hpp:72
MIDIChordButton::update
void update() final override
Update this updatable.
Definition
Abstract/MIDIChordButton.hpp:49
AH
PrintStream library
Definition
Array.hpp:10
AH::ExtIO::pin_t
Type for storing pin numbers of Extended Input/Output elements.
Definition
Hardware-Types.hpp:25
Generated by
1.17.0