From 09c85276d6d8ef217a53e54856296bde6983b511 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 13 May 2019 13:52:36 -0400 Subject: [PATCH] Use linear scaling for Light value. --- include/engine/Light.hpp | 6 +++--- src/app/ModuleLightWidget.cpp | 12 ++++++------ src/engine/Engine.cpp | 10 ++++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/engine/Light.hpp b/include/engine/Light.hpp index 46029b2c..2a2ba504 100644 --- a/include/engine/Light.hpp +++ b/include/engine/Light.hpp @@ -14,16 +14,16 @@ struct Light { /** Sets the brightness immediately with no light decay. */ void setBrightness(float brightness) { - value = (brightness > 0.f) ? std::pow(brightness, 2) : 0.f; + value = (brightness > 0.f) ? brightness : 0.f; } float getBrightness() { - return std::sqrt(value); + return value; } /** Emulates light decay with slow fall but immediate rise. */ void setSmoothBrightness(float brightness, float deltaTime) { - float v = (brightness > 0.f) ? std::pow(brightness, 2) : 0.f; + float v = (brightness > 0.f) ? brightness : 0.f; if (v < value) { // Fade out light const float lambda = 30.f; diff --git a/src/app/ModuleLightWidget.cpp b/src/app/ModuleLightWidget.cpp index c1f0aec5..34977ae5 100644 --- a/src/app/ModuleLightWidget.cpp +++ b/src/app/ModuleLightWidget.cpp @@ -12,13 +12,13 @@ void ModuleLightWidget::step() { assert(module->lights.size() >= firstLightId + baseColors.size()); for (size_t i = 0; i < baseColors.size(); i++) { - float brightness = module->lights[firstLightId + i].getBrightness(); - if (!std::isfinite(brightness)) - brightness = 0.f; + float b = module->lights[firstLightId + i].getBrightness(); + if (!std::isfinite(b)) + b = 0.f; + b = math::clamp(b, 0.f, 1.f); // Because LEDs are nonlinear, this seems to look more natural. - brightness = std::sqrt(brightness); - brightness = math::clamp(brightness, 0.f, 1.f); - brightnesses[i] = brightness; + b = std::sqrt(b); + brightnesses[i] = b; } } else { diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index d9aa252c..e6f56da9 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -495,6 +495,7 @@ void Engine::addModule(Module *module) { } // Add module internal->modules.push_back(module); + // Trigger Add event module->onAdd(); // Update ParamHandles for (ParamHandle *paramHandle : internal->paramHandles) { @@ -507,6 +508,9 @@ void Engine::removeModule(Module *module) { assert(module); VIPLock vipLock(internal->vipMutex); std::lock_guard lock(internal->mutex); + // Check that the module actually exists + auto it = std::find(internal->modules.begin(), internal->modules.end(), module); + assert(it != internal->modules.end()); // If a param is being smoothed on this module, stop smoothing it immediately if (module == internal->smoothModule) { internal->smoothModule = NULL; @@ -532,11 +536,9 @@ void Engine::removeModule(Module *module) { m->rightModule = NULL; } } - // Check that the module actually exists - auto it = std::find(internal->modules.begin(), internal->modules.end(), module); - assert(it != internal->modules.end()); - // Remove the module + // Trigger Remove event module->onRemove(); + // Remove module internal->modules.erase(it); }