Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Abstract/MIDIButtons.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <Def/Def.hpp>
6
8
16template <class Sender, uint8_t NumButtons>
18 protected:
29
30 public:
31 void begin() final override {
32 for (auto &button : buttons)
33 button.begin();
34 }
35 void update() final override {
36 MIDIAddress address = baseAddress;
37 for (auto &button : buttons) {
38 AH::Button::State state = button.update();
39 if (state == AH::Button::Falling) {
40 sender.sendOn(address);
41 } else if (state == AH::Button::Rising) {
42 sender.sendOff(address);
43 }
44 address += incrementAddress;
45 }
46 }
47
48 AH::Button::State getButtonState(size_t index) const {
49 return buttons[index].getState();
50 }
51
53 MIDIAddress getBaseAddress() const { return this->baseAddress; }
58 this->baseAddress = address;
59 }
68 this->incrementAddress = address;
69 }
70
72 void invert() {
73 for (auto &button : buttons)
74 button.invert();
75 }
76
77 private:
81
82 public:
83 Sender sender;
84};
85
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
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
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 MIDI events.
RelativeMIDIAddress incrementAddress
AH::Button::State getButtonState(size_t index) const
void setBaseAddressUnsafe(MIDIAddress address)
Set the MIDI base address.
MIDIAddress getBaseAddress() const
Get the MIDI base address.
Array< AH::Button, NumButtons > buttons
void begin() final override
Initialize this updatable.
MIDIAddress baseAddress
MIDIButtons(const Array< AH::Button, NumButtons > &buttons, MIDIAddress baseAddress, RelativeMIDIAddress incrementAddress, const Sender &sender)
Construct a new MIDIButtons.
void setIncrementAddressUnsafe(RelativeMIDIAddress address)
Set the MIDI increment address.
RelativeMIDIAddress getIncrementAddress() const
Get the MIDI increment address.
void update() final override
Update this updatable.
A class for saving an offset to a MIDI address.
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32