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