NeuralAmpModelerPlugin

Plugin for Neural Amp Modeler
Log | Files | Refs | Submodules | README | LICENSE

commit 8011348d6e81303c10e1ed7da19c046a8a4f59af
parent 7ffbf3fb0415b9ab7e683032d5c93238515dd05d
Author: Steven Atkinson <steven@atkinson.mn>
Date:   Sat, 15 Jul 2023 12:02:23 -0700

Get expected sample rate from model for warning message (#338)

* Plugin listens to models for sample rate warning message

* Includes cleanup
Diffstat:
MNeuralAmpModeler/NeuralAmpModeler.cpp | 8++++++--
MNeuralAmpModeler/NeuralAmpModelerControls.h | 13++++++++++++-
2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/NeuralAmpModeler/NeuralAmpModeler.cpp b/NeuralAmpModeler/NeuralAmpModeler.cpp @@ -517,14 +517,18 @@ void NeuralAmpModeler::_CheckSampleRateWarning() { if (auto* pGraphics = GetUI()) { + auto* control = pGraphics->GetControlWithTag(kCtrlTagSampleRateWarning)->As<NAMSampleRateWarningControl>(); bool showWarning = false; if (_HaveModel()) { const auto pluginSampleRate = GetSampleRate(); - const double namSampleRate = 48000.0; // TODO from model + const auto namSampleRateFromModel = mModel->GetExpectedSampleRate(); + // Any model with "-1" is probably 48k + const auto namSampleRate = namSampleRateFromModel == -1.0 ? 48000.0 : namSampleRateFromModel; + control->SetSampleRate(namSampleRate); showWarning = pluginSampleRate != namSampleRate; } - pGraphics->GetControlWithTag(kCtrlTagSampleRateWarning)->SetDisabled(!showWarning); + control->SetDisabled(!showWarning); mCheckSampleRateWarning = false; } } diff --git a/NeuralAmpModeler/NeuralAmpModelerControls.h b/NeuralAmpModeler/NeuralAmpModelerControls.h @@ -1,5 +1,7 @@ #pragma once +#include <cmath> // std::round +#include <sstream> // std::stringstream #include "IControls.h" #define PLUG() static_cast<PLUG_CLASS_NAME*>(GetDelegate()) @@ -436,10 +438,11 @@ class NAMSampleRateWarningControl : public ITextControl { public: NAMSampleRateWarningControl(const IRECT& bounds) - : ITextControl(bounds, "WARNING: Run NAM at sample rate 48kHz!", _WARNING_TEXT) + : ITextControl(bounds, "", _WARNING_TEXT) { // Default to disabled so that we don't get a flash every time we open the UI. SetDisabled(true); + SetSampleRate(48000.0); } void SetDisabled(bool disable) override { @@ -449,6 +452,14 @@ public: SetDirty(false); } } + // Adjust what's displayed according to the provided smalpe rate. + // Assumes that the given value is valid. + void SetSampleRate(const double sampleRate) + { + std::stringstream ss; + ss << "WARNING: NAM model expects sample rate " << static_cast<long>(std::round(sampleRate)); + SetStr(ss.str().c_str()); + } protected: float mDisabledBlend = 0.0f; // when this is disabled, it's completely gone.