Line data Source code
1 : #pragma once 2 : 3 : #include <Banks/BankAddresses.hpp> 4 : #include <MIDI_Outputs/Bankable/Abstract/MIDIButtons.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 of a **collection 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 : * The buttons are debounced in software. 19 : * This version can be banked. 20 : * 21 : * @tparam NumButtons 22 : * The number of buttons in the collection. 23 : * 24 : * @ingroup BankableMIDIOutputElements 25 : */ 26 : template <uint8_t NumButtons> 27 : class NoteButtons 28 : : public MIDIButtons<SingleAddress, DigitalNoteSender, NumButtons> { 29 : public: 30 : /** 31 : * @brief Create a new Bankable NoteButtons object with the given pins, 32 : * the given controller number and channel. 33 : * 34 : * @param config 35 : * The bank configuration to use: the bank to add this element to, 36 : * and whether to change the address, channel or cable number. 37 : * @param buttons 38 : * A list of digital input pins with the buttons connected. 39 : * The internal pull-up resistors will be enabled. 40 : * @param baseAddress 41 : * The MIDI address of the first button, containing the note 42 : * number [0, 127], channel [Channel_1, Channel_16], and optional 43 : * cable number [Cable_1, Cable_16]. 44 : * @param incrementAddress 45 : * The number of addresses to increment for each next button. 46 : * E.g. if `baseAddress` is 8, and `incrementAddress` is 2, 47 : * then the first button will send on address 8, the second 48 : * button will send on address 10, button three on address 12, etc. 49 : * @param velocity 50 : * The velocity of the MIDI Note events. 51 : */ 52 1 : NoteButtons(OutputBankConfig<> config, 53 : const Array<AH::Button, NumButtons> &buttons, 54 : MIDIAddress baseAddress, RelativeMIDIAddress incrementAddress, 55 : uint8_t velocity = 0x7F) 56 : : MIDIButtons<SingleAddress, DigitalNoteSender, NumButtons> { 57 : {config, baseAddress}, 58 : buttons, 59 : incrementAddress, 60 : {velocity}, 61 1 : } {} 62 : 63 : /// Set the velocity of the MIDI Note events. 64 : void setVelocity(uint8_t velocity) { this->sender.setVelocity(velocity); } 65 : /// Get the velocity of the MIDI Note events. 66 : uint8_t getVelocity() const { return this->sender.getVelocity(); } 67 : }; 68 : 69 : } // namespace Bankable 70 : 71 : END_CS_NAMESPACE