FastLED 3.9.15
Loading...
Searching...
No Matches

◆ CalcDecayFactor()

float CalcDecayFactor ( bool sustain_pedal_on,
bool key_on,
int key_idx,
float velocity,
bool dampened_key,
float time_elapsed_ms )

Definition at line 70 of file util.cpp.

75 {
76
77 static const float kDefaultDecayTime = .2f * 1000.f;
78 static const float kBias = 1.10;
79 float decay_time = kDefaultDecayTime; // default - no sustain.
80 if (key_on || sustain_pedal_on || !dampened_key) {
81 decay_time = MapDecayTime(key_idx) * max(0.25f, velocity);
82 }
83 // decay_interp is a value which starts off as 1.0 to signify the start of the
84 // key press and gradually decreases to 0.0. For example, if the decay time is 1 second
85 // then at the time = 0s, decay_interp is 1.0, and after one second decay_interp is 0.0
86 float intensity_factor = mapf(time_elapsed_ms,
87 0.0, decay_time * kBias,
88 1.0, 0.0); // Startup at full brightness -> no brighness.
89
90
91 // When decay_interp reaches 0, the lighting sequence is effectively finished. However
92 // because this is time based and time keeps on going this value will move into negative
93 // territory, we take care of this by simply clamping all negative values to 0.0.
94 intensity_factor = constrain(intensity_factor, 0.0f, 1.0f);
95 return intensity_factor;
96}
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
Definition util.cpp:17
float MapDecayTime(uint8_t key_idx)
Definition util.cpp:33

References MapDecayTime(), and mapf().

Referenced by Key::CalcAttackDecayFactor(), and anonymous_namespace{Painter.cpp}::CalcLuminance().

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