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.

37 lines
743B

  1. #include <app/ModuleLightWidget.hpp>
  2. namespace rack {
  3. namespace app {
  4. void ModuleLightWidget::step() {
  5. std::vector<float> brightnesses(baseColors.size());
  6. if (module) {
  7. assert(module->lights.size() >= firstLightId + baseColors.size());
  8. for (size_t i = 0; i < baseColors.size(); i++) {
  9. float b = module->lights[firstLightId + i].getBrightness();
  10. if (!std::isfinite(b))
  11. b = 0.f;
  12. b = math::clamp(b, 0.f, 1.f);
  13. // Because LEDs are nonlinear, this seems to look more natural.
  14. b = std::sqrt(b);
  15. brightnesses[i] = b;
  16. }
  17. }
  18. else {
  19. // Turn all lights on
  20. for (size_t i = 0; i < baseColors.size(); i++) {
  21. brightnesses[i] = 1.f;
  22. }
  23. }
  24. setBrightnesses(brightnesses);
  25. }
  26. } // namespace app
  27. } // namespace rack