18 static const Datum kData[] = {
30 const float key = time * 255.f;
31 static const int n =
sizeof(kData) /
sizeof(kData[0]);
32 float approx_val =
Interp(key, kData, n);
35 static const float k = (1.0f / 255.f);
36 const float out = approx_val * k;
41 bool sustain_pedal_on,
60 float brigthness_factor = 0.0f;
76 if (color.
v_ <= 0.0) {
82 static const float kDefaultSaturationTime = 0.05f * 1000.f;
85 float saturation_factor =
mapf(time_delta_ms,
86 0.0f, kDefaultSaturationTime,
90 saturation_factor =
fl::min(1.0f, saturation_factor);
93 return saturation_factor;
107 const float time_delta_ms =
static_cast<float>(now_ms - key.
mEventTime);
109 const float lum = CalcLuminance(time_delta_ms,
keyboard->mSustainPedal, key, i);
110 const float sat = CalcSaturation(time_delta_ms, key.
mCurrColor, key.
mOn);
167 const int* led_column_table,
int led_column_table_length,
171 FL_WARN(
"\n\n############## VU NOTES ################\n\n");
175 for (
int i = 0; i < led_column_table_length; ++i) {
180 bool black_key =
false;
181 switch (key.
mIdx % 12) {
191 const int pixel_count = led_column_table[i];
194 const int black_pixel_count = pixel_count - draw_pixel_count;
198 const bool reverse_correct = black_key == (key.
mIdx % 2);
200 if (reverse_correct) {
201 for (
int j = 0; j < draw_pixel_count; ++j) {
202 if (j < draw_pixel_count - 1) {
206 ColorHSV hsv(random(512) / 512.f, random(512) / 512.f, 1.0);
211 for (
int j = 0; j < black_pixel_count; ++j) {
215 for (
int j = 0; j < black_pixel_count; ++j) {
219 for (
int j = draw_pixel_count - 1; j >= 0; --j) {
220 if (j < draw_pixel_count - 1) {
224 ColorHSV hsv(random(512) / 512.f, random(512) / 512.f, 1.0);
235 const int* led_column_table,
int led_column_table_length,
238 FL_WARN(
"\n\n############## VU MID NOTES FADE ################\n\n");
248 float SumBrightness()
const {
251 out += (fade_factor * n_fade0);
252 out += (fade_factor * n_fade1);
261 static DrawPoints Generate(
int n_led,
float factor) {
264 if (n_led == 0 || factor == 0.0f) {
265 out.n_black0 = n_led;
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);
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) {
278 int n_half_black = n_half_lights - n_half_fill - n_fade_pix;
281 if (n_half_fill > 0) {
282 n_fill_pix = n_half_fill * 2 + (is_odd ? -1 : 0);
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) {
292 out.n_black1 = n_half_black;
293 out.fade_factor = fade_pix_perc;
301 for (
int i = 0; i < led_column_table_length; ++i) {
310 const int n_led = led_column_table[i];
312 if (active_lights_factor > 0.0f) {
313 DrawPoints dp = F::Generate(n_led, active_lights_factor);
321 c.
v_ = dp.fade_factor;
322 fade_col = c.
ToRGB();
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);
332 if (active_lights_factor > 0.0) {
333 int total_lights_on = dp.SumBrightness();
338 #define P(X) dprint(", "#X ": "); dprint(X);
344 P(active_lights_factor);
362 const int* led_column_table,
int led_column_table_length,
367 uint32_t skipped_lights = 0;
368 for (
int i = 0; i < led_column_table_length; ++i) {
370 uint32_t painted_lights = 0;
374 const float inactive_lights_factor = 1.0f - active_lights_factor;
375 const float taper_point_1 = inactive_lights_factor / 2.0f;
376 const float taper_point_2 = taper_point_1 + active_lights_factor;
378 const int taper_idx_1 =
static_cast<int>(
fl::floor(taper_point_1 * led_column_table[i]));
379 const int taper_idx_2 =
static_cast<int>(
fl::floor(taper_point_2 * led_column_table[i]));
383 for (
int i = 0; i < taper_idx_1 / 2; ++i) {
388 int length = taper_idx_2 - taper_idx_1;
394 length = led_column_table[i] - taper_idx_2;
395 for (
int i = 0; i <
length; ++i) {
399 skipped_lights +=
fl::max(0,
static_cast<int32_t
>(led_column_table[i]) -
static_cast<int32_t
>(painted_lights));
402 for (uint32_t i = 0; i < skipped_lights; ++i) {
411 const int* led_column_table,
int led_column_table_length,
415 int total_counted = 0;
433 float denom = total_counted ? total_counted : 1;
441 for (
int i = 0; i < led_column_table_length; ++i) {
442 const int n = led_column_table[i];
443 for (
int i = 0; i < n; ++i) {
452 const int* led_column_table,
int led_column_table_length,
458 for (
int i = 0; i < led_column_table_length; ++i) {
461 const int pixel_count = led_column_table[i];
464 const int black_pixel_count = pixel_count - draw_pixel_count;
468 for (
int j = 0; j < black_pixel_count; ++j) {
471 for (
int j = 0; j < draw_pixel_count; ++j) {
476 for (
int j = 0; j < draw_pixel_count; ++j) {
480 for (
int j = 0; j < black_pixel_count; ++j) {
ValT Interp(const KeyT &k, const InterpData< KeyT, ValT > *array, const int n)
LedRopeTCL led_rope(kNumKeys)
static const int kNumKeys
virtual void Set(int i, const Color3i &c)=0
virtual void DrawRepeat(const int *value_array, int array_length)=0
virtual void DrawSequentialRepeat(int repeat)=0
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
LedColumns LedLayoutArray()
Centralized logging categories for FastLED hardware interfaces and subsystems.
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)
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type ceil(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NOEXCEPT
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type floor(T x) FL_NOEXCEPT
float IntensityFactor() const
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)