17 static const Datum kData[] = {
29 const float key = time * 255.f;
30 static const int n =
sizeof(kData) /
sizeof(kData[0]);
31 float approx_val =
Interp(key, kData, n);
34 static const float k = (1.0f / 255.f);
35 const float out = approx_val * k;
40 bool sustain_pedal_on,
59 float brigthness_factor = 0.0f;
75 if (color.
v_ <= 0.0) {
81 static const float kDefaultSaturationTime = 0.05f * 1000.f;
84 float saturation_factor =
mapf(time_delta_ms,
85 0.0f, kDefaultSaturationTime,
89 saturation_factor =
MIN(1.0f, saturation_factor);
92 return saturation_factor;
106 const float time_delta_ms =
static_cast<float>(now_ms - key.
event_time_);
108 const float lum = CalcLuminance(time_delta_ms, keyboard->
sustain_pedal_, key, i);
109 const float sat = CalcSaturation(time_delta_ms, key.
curr_color_, key.
on_);
166 const int* led_column_table,
int led_column_table_length,
170 FASTLED_WARN(
"\n\n############## VU NOTES ################\n\n");
174 for (
int i = 0; i < led_column_table_length; ++i) {
179 bool black_key =
false;
180 switch (key.
idx_ % 12) {
190 const int pixel_count = led_column_table[i];
191 const int draw_pixel_count = ceil(pixel_count * sqrt(key.
curr_color_.
v_));
193 const int black_pixel_count = pixel_count - draw_pixel_count;
197 const bool reverse_correct = black_key == (key.
idx_ % 2);
199 if (reverse_correct) {
200 for (
int j = 0; j < draw_pixel_count; ++j) {
201 if (j < draw_pixel_count - 1) {
205 ColorHSV hsv(random(512) / 512.f, random(512) / 512.f, 1.0);
210 for (
int j = 0; j < black_pixel_count; ++j) {
214 for (
int j = 0; j < black_pixel_count; ++j) {
218 for (
int j = draw_pixel_count - 1; j >= 0; --j) {
219 if (j < draw_pixel_count - 1) {
223 ColorHSV hsv(random(512) / 512.f, random(512) / 512.f, 1.0);
234 const int* led_column_table,
int led_column_table_length,
237 FASTLED_WARN(
"\n\n############## VU MID NOTES FADE ################\n\n");
247 float SumBrightness()
const {
250 out += (fade_factor * n_fade0);
251 out += (fade_factor * n_fade1);
260 static DrawPoints Generate(
int n_led,
float factor) {
262 memset(&out, 0,
sizeof(out));
263 if (n_led == 0 || factor == 0.0f) {
264 out.n_black0 = n_led;
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);
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) {
277 int n_half_black = n_half_lights - n_half_fill - n_fade_pix;
280 if (n_half_fill > 0) {
281 n_fill_pix = n_half_fill * 2 + (is_odd ? -1 : 0);
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) {
291 out.n_black1 = n_half_black;
292 out.fade_factor = fade_pix_perc;
300 for (
int i = 0; i < led_column_table_length; ++i) {
309 const int n_led = led_column_table[i];
311 if (active_lights_factor > 0.0f) {
312 DrawPoints dp = F::Generate(n_led, active_lights_factor);
320 c.
v_ = dp.fade_factor;
321 fade_col = c.
ToRGB();
331 if (active_lights_factor > 0.0) {
332 int total_lights_on = dp.SumBrightness();
337 #define P(X) dprint(", "#X ": "); dprint(X);
343 P(active_lights_factor);
361 const int* led_column_table,
int led_column_table_length,
366 uint32_t skipped_lights = 0;
367 for (
int i = 0; i < led_column_table_length; ++i) {
369 uint32_t painted_lights = 0;
372 const float active_lights_factor = led_column_table[i] * sqrt(key.
curr_color_.
v_);
373 const float inactive_lights_factor = 1.0f - active_lights_factor;
374 const float taper_point_1 = inactive_lights_factor / 2.0f;
375 const float taper_point_2 = taper_point_1 + active_lights_factor;
377 const int taper_idx_1 =
static_cast<int>(floor(taper_point_1 * led_column_table[i]));
378 const int taper_idx_2 =
static_cast<int>(floor(taper_point_2 * led_column_table[i]));
382 for (
int i = 0; i < taper_idx_1 / 2; ++i) {
387 int length = taper_idx_2 - taper_idx_1;
388 for (
int i = 0; i < min(200,
length); ++i) {
393 length = led_column_table[i] - taper_idx_2;
394 for (
int i = 0; i <
length; ++i) {
398 skipped_lights +=
MAX(0,
static_cast<int32_t
>(led_column_table[i]) -
static_cast<int32_t
>(painted_lights));
401 for (uint32_t i = 0; i < skipped_lights; ++i) {
410 const int* led_column_table,
int led_column_table_length,
414 int total_counted = 0;
432 float denom = total_counted ? total_counted : 1;
440 for (
int i = 0; i < led_column_table_length; ++i) {
441 const int n = led_column_table[i];
442 for (
int i = 0; i < n; ++i) {
451 const int* led_column_table,
int led_column_table_length,
457 for (
int i = 0; i < led_column_table_length; ++i) {
460 const int pixel_count = led_column_table[i];
461 const int draw_pixel_count = ceil(pixel_count * sqrt(key.
curr_color_.
v_));
463 const int black_pixel_count = pixel_count - draw_pixel_count;
467 for (
int j = 0; j < black_pixel_count; ++j) {
470 for (
int j = 0; j < draw_pixel_count; ++j) {
475 for (
int j = 0; j < draw_pixel_count; ++j) {
479 for (
int j = 0; j < black_pixel_count; ++j) {
ValT Interp(const KeyT &k, const InterpData< KeyT, ValT > *array, const int n)
static const int kNumKeys
virtual void RawDrawPixel(const Color3i &c)=0
virtual void RawCommitDraw()=0
virtual void Set(int i, const Color3i &c)=0
virtual void DrawRepeat(const int *value_array, int array_length)=0
virtual void RawBeginDraw()=0
virtual void RawDrawPixels(const Color3i &c, int n)=0
virtual Color3i * GetIterator(int i)=0
virtual void DrawSequentialRepeat(int repeat)=0
UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
LedColumns LedLayoutArray()
float CalcLuminance(float time_delta_ms, bool sustain_pedal_on, const Key &key, int key_idx)
float CalcSaturation(float time_delta_ms, const ColorHSV &color, bool key_on)
float LuminanceDecay(float time)
#define P(x)
Reads a single byte from the p array.
float IntensityFactor() const
unsigned long event_time_
static void PaintBrightSurprise(const KeyboardState &keyboard, const int *led_column_table, int led_column_table_length, LedRopeInterface *led_rope)
static void PaintVuNotes(uint32_t now_ms, const KeyboardState &keyboard, const int *led_column_table, int led_column_table_length, LedRopeInterface *led_rope)
static void PaintVuSpaceInvaders(uint32_t now_ms, const KeyboardState &keyboard, const int *led_column_table, int led_column_table_length, LedRopeInterface *led_rope)
static void Paint(uint32_t now_ms, uint32_t delta_ms, VisState vis_state, KeyboardState *keyboard, LedRopeInterface *light_rope)
static void PaintVuMidNotesFade(uint32_t delta_ms, const KeyboardState &keyboard, const int *led_column_table, int led_column_table_length, LedRopeInterface *led_rope)
static void VegasVisualizer(const KeyboardState &keyboard, const int *led_column_table, int led_column_table_length, LedRopeInterface *led_rope)
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
float CalcDecayFactor(bool sustain_pedal_on, bool key_on, int key_idx, float velocity, bool dampened_key, float time_elapsed_ms)