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

◆ UpdateIntensity()

void Key::UpdateIntensity ( uint32_t now_ms,
uint32_t delta_ms )

Definition at line 69 of file Keyboard.cpp.

69 {
70 if (on_) {
71 // Intensity can be calculated by a
72 float intensity =
75 AttackRemapFactor(now_ms);
76
77 // This is FRAME RATE DEPENDENT FUNCTION!!!!
78 // CHANGE TO TIME INDEPENDENT BEFORE SUBMIT.
79 intensity_ = (.9f * intensity) + (.1f * intensity_);
80 } else if(intensity_ > 0.0f) { // major cpu hotspot.
81
83 float delta_s = delta_ms / 1000.f;
84 if (intensity_ > .5f) {
85 const float kRate = .12f;
86 // Time flexible decay function. Stays accurate
87 // even as the frame rate changes.
88 // Formula: A = Pe^(r*t)
89 intensity_ = intensity_ * exp(-delta_s * kRate);
90 } else {
91 // Quickly fade at the bottom end of the transition.
92 const float kRate = .05f;
93 intensity_ -= delta_s * kRate;
94 }
95 } else {
96 float delta_s = delta_ms / 1000.f;
97 if (intensity_ > .5f) {
98 const float kRate = 12.0f;
99 // Time flexible decay function. Stays accurate
100 // even as the frame rate changes.
101 // Formula: A = Pe^(r*t)
102 intensity_ = intensity_ * exp(-delta_s * kRate);
103 } else {
104 // Quickly fade at the bottom end of the transition.
105 const float kRate = 2.0f;
106 intensity_ -= delta_s * kRate;
107 }
108
109 }
110 intensity_ = constrain(intensity_, 0.0f, 1.0f);
111 }
112}
T exp(T value)
Definition math.h:47
float AttackRemapFactor(uint32_t now_ms)
Definition Keyboard.cpp:57
unsigned long event_time_
Definition Keyboard.h:41
bool on_
Definition Keyboard.h:36
bool sustain_pedal_on_
Definition Keyboard.h:38
float CalcAttackDecayFactor(uint32_t delta_ms) const
Definition Keyboard.cpp:45
float VelocityFactor() const
Definition Keyboard.cpp:43
float intensity_
Definition Keyboard.h:46

References AttackRemapFactor(), CalcAttackDecayFactor(), event_time_, intensity_, on_, sustain_pedal_on_, and VelocityFactor().

Referenced by Update().

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