From b0b720bc3cde418383cc5601c27818dbe3ec5e43 Mon Sep 17 00:00:00 2001 From: Mike Oliphant Date: Sat, 18 Jul 2026 16:30:20 -0700 Subject: [PATCH] Fix race condition when setting the quality scale while loading a model --- src/nam_plugin.cpp | 23 +++++++++++------------ src/nam_plugin.h | 1 - 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index aa3f769..dae47de 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -222,6 +222,12 @@ namespace NAM { lv2_atom_forge_set_buffer(&atom_forge, (uint8_t*)ports.notify, ports.notify->atom.size); lv2_atom_forge_sequence_head(&atom_forge, &sequence_frame, uris.units_frame); + if (*(ports.quality_scale) != loader.GetDefaultQualityScaleFactor()) + { + // Do this before checking the model path parameter so we make sure to set the quality first + loader.SetDefaultQualityScaleFactor(*(ports.quality_scale)); + } + LV2_ATOM_SEQUENCE_FOREACH(ports.control, event) { if (event->body.type == uris.atom_Object) @@ -254,24 +260,17 @@ namespace NAM { } } - if (*(ports.quality_scale) != qualityScale) - { - qualityScale = *(ports.quality_scale); - - loader.SetDefaultQualityScaleFactor(qualityScale); - - if (currentModel != nullptr) - { - currentModel->SetQualityScaleFactor(qualityScale); - } - } - float level; float modelInputAdjustmentDB = 0; if (currentModel != nullptr) { + if (*(ports.quality_scale) != currentModel->GetQualityScaleFactor()) + { + currentModel->SetQualityScaleFactor(*(ports.quality_scale)); + } + modelInputAdjustmentDB = currentModel->GetRecommendedInputDBAdjustment(); #ifdef SMART_BYPASS_ENABLED diff --git a/src/nam_plugin.h b/src/nam_plugin.h index 9a8a9ca..318819e 100644 --- a/src/nam_plugin.h +++ b/src/nam_plugin.h @@ -76,7 +76,6 @@ namespace NAM { std::string currentModelPath; float prevDCInput = 0; float prevDCOutput = 0; - float qualityScale = 1.0f; Plugin(); ~Plugin();