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

◆ UpdateIntensity()

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

Definition at line 71 of file Keyboard.cpp.

71 {
72 if (on_) {
73 // Intensity can be calculated by a
74 float intensity =
77 AttackRemapFactor(now_ms);
78
79 // This is FRAME RATE DEPENDENT FUNCTION!!!!
80 // CHANGE TO TIME INDEPENDENT BEFORE SUBMIT.
81 intensity_ = (.9f * intensity) + (.1f * intensity_);
82 } else if(intensity_ > 0.0f) { // major cpu hotspot.
83
85 float delta_s = delta_ms / 1000.f;
86 if (intensity_ > .5f) {
87 const float kRate = .12f;
88 // Time flexible decay function. Stays accurate
89 // even as the frame rate changes.
90 // Formula: A = Pe^(r*t)
91 intensity_ = intensity_ * exp(-delta_s * kRate);
92 } else {
93 // Quickly fade at the bottom end of the transition.
94 const float kRate = .05f;
95 intensity_ -= delta_s * kRate;
96 }
97 } else {
98 float delta_s = delta_ms / 1000.f;
99 if (intensity_ > .5f) {
100 const float kRate = 12.0f;
101 // Time flexible decay function. Stays accurate
102 // even as the frame rate changes.
103 // Formula: A = Pe^(r*t)
104 intensity_ = intensity_ * exp(-delta_s * kRate);
105 } else {
106 // Quickly fade at the bottom end of the transition.
107 const float kRate = 2.0f;
108 intensity_ -= delta_s * kRate;
109 }
110
111 }
112 intensity_ = constrain(intensity_, 0.0f, 1.0f);
113 }
114}
float AttackRemapFactor(uint32_t now_ms)
Definition Keyboard.cpp:59
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:47
float VelocityFactor() const
Definition Keyboard.cpp:45
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: