16 static const Datum kData[] = {
28 const float key = time * 255.f;
29 static const int n =
sizeof(kData) /
sizeof(kData[0]);
30 float approx_val =
Interp(key, kData, n);
33 static const float k = (1.0f / 255.f);
34 const float out = approx_val * k;
39 bool sustain_pedal_on,
58 float brigthness_factor = 0.0f;
74 if (color.
v_ <= 0.0) {
80 static const float kDefaultSaturationTime = 0.05f * 1000.f;
83 float saturation_factor =
mapf(time_delta_ms,
84 0.0f, kDefaultSaturationTime,
88 saturation_factor =
MIN(1.0f, saturation_factor);
91 return saturation_factor;
105 const float time_delta_ms =
static_cast<float>(now_ms - key.
event_time_);
107 const float lum = CalcLuminance(time_delta_ms, keyboard->
sustain_pedal_, key, i);
108 const float sat = CalcSaturation(time_delta_ms, key.
curr_color_, key.
on_);
165 const int* led_column_table,
int led_column_table_length,
170 for (
int i = 0; i < led_column_table_length; ++i) {
175 bool black_key =
false;
176 switch (key.
idx_ % 12) {
186 const int pixel_count = led_column_table[i];
187 const int draw_pixel_count = ceil(pixel_count * sqrt(key.
curr_color_.
v_));
189 const int black_pixel_count = pixel_count - draw_pixel_count;
193 const bool reverse_correct = black_key == (key.
idx_ % 2);
195 if (reverse_correct) {
196 for (
int j = 0; j < draw_pixel_count; ++j) {
197 if (j < draw_pixel_count - 1) {
201 ColorHSV hsv(random(512) / 512.f, random(512) / 512.f, 1.0);
206 for (
int j = 0; j < black_pixel_count; ++j) {
210 for (
int j = 0; j < black_pixel_count; ++j) {
214 for (
int j = draw_pixel_count - 1; j >= 0; --j) {
215 if (j < draw_pixel_count - 1) {
219 ColorHSV hsv(random(512) / 512.f, random(512) / 512.f, 1.0);
230 const int* led_column_table,
int led_column_table_length,
240 float SumBrightness()
const {
243 out += (fade_factor * n_fade0);
244 out += (fade_factor * n_fade1);
253 static DrawPoints Generate(
int n_led,
float factor) {
255 memset(&out, 0,
sizeof(out));
256 if (n_led == 0 || factor == 0.0f) {
257 out.n_black0 = n_led;
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);
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) {
270 int n_half_black = n_half_lights - n_half_fill - n_fade_pix;
273 if (n_half_fill > 0) {
274 n_fill_pix = n_half_fill * 2 + (is_odd ? -1 : 0);
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) {
284 out.n_black1 = n_half_black;
285 out.fade_factor = fade_pix_perc;
293 for (
int i = 0; i < led_column_table_length; ++i) {
302 const int n_led = led_column_table[i];
304 if (active_lights_factor > 0.0f) {
305 DrawPoints dp = F::Generate(n_led, active_lights_factor);
313 c.
v_ = dp.fade_factor;
314 fade_col = c.
ToRGB();
324 if (active_lights_factor > 0.0) {
325 int total_lights_on = dp.SumBrightness();
330 #define P(X) dprint(", "#X ": "); dprint(X);
336 P(active_lights_factor);
354 const int* led_column_table,
int led_column_table_length,
359 uint32_t skipped_lights = 0;
360 for (
int i = 0; i < led_column_table_length; ++i) {
362 uint32_t painted_lights = 0;
365 const float active_lights_factor = led_column_table[i] * sqrt(key.
curr_color_.
v_);
366 const float inactive_lights_factor = 1.0f - active_lights_factor;
367 const float taper_point_1 = inactive_lights_factor / 2.0f;
368 const float taper_point_2 = taper_point_1 + active_lights_factor;
370 const int taper_idx_1 =
static_cast<int>(floor(taper_point_1 * led_column_table[i]));
371 const int taper_idx_2 =
static_cast<int>(floor(taper_point_2 * led_column_table[i]));
375 for (
int i = 0; i < taper_idx_1 / 2; ++i) {
380 int length = taper_idx_2 - taper_idx_1;
381 for (
int i = 0; i < min(200, length); ++i) {
386 length = led_column_table[i] - taper_idx_2;
387 for (
int i = 0; i < length; ++i) {
391 skipped_lights +=
MAX(0,
static_cast<int32_t
>(led_column_table[i]) -
static_cast<int32_t
>(painted_lights));
394 for (uint32_t i = 0; i < skipped_lights; ++i) {
403 const int* led_column_table,
int led_column_table_length,
407 int total_counted = 0;
425 float denom = total_counted ? total_counted : 1;
433 for (
int i = 0; i < led_column_table_length; ++i) {
434 const int n = led_column_table[i];
435 for (
int i = 0; i < n; ++i) {
444 const int* led_column_table,
int led_column_table_length,
450 for (
int i = 0; i < led_column_table_length; ++i) {
453 const int pixel_count = led_column_table[i];
454 const int draw_pixel_count = ceil(pixel_count * sqrt(key.
curr_color_.
v_));
456 const int black_pixel_count = pixel_count - draw_pixel_count;
460 for (
int j = 0; j < black_pixel_count; ++j) {
463 for (
int j = 0; j < draw_pixel_count; ++j) {
468 for (
int j = 0; j < draw_pixel_count; ++j) {
472 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
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)