Line data Source code
1 : #pragma once
2 :
3 : #include <Banks/BankAddresses.hpp>
4 : #include <MIDI_Outputs/Bankable/Abstract/MIDIButtonMatrix.hpp>
5 : #include <MIDI_Senders/DigitalNoteSender.hpp>
6 :
7 : BEGIN_CS_NAMESPACE
8 :
9 : namespace Bankable {
10 :
11 : /**
12 : * @brief A class of MIDIOutputElement%s that read the input from a **matrix
13 : * of momentary push buttons or switches**, and send out MIDI **Note**
14 : * events.
15 : *
16 : * A Note On event is sent when a button is pressed, and a Note Off
17 : * event is sent when a button is released.
18 : * Crude software debouncing is implemented by limiting the refresh rate.
19 : * This version can be banked.
20 : *
21 : * @tparam NumRows
22 : * The number of rows of the matrix.
23 : * @tparam NumCols
24 : * The number of columns of the matrix.
25 : *
26 : * @ingroup BankableMIDIOutputElements
27 : */
28 : template <uint8_t NumRows, uint8_t NumCols>
29 : class NoteButtonMatrix
30 : : public MIDIButtonMatrix<MatrixAddress<NumRows, NumCols>,
31 : DigitalNoteSender, NumRows, NumCols> {
32 : public:
33 : /**
34 : * @brief Create a new Bankable NoteButtonMatrix object with the given
35 : * pins, note numbers and channel.
36 : *
37 : * @param config
38 : * The bank configuration to use: the bank to add this element to,
39 : * and whether to change the address, channel or cable number.
40 : * @param rowPins
41 : * A list of pin numbers connected to the rows of the button
42 : * matrix.
43 : * **⚠** These pins will be driven LOW as outputs (Lo-Z).
44 : * @param colPins
45 : * A list of pin numbers connected to the columns of the button
46 : * matrix.
47 : * These pins will be used as inputs (Hi-Z), and the
48 : * internal pull-up resistor will be enabled.
49 : * @param notes
50 : * A 2-dimensional array of the same dimensions as the button
51 : * matrix that contains the note number of each button. [0, 127]
52 : * @param channelCN
53 : * The MIDI channel [Channel_1, Channel_16] and Cable Number
54 : * [Cable_1, Cable_16].
55 : * @param velocity
56 : * The velocity of the MIDI Note events.
57 : */
58 2 : NoteButtonMatrix(OutputBankConfig<> config, const PinList<NumRows> &rowPins,
59 : const PinList<NumCols> &colPins,
60 : const AddressMatrix<NumRows, NumCols> ¬es,
61 : MIDIChannelCable channelCN = {Channel_1, Cable_1},
62 : uint8_t velocity = 0x7F)
63 : : MIDIButtonMatrix<MatrixAddress<NumRows, NumCols>, DigitalNoteSender,
64 : NumRows, NumCols> {
65 : {config, notes, channelCN},
66 : rowPins,
67 : colPins,
68 : {velocity},
69 2 : } {}
70 :
71 : /// Set the velocity of the MIDI Note events.
72 : void setVelocity(uint8_t velocity) { this->sender.setVelocity(velocity); }
73 : /// Get the velocity of the MIDI Note events.
74 : uint8_t getVelocity() const { return this->sender.getVelocity(); }
75 : };
76 :
77 : } // namespace Bankable
78 :
79 : END_CS_NAMESPACE
|