@@ -14,16 +14,16 @@ struct Light { | |||||
/** Sets the brightness immediately with no light decay. */ | /** Sets the brightness immediately with no light decay. */ | ||||
void setBrightness(float brightness) { | void setBrightness(float brightness) { | ||||
value = (brightness > 0.f) ? std::pow(brightness, 2) : 0.f; | |||||
value = (brightness > 0.f) ? brightness : 0.f; | |||||
} | } | ||||
float getBrightness() { | float getBrightness() { | ||||
return std::sqrt(value); | |||||
return value; | |||||
} | } | ||||
/** Emulates light decay with slow fall but immediate rise. */ | /** Emulates light decay with slow fall but immediate rise. */ | ||||
void setSmoothBrightness(float brightness, float deltaTime) { | 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) { | if (v < value) { | ||||
// Fade out light | // Fade out light | ||||
const float lambda = 30.f; | const float lambda = 30.f; | ||||
@@ -12,13 +12,13 @@ void ModuleLightWidget::step() { | |||||
assert(module->lights.size() >= firstLightId + baseColors.size()); | assert(module->lights.size() >= firstLightId + baseColors.size()); | ||||
for (size_t i = 0; i < baseColors.size(); i++) { | 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. | // 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 { | else { | ||||
@@ -495,6 +495,7 @@ void Engine::addModule(Module *module) { | |||||
} | } | ||||
// Add module | // Add module | ||||
internal->modules.push_back(module); | internal->modules.push_back(module); | ||||
// Trigger Add event | |||||
module->onAdd(); | module->onAdd(); | ||||
// Update ParamHandles | // Update ParamHandles | ||||
for (ParamHandle *paramHandle : internal->paramHandles) { | for (ParamHandle *paramHandle : internal->paramHandles) { | ||||
@@ -507,6 +508,9 @@ void Engine::removeModule(Module *module) { | |||||
assert(module); | assert(module); | ||||
VIPLock vipLock(internal->vipMutex); | VIPLock vipLock(internal->vipMutex); | ||||
std::lock_guard<std::recursive_mutex> lock(internal->mutex); | std::lock_guard<std::recursive_mutex> 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 a param is being smoothed on this module, stop smoothing it immediately | ||||
if (module == internal->smoothModule) { | if (module == internal->smoothModule) { | ||||
internal->smoothModule = NULL; | internal->smoothModule = NULL; | ||||
@@ -532,11 +536,9 @@ void Engine::removeModule(Module *module) { | |||||
m->rightModule = NULL; | 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(); | module->onRemove(); | ||||
// Remove module | |||||
internal->modules.erase(it); | internal->modules.erase(it); | ||||
} | } | ||||