You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1KB

  1. #pragma once
  2. #include <common.hpp>
  3. namespace rack {
  4. namespace engine {
  5. struct Light {
  6. /** The square of the brightness.
  7. Unstable API. Use set/getBrightness().
  8. */
  9. float value = 0.f;
  10. /** Sets the brightness immediately with no light decay. */
  11. void setBrightness(float brightness) {
  12. value = brightness;
  13. }
  14. float getBrightness() {
  15. return value;
  16. }
  17. /** Emulates light decay with slow fall but immediate rise. */
  18. void setBrightnessSmooth(float brightness, float deltaTime) {
  19. if (brightness < value) {
  20. // Fade out light
  21. const float lambda = 30.f;
  22. value += (brightness - value) * lambda * deltaTime;
  23. }
  24. else {
  25. // Immediately illuminate light
  26. value = brightness;
  27. }
  28. }
  29. /** Alias for setBrightnessSmooth() */
  30. void setSmoothBrightness(float brightness, float deltaTime) {
  31. setBrightnessSmooth(brightness, deltaTime);
  32. }
  33. /** Use `setBrightnessSmooth(brightness, sampleTime * frames)` instead. */
  34. DEPRECATED void setBrightnessSmooth(float brightness, int frames = 1) {
  35. setSmoothBrightness(brightness, frames / 44100.f);
  36. }
  37. };
  38. } // namespace engine
  39. } // namespace rack