Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Abstract/MIDIButtonMatrix.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <Def/Def.hpp>
6
8
14template <class Sender, uint8_t NumRows, uint8_t NumCols>
16 : public MIDIOutputElement,
17 public AH::ButtonMatrix<MIDIButtonMatrix<Sender, NumRows, NumCols>,
18 NumRows, NumCols> {
20 friend class AH::ButtonMatrix<MIDIButtonMatrix, NumRows, NumCols>;
21
22 protected:
42 MIDIButtonMatrix(const PinList<NumRows> &rowPins,
43 const PinList<NumCols> &colPins,
45 MIDIChannelCable channelCN, const Sender &sender)
47 baseChannelCN(channelCN), sender(sender) {}
48
49 public:
50 void begin() final override { ButtonMatrix::begin(); }
51
52 void update() final override { ButtonMatrix::update(); }
53
55 MIDIAddress getAddress(uint8_t row, uint8_t col) const {
56 return {this->addresses[row][col], baseChannelCN};
57 }
61 void setAddressUnsafe(uint8_t row, uint8_t col, uint8_t address) {
62 this->addresses[row][col] = address;
63 }
70 this->baseChannelCN = bccn;
71 }
72
73 private:
74 void onButtonChanged(uint8_t row, uint8_t col, bool state) {
75 int8_t address = addresses[row][col];
76 if (state == LOW)
77 sender.sendOn({address, baseChannelCN});
78 else
79 sender.sendOff({address, baseChannelCN});
80 }
81
84
85 public:
86 Sender sender;
87};
88
constexpr PinStatus_t LOW
Array2D< uint8_t, NumRows, NumCols > AddressMatrix
Definition Def.hpp:30
#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.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
void setAddressUnsafe(uint8_t row, uint8_t col, uint8_t address)
Set the MIDI address of button at the given row and column.
void onButtonChanged(uint8_t row, uint8_t col, bool state)
AddressMatrix< NumRows, NumCols > addresses
MIDIChannelCable getChannelCable() const
Get the MIDI channel and cable number.
void begin() final override
Initialize this updatable.
MIDIAddress getAddress(uint8_t row, uint8_t col) const
Get the MIDI address of the button at the given row and column.
void setChannelCableUnsafe(MIDIChannelCable bccn)
Set the MIDI channel and cable number of all buttons.
MIDIButtonMatrix(const PinList< NumRows > &rowPins, const PinList< NumCols > &colPins, const AddressMatrix< NumRows, NumCols > &addresses, MIDIChannelCable channelCN, const Sender &sender)
Construct a new MIDIButtonMatrix.
void update() final override
Update this updatable.
A class for saving a MIDI channel and cable number.