Skip to content

Commit

Permalink
Refactor control updates that depend on a model. Fix model info in se…
Browse files Browse the repository at this point in the history
…ttings page (#527)
  • Loading branch information
sdatkinson authored Nov 17, 2024
1 parent 420f438 commit cc3d22b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
47 changes: 27 additions & 20 deletions NeuralAmpModeler/NeuralAmpModeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NAMSettingsPageControl*>(pGraphics->GetControlWithTag(kCtrlTagSettingsBox))->SetModelInfo(modelInfo);

const bool disableInputCalibrationControls = !mModel->HasInputLevel();
pGraphics->GetControlWithTag(kCtrlTagCalibrateInput)->SetDisabled(disableInputCalibrationControls);
pGraphics->GetControlWithTag(kCtrlTagInputCalibrationLevel)->SetDisabled(disableInputCalibrationControls);

_UpdateControlsFromModel();
mNewModelLoadedInDSP = false;
}
}
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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<NAMSettingsPageControl*>(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;
Expand Down
3 changes: 3 additions & 0 deletions NeuralAmpModeler/NeuralAmpModeler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit cc3d22b

Please sign in to comment.