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 71 of file util.cpp.

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

References MapDecayTime(), mapf(), and fl::max().

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: