Control Surface  1.1.1
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButtonMatrix.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 #include <Def/Def.hpp>
8 
10 
11 namespace Bankable {
12 
28 template <class BankAddress, class Sender, uint8_t nb_rows, uint8_t nb_cols>
30  public AH::ButtonMatrix<nb_rows, nb_cols> {
31 
32  protected:
50  MIDIButtonMatrix(const BankAddress &bankAddress,
51  const PinList<nb_rows> &rowPins,
52  const PinList<nb_cols> &colPins, const Sender &sender)
53  : AH::ButtonMatrix<nb_rows, nb_cols>(rowPins, colPins),
54  address{bankAddress}, sender{sender} {}
55 
56  public:
58 
60 
61  private:
62  void onButtonChanged(uint8_t row, uint8_t col, bool state) final override {
63  if (state == LOW) {
64  if (!activeButtons)
65  address.lock(); // Don't allow changing of the bank setting
66  activeButtons++;
67  sender.sendOn(address.getActiveAddress(row, col));
68  } else {
69  sender.sendOff(address.getActiveAddress(row, col));
70  activeButtons--;
71  if (!activeButtons)
72  address.unlock();
73  }
74  }
75 
76  BankAddress address;
77  uint16_t activeButtons = 0;
78 
79  public:
80  Sender sender;
81 };
82 
83 } // namespace Bankable
84 
AH::Updatable<>
BankableMIDIOutput.hpp
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition: BankAddresses.hpp:7
MIDIOutputElement.hpp
Bankable::MIDIButtonMatrix::activeButtons
uint16_t activeButtons
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:77
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
AH::ButtonMatrix::colPins
const PinList< nb_cols > colPins
Definition: ButtonMatrix.hpp:86
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Array.hpp
AH::ButtonMatrix::begin
void begin()
Initialize (enable internal pull-up resistors on column pins).
Definition: ButtonMatrix.ipp:41
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:47
Bankable::MIDIButtonMatrix::onButtonChanged
void onButtonChanged(uint8_t row, uint8_t col, bool state) final override
The callback function that is called whenever a button changes state.
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:62
ButtonMatrix.hpp
AH
Definition: Array.hpp:14
AH::ButtonMatrix::rowPins
const PinList< nb_rows > rowPins
Definition: ButtonMatrix.hpp:85
Bankable::MIDIButtonMatrix::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:57
Bankable::MIDIButtonMatrix
MIDIButtonMatrix.
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:29
AH::ButtonMatrix::ButtonMatrix
ButtonMatrix(const PinList< nb_rows > &rowPins, const PinList< nb_cols > &colPins)
Construct a new ButtonMatrix object.
Definition: ButtonMatrix.ipp:10
Bankable::MIDIButtonMatrix::sender
Sender sender
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:80
Bankable::MIDIButtonMatrix::address
BankAddress address
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:76
Bankable::MIDIButtonMatrix::MIDIButtonMatrix
MIDIButtonMatrix(const BankAddress &bankAddress, const PinList< nb_rows > &rowPins, const PinList< nb_cols > &colPins, const Sender &sender)
Create a new Bankable MIDIButtonMatrix.
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:50
AH::ButtonMatrix
A class that reads the states of a button matrix.
Definition: ButtonMatrix.hpp:23
Bankable::MIDIButtonMatrix::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIButtonMatrix.hpp:59
AH::ButtonMatrix::update
void update()
Scan the matrix, read all button states, and call the onButtonChanged callback.
Definition: ButtonMatrix.ipp:17