Line data Source code
1 : #include <Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
2 : #include <MIDI_Inputs/NoteCCRange.hpp>
3 :
4 : BEGIN_CS_NAMESPACE
5 :
6 : template <uint8_t NumLEDs>
7 1 : class NoteCCLED : public SimpleNoteCCValueCallback {
8 : public:
9 1 : NoteCCLED(const PinList<NumLEDs> &ledPins) : ledPins(ledPins) {}
10 :
11 : void setThreshold(uint8_t threshold) { this->threshold = threshold; }
12 : uint8_t getThreshold() const { return this->threshold; }
13 :
14 2 : void begin(const INoteCCValue &t) override {
15 4 : for (pin_t pin : ledPins)
16 2 : ExtIO::pinMode(pin, OUTPUT);
17 2 : updateAll(t);
18 2 : }
19 :
20 4 : void update(const INoteCCValue &t, uint8_t index) override {
21 4 : uint8_t value = t.getValue(index);
22 4 : bool state = value > threshold;
23 4 : ExtIO::digitalWrite(ledPins[index], state);
24 4 : }
25 :
26 : private:
27 : PinList<NumLEDs> ledPins;
28 1 : uint8_t threshold = 0x3F;
29 : };
30 :
31 : template <uint8_t RangeLen>
32 : class NoteRangeLEDs : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
33 : NoteCCLED<RangeLen>> {
34 : public:
35 : NoteRangeLEDs(const PinList<RangeLen> &ledPins,
36 : MIDICNChannelAddress address)
37 : : GenericNoteCCRange<MIDIInputElementNote, RangeLen,
38 : NoteCCLED<RangeLen>>{
39 : address,
40 : {ledPins},
41 : } {}
42 : };
43 :
44 1 : class NoteValueLED
45 : : public GenericNoteCCRange<MIDIInputElementNote, 1, NoteCCLED<1>> {
46 : public:
47 1 : NoteValueLED(pin_t ledPin, MIDICNChannelAddress address)
48 1 : : GenericNoteCCRange<MIDIInputElementNote, 1, NoteCCLED<1>>{
49 1 : address,
50 1 : {{ledPin}},
51 2 : } {}
52 : };
53 :
54 : using MIDINoteLED[[deprecated("Use NoteValueLED instead")]] = NoteValueLED;
55 :
56 : template <uint8_t RangeLen>
57 : class CCRangeLEDs : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
58 : NoteCCLED<RangeLen>> {
59 : public:
60 : CCRangeLEDs(const PinList<RangeLen> &ledPins, MIDICNChannelAddress address)
61 : : GenericNoteCCRange<MIDIInputElementCC, RangeLen, NoteCCLED<RangeLen>>{
62 : address,
63 : {ledPins},
64 : } {}
65 : };
66 :
67 : class CCValueLED
68 : : public GenericNoteCCRange<MIDIInputElementCC, 1, NoteCCLED<1>> {
69 : public:
70 : CCValueLED(pin_t ledPin, MIDICNChannelAddress address)
71 : : GenericNoteCCRange<MIDIInputElementCC, 1, NoteCCLED<1>>{
72 : address,
73 : {{ledPin}},
74 : } {}
75 : };
76 :
77 : namespace Bankable {
78 :
79 : template <uint8_t RangeLen, uint8_t BankSize>
80 : class NoteRangeLEDs : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
81 : BankSize, NoteCCLED<RangeLen>> {
82 : public:
83 : NoteRangeLEDs(const BankConfig<BankSize> &config,
84 : const PinList<RangeLen> &ledPins,
85 : const MIDICNChannelAddress &address)
86 : : GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
87 : NoteCCLED<RangeLen>>{
88 : config,
89 : address,
90 : {ledPins},
91 : } {}
92 : };
93 :
94 : template <uint8_t BankSize>
95 : class NoteValueLED : public GenericNoteCCRange<MIDIInputElementNote, 1,
96 : BankSize, NoteCCLED<1>> {
97 : public:
98 : NoteValueLED(const BankConfig<BankSize> &config, pin_t ledPin,
99 : const MIDICNChannelAddress &address)
100 : : GenericNoteCCRange<MIDIInputElementNote, 1, BankSize, NoteCCLED<1>>{
101 : config,
102 : address,
103 : {{ledPin}},
104 : } {}
105 : };
106 :
107 : template <uint8_t BankSize>
108 : using MIDINoteLED[[deprecated("Use NoteValueLED instead")]] =
109 : NoteValueLED<BankSize>;
110 :
111 : template <uint8_t RangeLen, uint8_t BankSize>
112 : class CCRangeLEDs : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
113 : BankSize, NoteCCLED<RangeLen>> {
114 : public:
115 : CCRangeLEDs(const BankConfig<BankSize> &config,
116 : const PinList<RangeLen> &ledPins,
117 : const MIDICNChannelAddress &address)
118 : : GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
119 : NoteCCLED<RangeLen>>{
120 : config,
121 : address,
122 : {ledPins},
123 : } {}
124 : };
125 :
126 : template <uint8_t BankSize>
127 : class CCValueLED
128 : : public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>> {
129 : public:
130 : CCValueLED(const BankConfig<BankSize> &config, pin_t ledPin,
131 : const MIDICNChannelAddress &address)
132 : : GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>>{
133 : config,
134 : address,
135 : {{ledPin}},
136 : } {}
137 : };
138 :
139 : } // namespace Bankable
140 :
141 : END_CS_NAMESPACE
|