This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
FastLED.hpp
Go to the documentation of this file.
1 #if defined(ARDUINO) && defined(FASTLED_VERSION)
2 #include <FastLED.h>
3 #endif
4 
6 #include <stdint.h>
7 
9 
11 struct Color {
12  uint8_t r;
13  uint8_t g;
14  uint8_t b;
15 #ifdef FASTLED_VERSION
16  explicit operator CRGB() const { return CRGB{r, g, b}; }
17 #endif
18 };
19 
24  Color operator()(uint8_t value, uint8_t index) const;
25 };
26 
28 
29 #ifdef FASTLED_VERSION
30 
32 
34 
37 template <class ColorMapper>
39  public:
40  NoteCCFastLED(CRGB *ledcolors, const ColorMapper &colormapper)
42 
48  void setBrightness(uint8_t brightness) { this->brightness = brightness; }
50  uint8_t getBrightness() const { return this->brightness; }
51 
52  void begin(const INoteCCValue &t) override {
53  updateAll(t);
54  }
55 
56  void update(const INoteCCValue &t, uint8_t index) override {
57  uint8_t value = t.getValue(index);
58  ledcolors[index] =
59  CRGB{colormapper(value, index)}.nscale8_video(brightness);
60  }
61 
62  private:
63  CRGB *ledcolors;
64  uint8_t brightness = 255;
65 
66  public:
67  ColorMapper colormapper;
68 };
69 
72 
79 template <uint8_t RangeLen, class ColorMapper = DefaultColorMapper>
81  : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
82  NoteCCFastLED<ColorMapper>> {
83  public:
84 #if 0
85  NoteRangeFastLED(CRGB (&leds)[RangeLen], MIDICNChannelAddress address,
86  const ColorMapper &colormapper = {})
89  address,
90  {leds, colormapper},
91  } {}
92 #endif
93 
95  const ColorMapper &colormapper = {})
98  address,
99  {leds.data, colormapper},
100  } {}
101 
103  const ColorMapper &colormapper = {})
106  address,
107  {leds, colormapper},
108  } {}
109 
111  void setBrightness(uint8_t brightness) {
112  this->callback.setBrightness(brightness);
113  }
115  uint8_t getBrightness() const { return this->callback.getBrightness(); }
116 };
117 
118 template <class ColorMapper = DefaultColorMapper>
119 class NoteValueFastLED : public GenericNoteCCRange<MIDIInputElementNote, 1,
120  NoteCCFastLED<ColorMapper>> {
121  public:
123  const ColorMapper &colormapper = {})
126  address,
127  {&led, colormapper},
128  } {}
129 
131  void setBrightness(uint8_t brightness) {
132  this->callback.setBrightness(brightness);
133  }
135  uint8_t getBrightness() const { return this->callback.getBrightness(); }
136 };
137 
138 template <uint8_t RangeLen, class ColorMapper = DefaultColorMapper>
139 class CCRangeFastLED : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
140  NoteCCFastLED<ColorMapper>> {
141 
142  public:
143 #if 0
144  CCRangeFastLED(CRGB (&leds)[RangeLen], MIDICNChannelAddress address,
145  const ColorMapper &colormapper = {})
148  address,
149  {leds, colormapper},
150  } {}
151 #endif
152 
154  const ColorMapper &colormapper = {})
157  address,
158  {leds.data, colormapper},
159  } {}
160 
162  const ColorMapper &colormapper = {})
165  address,
166  {leds, colormapper},
167  } {}
168 
170  void setBrightness(uint8_t brightness) {
171  this->callback.setBrightness(brightness);
172  }
174  uint8_t getBrightness() const { return this->callback.getBrightness(); }
175 };
176 
177 template <class ColorMapper = DefaultColorMapper>
178 class CCValueFastLED : public GenericNoteCCRange<MIDIInputElementCC, 1,
179  NoteCCFastLED<ColorMapper>> {
180  public:
182  const ColorMapper &colormapper = {})
184  address,
185  {&led, colormapper},
186  } {}
187 
189  void setBrightness(uint8_t brightness) {
190  this->callback.setBrightness(brightness);
191  }
193  uint8_t getBrightness() const { return this->callback.getBrightness(); }
194 };
195 
197 
198 namespace Bankable {
199 
202 
203 template <uint8_t RangeLen, uint8_t BankSize,
204  class ColorMapper = DefaultColorMapper>
206  : public GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
207  NoteCCFastLED<ColorMapper>> {
208  public:
209 #if 0
210  NoteRangeFastLED(BankConfig<BankSize> config, CRGB (&leds)[RangeLen],
212  const ColorMapper &colormapper = {})
213  : GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
215  config,
216  address,
217  {leds, colormapper},
218  } {}
219 #endif
220 
223  const ColorMapper &colormapper = {})
224  : GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
226  config,
227  address,
228  {leds.data, colormapper},
229  } {}
230 
233  const ColorMapper &colormapper = {})
234  : GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
236  config,
237  address,
238  {leds, colormapper},
239  } {}
240 
242  void setBrightness(uint8_t brightness) {
243  this->callback.setBrightness(brightness);
244  }
246  uint8_t getBrightness() const { return this->callback.getBrightness(); }
247 };
248 
249 template <uint8_t BankSize, class ColorMapper = DefaultColorMapper>
251  : public GenericNoteCCRange<MIDIInputElementNote, 1, BankSize,
252  NoteCCFastLED<ColorMapper>> {
253  public:
256  const ColorMapper &colormapper = {})
259  config,
260  address,
261  {&led, colormapper},
262  } {}
263 
265  void setBrightness(uint8_t brightness) {
266  this->callback.setBrightness(brightness);
267  }
269  uint8_t getBrightness() const { return this->callback.getBrightness(); }
270 };
271 
272 template <uint8_t RangeLen, uint8_t BankSize,
273  class ColorMapper = DefaultColorMapper>
275  : public GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
276  NoteCCFastLED<ColorMapper>> {
277  public:
278 #if 0
279  CCRangeFastLED(BankConfig<BankSize> config, CRGB (&leds)[RangeLen],
281  const ColorMapper &colormapper = {})
282  : GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
284  config,
285  address,
286  {leds, colormapper},
287  } {}
288 #endif
289 
292  const ColorMapper &colormapper = {})
293  : GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
295  config,
296  address,
297  {leds.data, colormapper},
298  } {}
299 
302  const ColorMapper &colormapper = {})
303  : GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
305  config,
306  address,
307  {leds, colormapper},
308  } {}
309 
311  void setBrightness(uint8_t brightness) {
312  this->callback.setBrightness(brightness);
313  }
315  uint8_t getBrightness() const { return this->callback.getBrightness(); }
316 };
317 
318 template <uint8_t BankSize, class ColorMapper = DefaultColorMapper>
320  : public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize,
321  NoteCCFastLED<ColorMapper>> {
322  public:
325  const ColorMapper &colormapper = {})
326  : GenericNoteCCRange<MIDIInputElementCC, 1, BankSize,
328  config,
329  address,
330  {&led, colormapper},
331  } {}
332 
334  void setBrightness(uint8_t brightness) {
335  this->callback.setBrightness(brightness);
336  }
338  uint8_t getBrightness() const { return this->callback.getBrightness(); }
339 };
340 
342 
343 } // namespace Bankable
344 
346 
347 #endif
DefaultColorMapper
The default mapping from a 7-bit MIDI value to an RGB color.
Definition: FastLED.hpp:22
NoteCCFastLED
Callback for Note or CC range or value input that displays the value to a FastLED strip.
Definition: FastLED.hpp:38
NoteRangeFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:115
MIDIInputElementNote
Class for objects that listen for incoming MIDI Note events.
Definition: MIDIInputElementNote.hpp:20
CCValueFastLED::CCValueFastLED
CCValueFastLED(CRGB &led, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:181
NoteValueFastLED::NoteValueFastLED
NoteValueFastLED(CRGB &led, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:122
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition: BankAddresses.hpp:7
Bankable::CCValueFastLED
Definition: FastLED.hpp:319
NoteCCFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:50
GenericNoteCCRange
Definition: NoteCCRange.hpp:105
INoteCCValue
Definition: NoteCCRange.hpp:9
NoteCCFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:48
NoteCCFastLED::update
void update(const INoteCCValue &t, uint8_t index) override
Definition: FastLED.hpp:56
NoteCCRange< MIDIInputElementNote, RangeLen, 1, NoteCCFastLED< ColorMapper > >::callback
NoteCCFastLED< ColorMapper > callback
Definition: NoteCCRange.hpp:97
NoteRangeFastLED
Definition: FastLED.hpp:80
SimpleNoteCCValueCallback
Definition: NoteCCRange.hpp:29
CCValueFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:189
Bankable::CCRangeFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:315
Bankable::GenericNoteCCRange
Definition: NoteCCRange.hpp:164
MIDIInputElementCC
Class for objects that listen for incoming MIDI Controller Change events.
Definition: MIDIInputElementCC.hpp:23
Array
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:20
Bankable::NoteValueFastLED::NoteValueFastLED
NoteValueFastLED(BankConfig< BankSize > config, CRGB &led, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:254
NoteCCFastLED::colormapper
ColorMapper colormapper
Definition: FastLED.hpp:67
Bankable::CCValueFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:338
Array::data
T data[N]
Definition: Array.hpp:21
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
NoteRangeFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:111
Bankable::CCValueFastLED::CCValueFastLED
CCValueFastLED(BankConfig< BankSize > config, CRGB &led, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:323
Bankable::NoteRangeFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:242
Bankable::NoteValueFastLED
Definition: FastLED.hpp:250
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
Bankable::CCRangeFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:311
NoteRangeFastLED::NoteRangeFastLED
NoteRangeFastLED(CRGB *leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:102
NoteCCFastLED::brightness
uint8_t brightness
Definition: FastLED.hpp:64
NoteCCFastLED::begin
void begin(const INoteCCValue &t) override
Definition: FastLED.hpp:52
DefaultColorMapper::operator()
Color operator()(uint8_t value, uint8_t index) const
Map from a 7-bit MIDI value to an RGB color.
Definition: FastLED.cpp:8
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
Bankable::NoteRangeFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:246
NoteValueFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:131
NamespaceSettings.hpp
Bankable::NoteRangeFastLED::NoteRangeFastLED
NoteRangeFastLED(BankConfig< BankSize > config, CRGB *leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:231
CCValueFastLED
Definition: FastLED.hpp:178
Bankable::NoteRangeFastLED::NoteRangeFastLED
NoteRangeFastLED(BankConfig< BankSize > config, Array< CRGB, RangeLen > &leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:221
NoteCCFastLED::ledcolors
CRGB * ledcolors
Definition: FastLED.hpp:63
Bankable::CCRangeFastLED::CCRangeFastLED
CCRangeFastLED(BankConfig< BankSize > config, CRGB *leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:300
NoteValueFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:135
Bankable::NoteRangeFastLED
Definition: FastLED.hpp:205
NoteValueFastLED
Definition: FastLED.hpp:119
Color::g
uint8_t g
Definition: FastLED.hpp:13
CCRangeFastLED::CCRangeFastLED
CCRangeFastLED(CRGB *leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:161
BankConfig
A struct for selecting the bank of BankableMIDIInputs and the bank type.
Definition: BankConfig.hpp:39
MIDIInputElement::address
const MIDICNChannelAddress address
Definition: MIDIInputElement.hpp:80
Bankable::CCValueFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:334
NoteRangeFastLED::NoteRangeFastLED
NoteRangeFastLED(Array< CRGB, RangeLen > &leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:94
INoteCCValue::getValue
virtual uint8_t getValue(uint8_t index) const =0
CCValueFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:193
Bankable::CCRangeFastLED
Definition: FastLED.hpp:274
Color::b
uint8_t b
Definition: FastLED.hpp:14
NoteCCFastLED::NoteCCFastLED
NoteCCFastLED(CRGB *ledcolors, const ColorMapper &colormapper)
Definition: FastLED.hpp:40
CCRangeFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:174
Bankable::CCRangeFastLED::CCRangeFastLED
CCRangeFastLED(BankConfig< BankSize > config, Array< CRGB, RangeLen > &leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:290
Bankable::NoteValueFastLED::getBrightness
uint8_t getBrightness() const
Get the maximum brightness of the LEDs.
Definition: FastLED.hpp:269
CCRangeFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:170
NoteCCRange.hpp
CCRangeFastLED::CCRangeFastLED
CCRangeFastLED(Array< CRGB, RangeLen > &leds, MIDICNChannelAddress address, const ColorMapper &colormapper={})
Definition: FastLED.hpp:153
Color
A structure for RGB colors.
Definition: FastLED.hpp:11
Bankable::NoteValueFastLED::setBrightness
void setBrightness(uint8_t brightness)
Set the maximum brightness of the LEDs.
Definition: FastLED.hpp:265
SimpleNoteCCValueCallback::updateAll
virtual void updateAll(const INoteCCValue &noteccval)
Definition: NoteCCRange.hpp:36
CCRangeFastLED
Definition: FastLED.hpp:139
Color::r
uint8_t r
Definition: FastLED.hpp:12