Line data Source code
1 : #pragma once 2 : 3 : #include <MIDI_Outputs/Abstract/MIDIButtons.hpp> 4 : #include <MIDI_Senders/DigitalNoteSender.hpp> 5 : 6 : BEGIN_CS_NAMESPACE 7 : 8 : /** 9 : * @brief A class of MIDIOutputElement%s that read the input of a **collection 10 : * of momentary push buttons or switches**, and send out MIDI **Note** 11 : * events. 12 : * 13 : * A Note On event is sent when a button is pressed, and a Note Off event is 14 : * sent when a button is released. 15 : * The buttons are debounced in software. 16 : * This version cannot be banked. 17 : * 18 : * @tparam NumButtons 19 : * The number of buttons in the collection. 20 : * 21 : * @ingroup MIDIOutputElements 22 : */ 23 : template <uint8_t NumButtons> 24 : class NoteButtons : public MIDIButtons<DigitalNoteSender, NumButtons> { 25 : public: 26 : /** 27 : * @brief Create a new NoteButtons object with the given pins, 28 : * the given controller number and channel. 29 : * 30 : * @param buttons 31 : * A list of digital input pins with the buttons connected. 32 : * The internal pull-up resistors will be enabled. 33 : * @param baseAddress 34 : * The MIDI address of the first button, containing the note 35 : * number [0, 127], channel [Channel_1, Channel_16], and optional 36 : * cable number [Cable_1, Cable_16]. 37 : * @param incrementAddress 38 : * The number of addresses to increment for each next button. 39 : * E.g. if `baseAddress` is 8, and `incrementAddress` is 2, 40 : * then the first button will send on address 8, the second 41 : * button will send on address 10, button three on address 12, etc. 42 : * @param velocity 43 : * The velocity of the MIDI Note events. 44 : */ 45 1 : NoteButtons(const Array<AH::Button, NumButtons> &buttons, 46 : MIDIAddress baseAddress, RelativeMIDIAddress incrementAddress, 47 : uint8_t velocity = 0x7F) 48 : : MIDIButtons<DigitalNoteSender, NumButtons> { 49 : buttons, 50 : baseAddress, 51 : incrementAddress, 52 : {velocity}, 53 1 : } {} 54 : 55 : /// Set the velocity of the MIDI Note events. 56 : void setVelocity(uint8_t velocity) { this->sender.setVelocity(velocity); } 57 : /// Get the velocity of the MIDI Note events. 58 : uint8_t getVelocity() const { return this->sender.getVelocity(); } 59 : }; 60 : 61 : END_CS_NAMESPACE