Line data Source code
1 : #pragma once 2 : 3 : #include <AH/Hardware/IncrementDecrementButtons.hpp> 4 : #include <Banks/BankableAddresses.hpp> 5 : #include <Def/Def.hpp> 6 : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp> 7 : #include <MIDI_Senders/DigitalNoteSender.hpp> 8 : 9 : BEGIN_CS_NAMESPACE 10 : 11 : namespace Bankable { 12 : 13 : /** 14 : * @brief An abstract class for two buttons that send incremental MIDI events. 15 : * 16 : * @todo Combine RelativeSender and ResetSender? 17 : */ 18 : template <class BankAddress, class RelativeSender, class ResetSender> 19 2 : class MIDIIncrementDecrementButtons : public MIDIOutputElement { 20 : protected: 21 : /** 22 : * @brief Construct a new MIDIIncrementDecrementButtons. 23 : * 24 : * @todo Documentation 25 : */ 26 2 : MIDIIncrementDecrementButtons(BankAddress addresses, 27 : const AH::IncrementDecrementButtons &buttons, 28 : uint8_t multiplier, 29 : const RelativeSender &relativeSender, 30 : const ResetSender &resetSender) 31 2 : : addresses{addresses}, buttons{buttons}, multiplier{multiplier}, 32 6 : relativeSender(relativeSender), resetSender(resetSender) {} 33 : 34 : public: 35 0 : void begin() override { buttons.begin(); } 36 : 37 0 : void update() override { 38 : using IncrDecrButtons = AH::IncrementDecrementButtons; 39 0 : MIDIAddress address = addresses.getFirstActiveAddress(); 40 0 : switch (buttons.update()) { 41 0 : case IncrDecrButtons::Nothing: break; 42 : case IncrDecrButtons::IncrementShort: // fallthrough 43 : case IncrDecrButtons::IncrementLong: // fallthrough 44 : case IncrDecrButtons::IncrementHold: 45 0 : send(multiplier, address); 46 0 : break; 47 : case IncrDecrButtons::DecrementShort: // fallthrough 48 : case IncrDecrButtons::DecrementLong: // fallthrough 49 : case IncrDecrButtons::DecrementHold: 50 0 : send(-multiplier, address); 51 0 : break; 52 0 : case IncrDecrButtons::Reset: reset(); break; 53 0 : default: break; 54 : } 55 0 : } 56 : 57 0 : void send(long delta, const MIDIAddress &address) { 58 0 : relativeSender.send(delta, address); 59 0 : } 60 : 61 0 : void reset() { 62 0 : MIDIAddress address = addresses.getSecondActiveAddress(); 63 0 : if (address) { 64 0 : resetSender.sendOn(address); 65 0 : resetSender.sendOff(address); 66 0 : } 67 0 : } 68 : 69 : #ifdef AH_INDIVIDUAL_BUTTON_INVERT 70 : void invert() { buttons.invert(); } 71 : #endif 72 : 73 : AH::IncrementDecrementButtons::State getButtonsState() const { 74 : return buttons.getState(); 75 : } 76 : 77 : private: 78 : BankAddress addresses; 79 : AH::IncrementDecrementButtons buttons; 80 : const uint8_t multiplier; 81 : 82 : public: 83 : RelativeSender relativeSender; 84 : ResetSender resetSender; 85 : }; 86 : 87 : } // namespace Bankable 88 : 89 : END_CS_NAMESPACE