Line data Source code
1 : #pragma once
2 :
3 : #include <Banks/BankAddresses.hpp>
4 : #include <MIDI_Outputs/Bankable/Abstract/MIDIButton.hpp>
5 : #include <MIDI_Senders/DigitalNoteSender.hpp>
6 :
7 : BEGIN_CS_NAMESPACE
8 : namespace Bankable {
9 : namespace ManyAddresses {
10 :
11 : /**
12 : * @brief A class of MIDIOutputElement%s that read the input of a **momentary
13 : * push button or switch**, and send out MIDI **Note** events.
14 : *
15 : * A Note On event is sent when the button is pressed, and a Note Off
16 : * event is sent when the button is released.
17 : * The button is debounced in software.
18 : * This version can be banked using an arbitrary list of alternative
19 : * addresses.
20 : *
21 : * @tparam NumBanks
22 : * The number of variants/alternative addresses the element has.
23 : *
24 : * @ingroup ManyAddressesMIDIOutputElements
25 : */
26 : template <setting_t NumBanks>
27 : class NoteButton
28 : : public Bankable::MIDIButton<ManyAddresses<NumBanks>, DigitalNoteSender> {
29 : public:
30 : /**
31 : * @brief Create a new Bankable NoteButton object with the given bank
32 : * configuration, button pin, and address.
33 : *
34 : * @param bank
35 : * The bank that selects the address to use.
36 : * @param pin
37 : * The digital input pin with the button connected.
38 : * The internal pull-up resistor will be enabled.
39 : * @param addresses
40 : * The list of MIDI addresses containing the note number
41 : * [0, 127], channel [Channel_1, Channel_16], and optional cable
42 : * number [Cable_1, Cable_16].
43 : * @param velocity
44 : * The velocity of the MIDI Note events.
45 : */
46 1 : NoteButton(const Bank<NumBanks> &bank, pin_t pin,
47 : const Array<MIDIAddress, NumBanks> &addresses,
48 : uint8_t velocity = 0x7F)
49 : : MIDIButton<ManyAddresses<NumBanks>, DigitalNoteSender> {
50 1 : {bank, addresses}, pin, {velocity}} {}
51 :
52 : /// Set the velocity of the MIDI Note events.
53 : void setVelocity(uint8_t velocity) { this->sender.setVelocity(velocity); }
54 : /// Get the velocity of the MIDI Note events.
55 : uint8_t getVelocity() const { return this->sender.getVelocity(); }
56 : };
57 :
58 : } // namespace ManyAddresses
59 : } // namespace Bankable
60 :
61 : END_CS_NAMESPACE
|