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 : namespace ManyAddresses { 11 : 12 : /** 13 : * @brief A class of MIDIOutputElement%s that read the input from a **matrix 14 : * of momentary push buttons or switches**, and send out MIDI **Note** 15 : * events. 16 : * 17 : * A Note On event is sent when a button is pressed, and a Note Off 18 : * event is sent when a button is released. 19 : * Crude software debouncing is implemented by limiting the refresh rate. 20 : * This version can be banked using an arbitrary list of alternative 21 : * addresses. 22 : * 23 : * @tparam NumBanks 24 : * The number of variants/alternative addresses the element has. 25 : * @tparam nb_rows 26 : * The number of rows of the matrix. 27 : * @tparam nb_cols 28 : * The number of columns of the matrix. 29 : * 30 : * @ingroup ManyAddressesMIDIOutputElements 31 : */ 32 : template <setting_t NumBanks, uint8_t nb_rows, uint8_t nb_cols> 33 2 : class NoteButtonMatrix 34 : : public MIDIButtonMatrix<ManyMatrixAddresses<NumBanks, nb_rows, nb_cols>, 35 : DigitalNoteSender, nb_rows, nb_cols> { 36 : public: 37 : /** 38 : * @brief Create a new Bankable NoteButtonMatrix object with the given 39 : * pins, controller numbers and channel. 40 : * 41 : * @param bank 42 : * The bank to add this element to. 43 : * @param rowPins 44 : * A list of pin numbers connected to the rows of the button 45 : * matrix. 46 : * **⚠** These pins will be driven LOW as outputs (Lo-Z). 47 : * @param colPins 48 : * A list of pin numbers connected to the columns of the button 49 : * matrix. 50 : * These pins will be used as inputs (Hi-Z), and the 51 : * internal pull-up resistor will be enabled. 52 : * @param notes 53 : * A list of 2-dimensional arrays of the same dimensions as the 54 : * button matrix that contains the MIDI Note number of each button. 55 : * [0, 127] 56 : * @param channelCNs 57 : * The a list containing the MIDI channels [CHANNEL_1, CHANNEL_16] 58 : * and Cable Numbers [CABLE_1, CABLE_16]. 59 : * @param velocity 60 : * The velocity of the MIDI Note events. 61 : */ 62 2 : NoteButtonMatrix( 63 : const Bank<NumBanks> &bank, const PinList<nb_rows> &rowPins, 64 : const PinList<nb_cols> &colPins, 65 : const Array<AddressMatrix<nb_rows, nb_cols>, NumBanks> ¬es, 66 : const Array<MIDIChannelCN, NumBanks> &channelCNs, 67 : uint8_t velocity = 0x7F) 68 2 : : MIDIButtonMatrix<ManyMatrixAddresses<NumBanks, nb_rows, nb_cols>, 69 : DigitalNoteSender, nb_rows, nb_cols>{ 70 2 : {bank, notes, channelCNs}, 71 2 : rowPins, 72 2 : colPins, 73 2 : {velocity}, 74 4 : } {} 75 : 76 : /// Set the velocity of the MIDI Note events. 77 : void setVelocity(uint8_t velocity) { this->sender.setVelocity(velocity); } 78 : /// Get the velocity of the MIDI Note events. 79 : uint8_t getVelocity() const { return this->sender.getVelocity(); } 80 : }; 81 : 82 : } // namespace ManyAddresses 83 : } // namespace Bankable 84 : 85 : END_CS_NAMESPACE