Line data Source code
1 : #pragma once 2 : 3 : #include <MIDI_Inputs/MIDIInputElementPC.hpp> 4 : #include <Selectors/Selector.hpp> 5 : 6 : BEGIN_CS_NAMESPACE 7 : 8 : template <setting_t N, class Callback = EmptySelectorCallback> 9 2 : class GenericProgramChangeSelector : public GenericSelector<N, Callback>, 10 : public MIDIInputElementPC { 11 : public: 12 2 : GenericProgramChangeSelector(Selectable<N> &selectable, 13 : const Callback &callback, 14 : const MIDIChannelCN &address) 15 2 : : GenericSelector<N, Callback>{selectable, callback}, 16 4 : MIDIInputElementPC{address} {} 17 : 18 0 : void begin() override { 19 0 : MIDIInputElementPC::begin(); 20 0 : GenericSelector<N, Callback>::begin(); 21 0 : } 22 : 23 0 : void reset() override { GenericSelector<N, Callback>::reset(); } 24 : 25 0 : bool updateImpl(const ChannelMessageMatcher &midimsg, 26 : const MIDIAddress &target) override { 27 0 : (void)target; 28 0 : uint8_t program = midimsg.data1; 29 0 : if (program < N) { 30 0 : this->set(program); 31 0 : } else { 32 0 : DEBUGFN(F("Warning: Received Program Change to program 0x") 33 : << hex << program << dec 34 : << F(", which is not smaller than the number of settings (") 35 : << N << ')'); 36 : } 37 0 : return true; 38 0 : } 39 : }; 40 : 41 : /** 42 : * @brief Selector that listens for MIDI Program Change events on a given 43 : * MIDI Channel, and uses the program number as its selection. 44 : * 45 : * @tparam N 46 : * The number of settings. The maximum program number is @f$ N - 1 @f$. 47 : * @ingroup Selectors 48 : */ 49 : template <setting_t N> 50 1 : class ProgramChangeSelector : public GenericProgramChangeSelector<N> { 51 : public: 52 1 : ProgramChangeSelector(Selectable<N> &selectable, 53 : const MIDIChannelCN &address) 54 1 : : GenericProgramChangeSelector<N>{selectable, {}, address} {} 55 : }; 56 : 57 : END_CS_NAMESPACE