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

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

References Color3i::Black(), Key::curr_color_, dprintln, 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: