Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Bankable/Abstract/MIDIButtonMatrix.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <Def/Def.hpp>
8
10
11namespace Bankable {
12
28template <class BankAddress, class Sender, uint8_t NumRows, uint8_t NumCols>
30 : public MIDIOutputElement,
31 public AH::ButtonMatrix<
32 MIDIButtonMatrix<BankAddress, Sender, NumRows, NumCols>, NumRows,
33 NumCols> {
35 friend class AH::ButtonMatrix<MIDIButtonMatrix, NumRows, NumCols>;
36
37 protected:
55 MIDIButtonMatrix(BankAddress bankAddress, const PinList<NumRows> &rowPins,
56 const PinList<NumCols> &colPins, const Sender &sender)
57 : ButtonMatrix(rowPins, colPins), address(bankAddress), sender(sender) {
58 }
59
60 public:
61 void begin() override { ButtonMatrix::begin(); }
62
63 void update() override { ButtonMatrix::update(); }
64
65 private:
66 void onButtonChanged(uint8_t row, uint8_t col, bool state) {
67 if (state == LOW) {
68 if (!activeButtons)
69 address.lock(); // Don't allow changing of the bank setting
71 sender.sendOn(address.getActiveAddress(row, col));
72 } else {
73 sender.sendOff(address.getActiveAddress(row, col));
75 if (!activeButtons)
76 address.unlock();
77 }
78 }
79
80 protected:
81 BankAddress address;
82 uint16_t activeButtons = 0;
83
84 public:
85 Sender sender;
86};
87
88} // namespace Bankable
89
constexpr PinStatus_t LOW
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class that reads the states of a button matrix.
void begin()
Initialize (enable internal pull-up resistors on column pins).
void update()
Scan the matrix, read all button states, and call the onButtonChanged callback.
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
A super class for object that have to be updated regularly.
void onButtonChanged(uint8_t row, uint8_t col, bool state)
MIDIButtonMatrix(BankAddress bankAddress, const PinList< NumRows > &rowPins, const PinList< NumCols > &colPins, const Sender &sender)
Create a new Bankable MIDIButtonMatrix.
void update() override
Update this updatable.
void begin() override
Initialize this updatable.
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.