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

◆ UpdateIntensity()

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

Definition at line 70 of file Keyboard.cpp.

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

References AttackRemapFactor(), CalcAttackDecayFactor(), fl::expf(), mEventTime, mIntensity, mOn, mSustainPedalOn, and VelocityFactor().

Referenced by Update().

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