From f0f4401e5b60f74c0a70af075c06f2bd60c850c7 Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Sat, 16 Nov 2024 17:36:01 -0800 Subject: [PATCH] Refactor control updates that depend on a model. Fix model info in settings page --- NeuralAmpModeler/NeuralAmpModeler.cpp | 47 +++++++++++++++------------ NeuralAmpModeler/NeuralAmpModeler.h | 3 ++ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/NeuralAmpModeler/NeuralAmpModeler.cpp b/NeuralAmpModeler/NeuralAmpModeler.cpp index b2922ad9..77cd3639 100644 --- a/NeuralAmpModeler/NeuralAmpModeler.cpp +++ b/NeuralAmpModeler/NeuralAmpModeler.cpp @@ -387,20 +387,7 @@ void NeuralAmpModeler::OnIdle() if (auto* pGraphics = GetUI()) { pGraphics->GetControlWithTag(kCtrlTagOutNorm)->SetDisabled(!mModel->HasLoudness()); - ModelInfo modelInfo; - modelInfo.sampleRate.known = true; - modelInfo.sampleRate.value = mModel->GetEncapsulatedSampleRate(); - modelInfo.inputCalibrationLevel.known = mModel->HasInputLevel(); - modelInfo.inputCalibrationLevel.value = mModel->HasInputLevel() ? mModel->GetInputLevel() : 0.0; - modelInfo.outputCalibrationLevel.known = mModel->HasOutputLevel(); - modelInfo.outputCalibrationLevel.value = mModel->HasOutputLevel() ? mModel->GetOutputLevel() : 0.0; - - static_cast(pGraphics->GetControlWithTag(kCtrlTagSettingsBox))->SetModelInfo(modelInfo); - - const bool disableInputCalibrationControls = !mModel->HasInputLevel(); - pGraphics->GetControlWithTag(kCtrlTagCalibrateInput)->SetDisabled(disableInputCalibrationControls); - pGraphics->GetControlWithTag(kCtrlTagInputCalibrationLevel)->SetDisabled(disableInputCalibrationControls); - + _UpdateControlsFromModel(); mNewModelLoadedInDSP = false; } } @@ -479,12 +466,7 @@ void NeuralAmpModeler::OnUIOpen() if (mModel != nullptr) { - auto* pGraphics = GetUI(); - assert(pGraphics != nullptr); - pGraphics->GetControlWithTag(kCtrlTagOutNorm)->SetDisabled(!mModel->HasLoudness()); - const bool disableInputCalibrationControls = !mModel->HasInputLevel(); - pGraphics->GetControlWithTag(kCtrlTagCalibrateInput)->SetDisabled(disableInputCalibrationControls); - pGraphics->GetControlWithTag(kCtrlTagInputCalibrationLevel)->SetDisabled(disableInputCalibrationControls); + _UpdateControlsFromModel(); } } @@ -939,6 +921,31 @@ int NeuralAmpModeler::_UnserializeStateLegacy_0_7_9(const IByteChunk& chunk, int return pos; } +void NeuralAmpModeler::_UpdateControlsFromModel() +{ + if (mModel == nullptr) + { + return; + } + if (auto* pGraphics = GetUI()) + { + ModelInfo modelInfo; + modelInfo.sampleRate.known = true; + modelInfo.sampleRate.value = mModel->GetEncapsulatedSampleRate(); + modelInfo.inputCalibrationLevel.known = mModel->HasInputLevel(); + modelInfo.inputCalibrationLevel.value = mModel->HasInputLevel() ? mModel->GetInputLevel() : 0.0; + modelInfo.outputCalibrationLevel.known = mModel->HasOutputLevel(); + modelInfo.outputCalibrationLevel.value = mModel->HasOutputLevel() ? mModel->GetOutputLevel() : 0.0; + + static_cast(pGraphics->GetControlWithTag(kCtrlTagSettingsBox))->SetModelInfo(modelInfo); + + const bool disableInputCalibrationControls = !mModel->HasInputLevel(); + pGraphics->GetControlWithTag(kCtrlTagOutNorm)->SetDisabled(!mModel->HasLoudness()); + pGraphics->GetControlWithTag(kCtrlTagCalibrateInput)->SetDisabled(disableInputCalibrationControls); + pGraphics->GetControlWithTag(kCtrlTagInputCalibrationLevel)->SetDisabled(disableInputCalibrationControls); + } +} + void NeuralAmpModeler::_UpdateLatency() { int latency = 0; diff --git a/NeuralAmpModeler/NeuralAmpModeler.h b/NeuralAmpModeler/NeuralAmpModeler.h index 3179f026..03e10791 100644 --- a/NeuralAmpModeler/NeuralAmpModeler.h +++ b/NeuralAmpModeler/NeuralAmpModeler.h @@ -251,6 +251,9 @@ class NeuralAmpModeler final : public iplug::Plugin int _UnserializeStateLegacy_0_7_9(const iplug::IByteChunk& chunk, int startPos); // And other legacy unsrializations if/as needed... + // Update all controls that depend on a model + void _UpdateControlsFromModel(); + // Make sure that the latency is reported correctly. void _UpdateLatency();