Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
MIDI_Outputs
Bankable
Abstract
Bankable/Abstract/MIDIButtons.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
AH/Containers/Array.hpp
>
4
#include <
AH/Hardware/Button.hpp
>
5
#include <
Banks/BankableAddresses.hpp
>
6
#include <
Def/Def.hpp
>
7
#include <
MIDI_Outputs/Abstract/MIDIOutputElement.hpp
>
8
9
BEGIN_CS_NAMESPACE
10
11
namespace
Bankable
{
12
22
template
<
class
BankAddress,
class
Sender, u
int
8_t NumButtons>
23
class
MIDIButtons
:
public
MIDIOutputElement
{
24
protected
:
30
MIDIButtons
(BankAddress bankAddress,
31
const
Array<AH::Button, NumButtons>
&
buttons
,
32
RelativeMIDIAddress
incrementAddress
,
const
Sender &
sender
)
33
:
address
(bankAddress),
buttons
(
buttons
),
34
incrementAddress
(
incrementAddress
),
sender
(
sender
) {}
35
36
public
:
37
void
begin
() final
override
{
38
for
(
auto
&button :
buttons
)
39
button.begin();
40
}
41
void
update
() final
override
{
42
RelativeMIDIAddress
offset = {0, 0, 0};
43
for
(
auto
&button :
buttons
) {
44
AH::Button::State
state = button.update();
45
if
(state ==
AH::Button::Falling
) {
46
if
(!
activeButtons
)
47
address
.lock();
// Don't allow changing of the bank setting
48
MIDIAddress
sendAddress =
address
.getActiveAddress() + offset;
49
sender
.sendOn(sendAddress);
50
activeButtons
++;
51
}
else
if
(state ==
AH::Button::Rising
) {
52
MIDIAddress
sendAddress =
address
.getActiveAddress() + offset;
53
sender
.sendOff(sendAddress);
54
activeButtons
--;
55
if
(!
activeButtons
)
56
address
.unlock();
57
}
58
offset +=
incrementAddress
;
59
}
60
}
61
63
void
invert
() {
64
for
(
auto
&button :
buttons
)
65
button.invert();
66
}
67
68
AH::Button::State
getButtonState
(
size_t
index)
const
{
69
return
buttons
[index].getState();
70
}
71
72
protected
:
73
BankAddress
address
;
74
Array<AH::Button, NumButtons>
buttons
;
75
RelativeMIDIAddress
incrementAddress
;
76
uint8_t
activeButtons
= 0;
77
78
public
:
79
Sender
sender
;
80
};
81
82
}
// namespace Bankable
83
84
END_CS_NAMESPACE
Array.hpp
BankableAddresses.hpp
Button.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::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::MIDIButtons::incrementAddress
RelativeMIDIAddress incrementAddress
Definition
Bankable/Abstract/MIDIButtons.hpp:75
Bankable::MIDIButtons::getButtonState
AH::Button::State getButtonState(size_t index) const
Definition
Bankable/Abstract/MIDIButtons.hpp:68
Bankable::MIDIButtons::address
BankAddress address
Definition
Bankable/Abstract/MIDIButtons.hpp:73
Bankable::MIDIButtons::sender
Sender sender
Definition
Bankable/Abstract/MIDIButtons.hpp:79
Bankable::MIDIButtons::activeButtons
uint8_t activeButtons
Definition
Bankable/Abstract/MIDIButtons.hpp:76
Bankable::MIDIButtons::MIDIButtons
MIDIButtons(BankAddress bankAddress, const Array< AH::Button, NumButtons > &buttons, RelativeMIDIAddress incrementAddress, const Sender &sender)
Construct a new MIDIButtons.
Definition
Bankable/Abstract/MIDIButtons.hpp:30
Bankable::MIDIButtons::invert
void invert()
Definition
Bankable/Abstract/MIDIButtons.hpp:63
Bankable::MIDIButtons::buttons
Array< AH::Button, NumButtons > buttons
Definition
Bankable/Abstract/MIDIButtons.hpp:74
Bankable::MIDIButtons::begin
void begin() final override
Initialize this updatable.
Definition
Bankable/Abstract/MIDIButtons.hpp:37
Bankable::MIDIButtons::update
void update() final override
Update this updatable.
Definition
Bankable/Abstract/MIDIButtons.hpp:41
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition
MIDIAddress.hpp:145
RelativeMIDIAddress
A class for saving an offset to a MIDI address.
Definition
MIDIAddress.hpp:113
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition
BankAddresses.hpp:7
AH::Array
An array wrapper for easy copying, comparing, and iterating.
Definition
Array.hpp:32
Generated by
1.17.0