57 lines
1.8 KiB
C++
57 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <AH/Hardware/ButtonMatrix.hpp>
|
|
#include <Def/Def.hpp>
|
|
#include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>
|
|
|
|
BEGIN_CS_NAMESPACE
|
|
|
|
template <class Sender, uint8_t NumRows, uint8_t NumCols>
|
|
class MIDIButtonMatrix
|
|
: public MIDIOutputElement,
|
|
public AH::ButtonMatrix<MIDIButtonMatrix<Sender, NumRows, NumCols>,
|
|
NumRows, NumCols> {
|
|
using ButtonMatrix = AH::ButtonMatrix<MIDIButtonMatrix, NumRows, NumCols>;
|
|
friend class AH::ButtonMatrix<MIDIButtonMatrix, NumRows, NumCols>;
|
|
|
|
protected:
|
|
MIDIButtonMatrix(const PinList<NumRows> &rowPins,
|
|
const PinList<NumCols> &colPins,
|
|
const AddressMatrix<NumRows, NumCols> &addresses,
|
|
MIDIChannelCable channelCN, const Sender &sender)
|
|
: ButtonMatrix(rowPins, colPins), addresses(addresses),
|
|
baseChannelCN(channelCN), sender(sender) {}
|
|
|
|
public:
|
|
void begin() final override { ButtonMatrix::begin(); }
|
|
void update() final override { ButtonMatrix::update(); }
|
|
|
|
MIDIAddress getAddress(uint8_t row, uint8_t col) const {
|
|
return {this->addresses[row][col], baseChannelCN};
|
|
}
|
|
void setAddressUnsafe(uint8_t row, uint8_t col, uint8_t address) {
|
|
this->addresses[row][col] = address;
|
|
}
|
|
MIDIChannelCable getChannelCable() const { return this->baseChannelCN; }
|
|
void setChannelCableUnsafe(MIDIChannelCable bccn) {
|
|
this->baseChannelCN = bccn;
|
|
}
|
|
|
|
private:
|
|
void onButtonChanged(uint8_t row, uint8_t col, bool state) {
|
|
int8_t address = addresses[row][col];
|
|
if (state == LOW)
|
|
sender.sendOn({address, baseChannelCN});
|
|
else
|
|
sender.sendOff({address, baseChannelCN});
|
|
}
|
|
|
|
AddressMatrix<NumRows, NumCols> addresses;
|
|
MIDIChannelCable baseChannelCN;
|
|
|
|
public:
|
|
Sender sender;
|
|
};
|
|
|
|
END_CS_NAMESPACE
|