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 232 of file Painter.cpp.

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

References Color3i::Black(), Key::curr_color_, dprintln, FASTLED_WARN, Key::IntensityFactor(), KeyboardState::keys_, P, LedRopeInterface::RawBeginDraw(), LedRopeInterface::RawCommitDraw(), LedRopeInterface::RawDrawPixels(), ColorHSV::ToRGB(), and ColorHSV::v_.

Referenced by Paint().

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