Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Bankable/Abstract/MIDIButtons.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <Def/Def.hpp>
8
10
11namespace Bankable {
12
22template <class BankAddress, class Sender, uint8_t NumButtons>
24 protected:
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);
51 } else if (state == AH::Button::Rising) {
52 MIDIAddress sendAddress = address.getActiveAddress() + offset;
53 sender.sendOff(sendAddress);
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:
77
78 public:
79 Sender sender;
80};
81
82} // namespace Bankable
83
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
State
An enumeration of the different states a button can be in.
Definition Button.hpp:45
@ Rising
Input went from low to high (0,1)
Definition Button.hpp:49
@ Falling
Input went from high to low (1,0)
Definition Button.hpp:48
A super class for object that have to be updated regularly.
An abstract class for momentary push buttons that send MIDI events.
AH::Button::State getButtonState(size_t index) const
MIDIButtons(BankAddress bankAddress, const Array< AH::Button, NumButtons > &buttons, RelativeMIDIAddress incrementAddress, const Sender &sender)
Construct a new MIDIButtons.
Array< AH::Button, NumButtons > buttons
void begin() final override
Initialize this updatable.
void update() final override
Update this updatable.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
A class for saving an offset to a MIDI address.
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32
T * begin()
Get a pointer to the first element.
Definition Array.hpp:74