Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
MIDI_Outputs
Bankable
Abstract
Bankable/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 <
Banks/BankAddresses.hpp
>
6
#include <
Def/Def.hpp
>
7
#include <
MIDI_Constants/Chords/Chords.hpp
>
8
#include <
MIDI_Outputs/Abstract/MIDIOutputElement.hpp
>
9
10
BEGIN_CS_NAMESPACE
11
12
namespace
Bankable
{
13
22
template
<
class
Sender>
23
class
MIDIChordButton
:
public
MIDIOutputElement
{
24
public
:
43
template
<u
int
8_t N>
44
MIDIChordButton
(
OutputBankConfig<>
config,
pin_t
pin,
MIDIAddress
address
,
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
{
52
AH::Button::State
state =
button
.update();
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
71
void
invert
() {
button
.invert(); }
72
73
AH::Button::State
getButtonState
()
const
{
return
button
.getState(); }
74
75
template
<u
int
8_t N>
76
void
setChord
(
Chord<N>
chord
) {
77
newChord
= AH::make_unique<Chord<N>>(std::move(
chord
));
78
}
79
80
private
:
81
SingleAddress
address
;
82
AH::Button
button
;
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
92
END_CS_NAMESPACE
BankAddresses.hpp
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
Bankable::MIDIChordButton::button
AH::Button button
Definition
Bankable/Abstract/MIDIChordButton.hpp:82
Bankable::MIDIChordButton::getButtonState
AH::Button::State getButtonState() const
Definition
Bankable/Abstract/MIDIChordButton.hpp:73
Bankable::MIDIChordButton::sender
Sender sender
Definition
Bankable/Abstract/MIDIChordButton.hpp:87
Bankable::MIDIChordButton::update
void update() override
Update this updatable.
Definition
Bankable/Abstract/MIDIChordButton.hpp:51
Bankable::MIDIChordButton::newChord
std::unique_ptr< const IChord > newChord
Definition
Bankable/Abstract/MIDIChordButton.hpp:84
Bankable::MIDIChordButton::begin
void begin() override
Initialize this updatable.
Definition
Bankable/Abstract/MIDIChordButton.hpp:50
Bankable::MIDIChordButton::invert
void invert()
Definition
Bankable/Abstract/MIDIChordButton.hpp:71
Bankable::MIDIChordButton::MIDIChordButton
MIDIChordButton(OutputBankConfig<> config, pin_t pin, MIDIAddress address, Chord< N > chord, const Sender &sender)
Construct a new bankable MIDIChordButton.
Definition
Bankable/Abstract/MIDIChordButton.hpp:44
Bankable::MIDIChordButton::chord
std::unique_ptr< const IChord > chord
Definition
Bankable/Abstract/MIDIChordButton.hpp:83
Bankable::MIDIChordButton::address
SingleAddress address
Definition
Bankable/Abstract/MIDIChordButton.hpp:81
Bankable::MIDIChordButton::setChord
void setChord(Chord< N > chord)
Definition
Bankable/Abstract/MIDIChordButton.hpp:76
Bankable::SingleAddress
Definition
BankAddresses.hpp:9
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
AH
PrintStream library
Definition
Array.hpp:10
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition
BankAddresses.hpp:7
AH::ExtIO::pin_t
Type for storing pin numbers of Extended Input/Output elements.
Definition
Hardware-Types.hpp:25
OutputBankConfig
Definition
BankConfig.hpp:79
Generated by
1.17.0