Control Surface  1.2.0
MIDI Control Surface library for Arduino
NoteCCRangeLEDs.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
9 
11 
14 template <uint8_t NumLEDs>
16  public:
17  NoteCCLED(const PinList<NumLEDs> &ledPins) : ledPins(ledPins) {}
18 
19  void setThreshold(uint8_t threshold) { this->threshold = threshold; }
20  uint8_t getThreshold() const { return this->threshold; }
21 
22  void begin(const INoteCCValue &t) override {
23  for (pin_t pin : ledPins)
25  updateAll(t);
26  }
27 
28  void update(const INoteCCValue &t, uint8_t index) override {
29  uint8_t value = t.getValue(index);
30  bool state = value > threshold;
31  AH::ExtIO::digitalWrite(ledPins[index], state ? HIGH : LOW);
32  }
33 
34  private:
35  PinList<NumLEDs> ledPins;
36  uint8_t threshold = 0x00;
37 };
38 
41 template <uint8_t NumLEDs>
43  public:
44  NoteCCLEDPWM(const PinList<NumLEDs> &ledPins) : ledPins(ledPins) {}
45 
46  void begin(const INoteCCValue &t) override {
47  for (pin_t pin : ledPins)
49  updateAll(t);
50  }
51 
52  void update(const INoteCCValue &t, uint8_t index) override {
53  uint8_t value = AH::increaseBitDepth<8, 7, uint8_t>(t.getValue(index));
54  AH::ExtIO::analogWrite(ledPins[index], value);
55  }
56 
57  private:
58  PinList<NumLEDs> ledPins;
59 };
60 
61 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
62 // Everything below is just definitions of type aliases to make the library
63 // easier to use.
64 //
65 // It defines MIDI elements that listen to (a single, a range of)
66 // (MIDI Note, MIDI Control Change) message(s) that display the values of
67 // these messages using normal on/off or PWM LEDs.
68 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
69 
70 // --------------------------------- ON/OFF --------------------------------- //
71 
74 
84 template <uint8_t RangeLen>
85 class NoteRangeLEDs : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
86  NoteCCLED<RangeLen>> {
87  public:
99  NoteRangeLEDs(const PinList<RangeLen> &ledPins, MIDIAddress address)
101  NoteCCLED<RangeLen>>{
102  address,
103  {ledPins},
104  } {}
105 };
106 
114  : public GenericNoteCCRange<MIDIInputElementNote, 1, NoteCCLED<1>> {
115  public:
126  address,
127  {{ledPin}},
128  } {}
129 };
130 
133 using MIDINoteLED [[deprecated("Use NoteValueLED instead")]] = NoteValueLED;
134 
144 template <uint8_t RangeLen>
145 class CCRangeLEDs : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
146  NoteCCLED<RangeLen>> {
147  public:
159  CCRangeLEDs(const PinList<RangeLen> &ledPins, MIDIAddress address)
160  : GenericNoteCCRange<MIDIInputElementCC, RangeLen, NoteCCLED<RangeLen>>{
161  address,
162  {ledPins},
163  } {}
164 };
165 
173  : public GenericNoteCCRange<MIDIInputElementCC, 1, NoteCCLED<1>> {
174  public:
185  address,
186  {{ledPin}},
187  } {}
188 };
189 
191 
192 namespace Bankable {
193 
196 
197 template <uint8_t RangeLen, uint8_t BankSize>
198 class NoteRangeLEDs : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
199  BankSize, NoteCCLED<RangeLen>> {
200  public:
201  NoteRangeLEDs(BankConfig<BankSize> config, const PinList<RangeLen> &ledPins,
203  : GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
204  NoteCCLED<RangeLen>>{
205  config,
206  address,
207  {ledPins},
208  } {}
209 };
210 
211 template <uint8_t BankSize>
212 class NoteValueLED : public GenericNoteCCRange<MIDIInputElementNote, 1,
213  BankSize, NoteCCLED<1>> {
214  public:
217  config,
218  address,
219  {{ledPin}},
220  } {}
221 };
222 
225 template <uint8_t BankSize>
226 using MIDINoteLED [[deprecated("Use NoteValueLED instead")]] =
228 
229 template <uint8_t RangeLen, uint8_t BankSize>
230 class CCRangeLEDs : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
231  BankSize, NoteCCLED<RangeLen>> {
232  public:
233  CCRangeLEDs(BankConfig<BankSize> config, const PinList<RangeLen> &ledPins,
234  const MIDIAddress &address)
235  : GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
236  NoteCCLED<RangeLen>>{
237  config,
238  address,
239  {ledPins},
240  } {}
241 };
242 
243 template <uint8_t BankSize>
245  : public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>> {
246  public:
248  const MIDIAddress &address)
249  : GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>>{
250  config,
251  address,
252  {{ledPin}},
253  } {}
254 };
255 
257 
258 } // namespace Bankable
259 
260 // ----------------------------------- PWM ---------------------------------- //
261 
264 
273 template <uint8_t RangeLen>
275  : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
276  NoteCCLEDPWM<RangeLen>> {
277  public:
289  NoteRangeLEDsPWM(const PinList<RangeLen> &ledPins, MIDIAddress address)
291  NoteCCLEDPWM<RangeLen>>{
292  address,
293  {ledPins},
294  } {}
295 };
296 
303  : public GenericNoteCCRange<MIDIInputElementNote, 1, NoteCCLEDPWM<1>> {
304  public:
315  address,
316  {{ledPin}},
317  } {}
318 };
319 
328 template <uint8_t RangeLen>
329 class CCRangeLEDsPWM : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
330  NoteCCLEDPWM<RangeLen>> {
331  public:
343  CCRangeLEDsPWM(const PinList<RangeLen> &ledPins, MIDIAddress address)
345  NoteCCLEDPWM<RangeLen>>{
346  address,
347  {ledPins},
348  } {}
349 };
350 
357  : public GenericNoteCCRange<MIDIInputElementCC, 1, NoteCCLEDPWM<1>> {
358  public:
369  address,
370  {{ledPin}},
371  } {}
372 };
373 
375 
376 namespace Bankable {
377 
380 
381 template <uint8_t RangeLen, uint8_t BankSize>
383  : public GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
384  NoteCCLEDPWM<RangeLen>> {
385  public:
387  const PinList<RangeLen> &ledPins,
388  const MIDIAddress &address)
389  : GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
390  NoteCCLEDPWM<RangeLen>>{
391  config,
392  address,
393  {ledPins},
394  } {}
395 };
396 
397 template <uint8_t BankSize>
398 class NoteValueLEDPWM : public GenericNoteCCRange<MIDIInputElementNote, 1,
399  BankSize, NoteCCLEDPWM<1>> {
400  public:
402  const MIDIAddress &address)
404  NoteCCLEDPWM<1>>{
405  config,
406  address,
407  {{ledPin}},
408  } {}
409 };
410 
411 template <uint8_t RangeLen, uint8_t BankSize>
413  : public GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
414  NoteCCLEDPWM<RangeLen>> {
415  public:
417  const PinList<RangeLen> &ledPins, const MIDIAddress &address)
418  : GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
419  NoteCCLEDPWM<RangeLen>>{
420  config,
421  address,
422  {ledPins},
423  } {}
424 };
425 
426 template <uint8_t BankSize>
427 class CCValueLEDPWM : public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize,
428  NoteCCLEDPWM<1>> {
429  public:
431  const MIDIAddress &address)
433  config,
434  address,
435  {{ledPin}},
436  } {}
437 };
438 
440 
441 } // namespace Bankable
442 
444 
LOW
const PinStatus_t LOW
Definition: ExtendedInputOutput.hpp:57
AH::ExtIO::analogWrite
void analogWrite(pin_t pin, analog_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:86
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
Bankable::CCValueLED
Definition: NoteCCRangeLEDs.hpp:245
Bankable::CCRangeLEDs::CCRangeLEDs
CCRangeLEDs(BankConfig< BankSize > config, const PinList< RangeLen > &ledPins, const MIDIAddress &address)
Definition: NoteCCRangeLEDs.hpp:233
MIDIInputElementNote
Class for objects that listen for incoming MIDI Note events.
Definition: MIDIInputElementNote.hpp:21
MIDIInputElement::address
const MIDIAddress address
Definition: MIDIInputElement.hpp:83
Warnings.hpp
Bankable::NoteValueLED
Definition: NoteCCRangeLEDs.hpp:213
Bankable::CCValueLEDPWM
Definition: NoteCCRangeLEDs.hpp:428
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition: BankAddresses.hpp:7
NoteCCLEDPWM::ledPins
PinList< NumLEDs > ledPins
Definition: NoteCCRangeLEDs.hpp:58
SimpleNoteCCValueCallback::updateAll
virtual void updateAll(const INoteCCValue &noteccval)
Update all values: called when a bank change causes all values to (possibly) change,...
Definition: NoteCCRange.hpp:58
NoteValueLED::NoteValueLED
NoteValueLED(pin_t ledPin, MIDIAddress address)
Construct a new NoteValueLED object.
Definition: NoteCCRangeLEDs.hpp:124
CCValueLED::CCValueLED
CCValueLED(pin_t ledPin, MIDIAddress address)
Construct a new CCValueLED object.
Definition: NoteCCRangeLEDs.hpp:183
GenericNoteCCRange
Definition: NoteCCRange.hpp:156
INoteCCValue
Interface for NoteCCValue objects: provides getters for the velocity or controller values.
Definition: NoteCCRange.hpp:13
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
Bankable::NoteValueLEDPWM
Definition: NoteCCRangeLEDs.hpp:399
SimpleNoteCCValueCallback
A callback for NoteCCRange with an action that can be implemented by the user.
Definition: NoteCCRange.hpp:46
Bankable::NoteRangeLEDsPWM::NoteRangeLEDsPWM
NoteRangeLEDsPWM(BankConfig< BankSize > config, const PinList< RangeLen > &ledPins, const MIDIAddress &address)
Definition: NoteCCRangeLEDs.hpp:386
Bankable::GenericNoteCCRange
Definition: NoteCCRange.hpp:249
NoteRangeLEDs::NoteRangeLEDs
NoteRangeLEDs(const PinList< RangeLen > &ledPins, MIDIAddress address)
Construct a new NoteRangeLEDs object.
Definition: NoteCCRangeLEDs.hpp:99
IncreaseBitDepth.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
MIDIInputElementCC
Class for objects that listen for incoming MIDI Controller Change events.
Definition: MIDIInputElementCC.hpp:26
NoteCCLED::begin
void begin(const INoteCCValue &t) override
Initialize: called once.
Definition: NoteCCRangeLEDs.hpp:22
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
Bankable::CCValueLED::CCValueLED
CCValueLED(BankConfig< BankSize > config, pin_t ledPin, const MIDIAddress &address)
Definition: NoteCCRangeLEDs.hpp:247
Bankable::CCRangeLEDs
Definition: NoteCCRangeLEDs.hpp:231
AH::ExtIO::digitalWrite
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:48
NoteCCLEDPWM::NoteCCLEDPWM
NoteCCLEDPWM(const PinList< NumLEDs > &ledPins)
Definition: NoteCCRangeLEDs.hpp:44
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
HIGH
const PinStatus_t HIGH
Definition: ExtendedInputOutput.hpp:56
Bankable::NoteRangeLEDs::NoteRangeLEDs
NoteRangeLEDs(BankConfig< BankSize > config, const PinList< RangeLen > &ledPins, MIDIAddress address)
Definition: NoteCCRangeLEDs.hpp:201
Bankable::NoteValueLED::NoteValueLED
NoteValueLED(BankConfig< BankSize > config, pin_t ledPin, MIDIAddress address)
Definition: NoteCCRangeLEDs.hpp:215
CCRangeLEDsPWM::CCRangeLEDsPWM
CCRangeLEDsPWM(const PinList< RangeLen > &ledPins, MIDIAddress address)
Construct a new CCRangeLEDsPWM object.
Definition: NoteCCRangeLEDs.hpp:343
NoteCCLEDPWM::update
void update(const INoteCCValue &t, uint8_t index) override
Update the given index: called when a new message is received for this index.
Definition: NoteCCRangeLEDs.hpp:52
OUTPUT
const PinMode_t OUTPUT
Definition: ExtendedInputOutput.hpp:60
CCRangeLEDs::CCRangeLEDs
CCRangeLEDs(const PinList< RangeLen > &ledPins, MIDIAddress address)
Construct a new CCRangeLEDs object.
Definition: NoteCCRangeLEDs.hpp:159
NoteValueLED
MIDI Input Element that listens for MIDI Note messages for the given note, and displays its value by ...
Definition: NoteCCRangeLEDs.hpp:114
NoteCCLED::ledPins
PinList< NumLEDs > ledPins
Definition: NoteCCRangeLEDs.hpp:35
NoteRangeLEDsPWM::NoteRangeLEDsPWM
NoteRangeLEDsPWM(const PinList< RangeLen > &ledPins, MIDIAddress address)
Construct a new NoteRangeLEDsPWM object.
Definition: NoteCCRangeLEDs.hpp:289
NoteCCLED::NoteCCLED
NoteCCLED(const PinList< NumLEDs > &ledPins)
Definition: NoteCCRangeLEDs.hpp:17
Bankable::CCValueLEDPWM::CCValueLEDPWM
CCValueLEDPWM(BankConfig< BankSize > config, pin_t ledPin, const MIDIAddress &address)
Definition: NoteCCRangeLEDs.hpp:430
NoteCCLED
Callback for Note or CC range or value input that displays the value to a normal on/off LED.
Definition: NoteCCRangeLEDs.hpp:15
INoteCCValue::getValue
virtual uint8_t getValue(uint8_t index) const =0
Get the velocity or controller value for the given index in the range.
CCRangeLEDsPWM
MIDI Input Element that listens for MIDI Control Change messages in a given range,...
Definition: NoteCCRangeLEDs.hpp:330
NoteCCLEDPWM
Callback for Note or CC range or value input that displays the value to a PWM LED.
Definition: NoteCCRangeLEDs.hpp:42
CCRangeLEDs
MIDI Input Element that listens for MIDI Control Change messages in a given range,...
Definition: NoteCCRangeLEDs.hpp:146
AH::ExtIO::pinMode
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:36
NoteCCLED::setThreshold
void setThreshold(uint8_t threshold)
Definition: NoteCCRangeLEDs.hpp:19
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
CCValueLED
MIDI Input Element that listens for MIDI Control Change messages for the given controller,...
Definition: NoteCCRangeLEDs.hpp:173
CCValueLEDPWM
MIDI Input Element that listens for MIDI Control Change messages for the given controller,...
Definition: NoteCCRangeLEDs.hpp:357
BankConfig
Definition: BankConfig.hpp:51
Bankable::CCRangeLEDsPWM
Definition: NoteCCRangeLEDs.hpp:414
NoteRangeLEDsPWM
MIDI Input Element that listens for MIDI Note messages in a given range, and displays their velocity ...
Definition: NoteCCRangeLEDs.hpp:276
Bankable::CCRangeLEDsPWM::CCRangeLEDsPWM
CCRangeLEDsPWM(BankConfig< BankSize > config, const PinList< RangeLen > &ledPins, const MIDIAddress &address)
Definition: NoteCCRangeLEDs.hpp:416
NoteValueLEDPWM
MIDI Input Element that listens for MIDI Note messages for the given note, and displays its velocity ...
Definition: NoteCCRangeLEDs.hpp:303
NoteCCLEDPWM::begin
void begin(const INoteCCValue &t) override
Initialize: called once.
Definition: NoteCCRangeLEDs.hpp:46
Bankable::NoteRangeLEDs
Definition: NoteCCRangeLEDs.hpp:199
NoteCCLED::threshold
uint8_t threshold
Definition: NoteCCRangeLEDs.hpp:36
NoteRangeLEDs
MIDI Input Element that listens for MIDI Note messages in a given range, and displays their values by...
Definition: NoteCCRangeLEDs.hpp:86
Bankable::NoteValueLEDPWM::NoteValueLEDPWM
NoteValueLEDPWM(BankConfig< BankSize > config, pin_t ledPin, const MIDIAddress &address)
Definition: NoteCCRangeLEDs.hpp:401
NoteCCRange.hpp
Bankable::NoteRangeLEDsPWM
Definition: NoteCCRangeLEDs.hpp:384
NoteValueLEDPWM::NoteValueLEDPWM
NoteValueLEDPWM(pin_t ledPin, MIDIAddress address)
Construct a new NoteValueLEDPWM object.
Definition: NoteCCRangeLEDs.hpp:313
NoteCCLED::update
void update(const INoteCCValue &t, uint8_t index) override
Update the given index: called when a new message is received for this index.
Definition: NoteCCRangeLEDs.hpp:28
NoteCCLED::getThreshold
uint8_t getThreshold() const
Definition: NoteCCRangeLEDs.hpp:20
CCValueLEDPWM::CCValueLEDPWM
CCValueLEDPWM(pin_t ledPin, MIDIAddress address)
Construct a new CCValueLEDPWM object.
Definition: NoteCCRangeLEDs.hpp:367