| 68 | } |
| 69 | |
| 70 | void Key::UpdateIntensity(uint32_t now_ms, uint32_t delta_ms) { |
| 71 | if (mOn) { |
| 72 | // Intensity can be calculated by a |
| 73 | float intensity = |
| 74 | CalcAttackDecayFactor(now_ms - mEventTime) * |
| 75 | VelocityFactor() * |
| 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 | } |
| 114 | |
| 115 | void KeyboardState::HandleNoteOn(uint8_t midi_note, uint8_t velocity, int color_selector_value, uint32_t now_ms) { |
| 116 | if (0 == velocity) { |
nothing calls this directly
no test coverage detected