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.

51 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. Default lambda set to roughly 2 screen frames.
  19. */
  20. void setBrightnessSmooth(float brightness, float deltaTime, float lambda = 30.f) {
  21. if (brightness < value) {
  22. // Fade out light
  23. value += (brightness - value) * lambda * deltaTime;
  24. }
  25. else {
  26. // Immediately illuminate light
  27. value = brightness;
  28. }
  29. }
  30. /** DEPRECATED Alias for setBrightnessSmooth() */
  31. void setSmoothBrightness(float brightness, float deltaTime) {
  32. setBrightnessSmooth(brightness, deltaTime);
  33. }
  34. /** Use `setBrightnessSmooth(brightness, sampleTime * frames)` instead. */
  35. DEPRECATED void setBrightnessSmooth(float brightness, int frames = 1) {
  36. setBrightnessSmooth(brightness, frames / 44100.f);
  37. }
  38. };
  39. } // namespace engine
  40. } // namespace rack