Control Surface
main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
src
MIDI_Outputs
Abstract
Abstract/MIDIButtonLatched.hpp
Go to the documentation of this file.
1
/* ✔ */
2
3
#pragma once
4
5
#include <
AH/Hardware/Button.hpp
>
6
#include <
Def/Def.hpp
>
7
#include <
MIDI_Outputs/Abstract/MIDIOutputElement.hpp
>
8
9
BEGIN_CS_NAMESPACE
10
19
template
<
class
Sender>
20
class
MIDIButtonLatched
:
public
MIDIOutputElement
{
21
protected
:
34
MIDIButtonLatched
(pin_t pin,
MIDIAddress
address
,
const
Sender &
sender
)
35
:
button
(pin),
address
(
address
),
sender
(
sender
) {}
36
37
public
:
38
void
begin
() final
override
{
button
.
begin
(); }
39
void
update
() final
override
{
40
AH::Button::State
state
=
button
.
update
();
41
if
(
state
==
AH::Button::Falling
)
42
toggleState
();
43
}
44
47
bool
toggleState
() {
48
setState
(!
getState
());
49
return
getState
();
50
}
51
53
bool
getState
()
const
{
return
state
; }
54
57
void
setState
(
bool
state
) {
58
this->state =
state
;
59
state
?
sender
.sendOn(
address
) :
sender
.sendOff(
address
);
60
}
61
63
void
invert
() {
button
.
invert
(); }
64
66
AH::Button::State
getButtonState
()
const
{
return
button
.
getState
(); }
67
69
MIDIAddress
getAddress
()
const
{
return
this->
address
; }
72
void
setAddressUnsafe
(
MIDIAddress
address
) { this->address =
address
; }
73
74
private
:
75
AH::Button
button
;
76
const
MIDIAddress
address
;
77
bool
state
=
false
;
78
79
public
:
80
Sender
sender
;
81
};
82
83
END_CS_NAMESPACE
Button.hpp
Def.hpp
MIDIOutputElement.hpp
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::update
State update()
Read the button and return its new state.
Definition
Button.cpp:11
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition
Button.hpp:45
AH::Button::Falling
@ Falling
Input went from high to low (1,0)
Definition
Button.hpp:48
AH::Button::invert
void invert()
Invert the input state of this button (button pressed is HIGH instead of LOW).
Definition
Button.cpp:9
AH::Button::getState
State getState() const
Get the state of the button, without updating it.
Definition
Button.cpp:32
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition
Button.cpp:7
AH::Updatable
A super class for object that have to be updated regularly.
Definition
Updatable.hpp:169
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition
MIDIAddress.hpp:145
MIDIButtonLatched
A class for momentary buttons and switches that send MIDI events.
Definition
Abstract/MIDIButtonLatched.hpp:20
MIDIButtonLatched::MIDIButtonLatched
MIDIButtonLatched(pin_t pin, MIDIAddress address, const Sender &sender)
Create a new MIDIButtonLatched object on the given pin and address.
Definition
Abstract/MIDIButtonLatched.hpp:34
MIDIButtonLatched::getState
bool getState() const
Get the current state.
Definition
Abstract/MIDIButtonLatched.hpp:53
MIDIButtonLatched::button
AH::Button button
Definition
Abstract/MIDIButtonLatched.hpp:75
MIDIButtonLatched::address
const MIDIAddress address
Definition
Abstract/MIDIButtonLatched.hpp:76
MIDIButtonLatched::setAddressUnsafe
void setAddressUnsafe(MIDIAddress address)
Set the MIDI address.
Definition
Abstract/MIDIButtonLatched.hpp:72
MIDIButtonLatched::getButtonState
AH::Button::State getButtonState() const
Get the state of the underlying button.
Definition
Abstract/MIDIButtonLatched.hpp:66
MIDIButtonLatched::sender
Sender sender
Definition
Abstract/MIDIButtonLatched.hpp:80
MIDIButtonLatched::toggleState
bool toggleState()
Flip the state (on → off or off → on).
Definition
Abstract/MIDIButtonLatched.hpp:47
MIDIButtonLatched::invert
void invert()
Definition
Abstract/MIDIButtonLatched.hpp:63
MIDIButtonLatched::getAddress
MIDIAddress getAddress() const
Get the MIDI address.
Definition
Abstract/MIDIButtonLatched.hpp:69
MIDIButtonLatched::begin
void begin() final override
Initialize this updatable.
Definition
Abstract/MIDIButtonLatched.hpp:38
MIDIButtonLatched::state
bool state
Definition
Abstract/MIDIButtonLatched.hpp:77
MIDIButtonLatched::setState
void setState(bool state)
Set the state to the given value.
Definition
Abstract/MIDIButtonLatched.hpp:57
MIDIButtonLatched::update
void update() final override
Update this updatable.
Definition
Abstract/MIDIButtonLatched.hpp:39
Generated by
1.10.0