FastLED 3.9.15
Loading...
Searching...
No Matches

◆ PaintVuMidNotesFade()

void Painter::PaintVuMidNotesFade ( uint32_t delta_ms,
const KeyboardState & keyboard,
const int * led_column_table,
int led_column_table_length,
LedRopeInterface * led_rope )
staticprivate

Definition at line 233 of file Painter.cpp.

236 {
237
238 FL_WARN("\n\n############## VU MID NOTES FADE ################\n\n");
239
240 struct DrawPoints {
241 int n_black0;
242 int n_fade0;
243 int n_fill;
244 int n_fade1;
245 int n_black1;
246 float fade_factor; // 0->1.0
247
248 float SumBrightness() const {
249 float out = 0;
250 out += n_fill;
251 out += (fade_factor * n_fade0);
252 out += (fade_factor * n_fade1);
253 return out;
254 }
255 };
256
257 // Generator for the DrawPoints struct above.
258 // n_led: How many led's there are in total.
259 // factor: 0->1, indicates % of led's "on".
260 struct F {
261 static DrawPoints Generate(int n_led, float factor) {
262 DrawPoints out;
263 fl::memset(&out, 0, sizeof(out));
264 if (n_led == 0 || factor == 0.0f) {
265 out.n_black0 = n_led;
266 return out;
267 }
268 const int is_odd = (n_led % 2);
269 const int n_half_lights = n_led / 2 + is_odd;
270 const float f_half_fill = n_half_lights * factor;
271 const int n_half_fill = static_cast<int>(f_half_fill); // Truncates float.
272
273 float fade_pix_perc = f_half_fill - static_cast<float>(n_half_fill);
274 int n_fade_pix = fade_pix_perc < 1.0f;
275 if (n_half_fill == 0) {
276 n_fade_pix = 1;
277 }
278 int n_half_black = n_half_lights - n_half_fill - n_fade_pix;
279
280 int n_fill_pix = 0;
281 if (n_half_fill > 0) {
282 n_fill_pix = n_half_fill * 2 + (is_odd ? -1 : 0);
283 }
284
285 out.n_black0 = n_half_black;
286 out.n_fade0 = n_fade_pix;
287 out.n_fill = n_fill_pix;
288 out.n_fade1 = n_fade_pix;
289 if (!n_fill_pix && is_odd) {
290 out.n_fade1 = 0;
291 }
292 out.n_black1 = n_half_black;
293 out.fade_factor = fade_pix_perc;
294 return out;
295 }
296 };
297
298
300
301 for (int i = 0; i < led_column_table_length; ++i) {
302 const Key& key = keyboard.mKeys[i];
303
304 float active_lights_factor = key.IntensityFactor();
305
306 //if (key.mCurrColor.v_ <= 0.f) {
307 // active_lights_factor = 0.0;
308 //}
309
310 const int n_led = led_column_table[i];
311
312 if (active_lights_factor > 0.0f) {
313 DrawPoints dp = F::Generate(n_led, active_lights_factor);
314
315 ColorHSV hsv = key.mCurrColor;
316 hsv.v_ = 1.0;
317 Color3i color = hsv.ToRGB();
318 // Now figure out optional fade color
319 Color3i fade_col;
320 ColorHSV c = key.mCurrColor;
321 c.v_ = dp.fade_factor;
322 fade_col = c.ToRGB();
323
324 // Output to graphics.
325 led_rope->RawDrawPixels(Color3i::Black(), dp.n_black0);
326 led_rope->RawDrawPixels(fade_col, dp.n_fade0);
327 led_rope->RawDrawPixels(color, dp.n_fill);
328 led_rope->RawDrawPixels(fade_col, dp.n_fade1);
329 led_rope->RawDrawPixels(Color3i::Black(), dp.n_black1);
330
331#ifdef DEBUG_PAINTER
332 if (active_lights_factor > 0.0) {
333 int total_lights_on = dp.SumBrightness();
334 //dprint("total_lights_on: "); dprint(total_lights_on);
335 //dprint(", total lights written: "); dprintln(total_lights_on + dp.n_black0 + dp.n_black1);
336
337 //float total = (dp.n_fade0 * dp.fade_factor) + (dp.n_fade1 * dp.fade_factor) + static_cast<float>(dp.n_fill);
338 #define P(X) dprint(", "#X ": "); dprint(X);
339
340 //dprint("active_lights_factor: "); dprintln(active_lights_factor);
341
342 //P(dp.n_black0); P(dp.n_fade0); P(dp.n_fill); P(dp.n_fade1); P(dp.n_black1); P(dp.fade_factor);
343 P(total_lights_on);
344 P(active_lights_factor);
345 //P(total);
346 dprintln("");
347 }
348#endif
349 } else {
351 }
352
353
354
355 }
356
357
359}
LedRopeTCL led_rope(kNumKeys)
KeyboardState keyboard
Key mKeys[kNumKeys]
Definition Keyboard.h:103
void RawCommitDraw()
void RawDrawPixels(const Color3i &c, int n)
void RawBeginDraw()
#define dprintln(x)
Definition dprint.h:14
#define FL_WARN(X)
Definition log.h:276
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
FASTLED_FORCE_INLINE fl::u8 P(fl::u8 x)
static Color3i Black()
Definition color.h:7
float v_
Definition color.h:108
Color3i ToRGB() const
Definition color.cpp:129
float IntensityFactor() const
Definition Keyboard.cpp:66
ColorHSV mCurrColor
Definition Keyboard.h:48

References Color3i::Black(), dprintln, FL_WARN, Key::IntensityFactor(), keyboard, led_rope, Key::mCurrColor, fl::memset(), ColorHSV::ToRGB(), and ColorHSV::v_.

Referenced by Paint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: