commit 824df5c121c602682dbb67071fe334a36453e8a8
parent cb0132011598d5597fc56fd7218795bfc725bbc9
Author: Steven Atkinson <[email protected]>
Date: Wed, 12 Jul 2023 12:57:04 -0700
Display a warning if host sample rate isn't correct for the NAM model (#331)
* Put in sample rate warning control (always on right now)
* Adjust wording
* Toggle disable state based on sample rate and model (hard-coded for now to 48k)
* Remove warning if there's no model loaded
* Check when UI open
Diffstat:
3 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/NeuralAmpModeler/NeuralAmpModeler.cpp b/NeuralAmpModeler/NeuralAmpModeler.cpp
@@ -148,6 +148,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
// Misc Areas
const auto helpButtonArea = mainArea.GetFromTRHC(50, 50).GetCentredInside(20, 20);
+ const auto sampleRateWarningArea = inputMeterArea.GetFromBottom(16.f).GetTranslated(12.f, 16.f).GetFromLeft(300.f);
// Model loader button
auto loadModelCompletionHandler = [&](const WDL_String& fileName, const WDL_String& path) {
@@ -224,6 +225,9 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
pGraphics->AttachControl(new NAMMeterControl(inputMeterArea, meterBackgroundBitmap, style), kCtrlTagInputMeter);
pGraphics->AttachControl(new NAMMeterControl(outputMeterArea, meterBackgroundBitmap, style), kCtrlTagOutputMeter);
+ // A warning when NAM isn't being run in the right sample rate:
+ pGraphics->AttachControl(new NAMSampleRateWarningControl(sampleRateWarningArea), kCtrlTagSampleRateWarning);
+
// Help/about box
pGraphics->AttachControl(new NAMCircleButtonControl(
helpButtonArea,
@@ -355,6 +359,7 @@ void NeuralAmpModeler::OnReset()
const auto sampleRate = GetSampleRate();
mInputSender.Reset(sampleRate);
mOutputSender.Reset(sampleRate);
+ mCheckSampleRateWarning = true;
}
void NeuralAmpModeler::OnIdle()
@@ -369,6 +374,10 @@ void NeuralAmpModeler::OnIdle()
mNewModelLoadedInDSP = false;
}
+ if (mCheckSampleRateWarning)
+ {
+ _CheckSampleRateWarning();
+ }
}
bool NeuralAmpModeler::SerializeState(IByteChunk& chunk) const
@@ -403,6 +412,7 @@ void NeuralAmpModeler::OnUIOpen()
SendControlMsgFromDelegate(kCtrlTagIRFileBrowser, kMsgTagLoadedIR, mIRPath.GetLength(), mIRPath.Get());
if (mModel != nullptr)
GetUI()->GetControlWithTag(kCtrlTagOutNorm)->SetDisabled(!mModel->HasLoudness());
+ mCheckSampleRateWarning = true;
}
void NeuralAmpModeler::OnParamChangeUI(int paramIdx, EParamSource source)
@@ -480,6 +490,7 @@ void NeuralAmpModeler::_ApplyDSPStaging()
mModel = std::move(mStagedModel);
mStagedModel = nullptr;
mNewModelLoadedInDSP = true;
+ mCheckSampleRateWarning = true;
}
if (mStagedIR != nullptr)
{
@@ -492,6 +503,7 @@ void NeuralAmpModeler::_ApplyDSPStaging()
mModel = nullptr;
mNAMPath.Set("");
mShouldRemoveModel = false;
+ mCheckSampleRateWarning = true;
}
if (mShouldRemoveIR)
{
@@ -501,6 +513,22 @@ void NeuralAmpModeler::_ApplyDSPStaging()
}
}
+void NeuralAmpModeler::_CheckSampleRateWarning()
+{
+ if (auto* pGraphics = GetUI())
+ {
+ bool showWarning = false;
+ if (_HaveModel())
+ {
+ const auto pluginSampleRate = GetSampleRate();
+ const double namSampleRate = 48000.0; // TODO from model
+ showWarning = pluginSampleRate != namSampleRate;
+ }
+ pGraphics->GetControlWithTag(kCtrlTagSampleRateWarning)->SetDisabled(!showWarning);
+ mCheckSampleRateWarning = false;
+ }
+}
+
void NeuralAmpModeler::_DeallocateIOPointers()
{
if (mInputPointers != nullptr)
diff --git a/NeuralAmpModeler/NeuralAmpModeler.h b/NeuralAmpModeler/NeuralAmpModeler.h
@@ -51,6 +51,7 @@ enum ECtrlTags
kCtrlTagOutputMeter,
kCtrlTagAboutBox,
kCtrlTagOutNorm,
+ kCtrlTagSampleRateWarning,
kNumCtrlTags
};
@@ -94,6 +95,9 @@ private:
// partially-instantiated.
void _ApplyDSPStaging();
// Deallocates mInputPointers and mOutputPointers
+ // Check whether the sample rate is correct for the NAM model.
+ // Adjust the warning control accordingly.
+ void _CheckSampleRateWarning();
void _DeallocateIOPointers();
// Fallback that just copies inputs to outputs if mDSP doesn't hold a model.
void _FallbackDSP(iplug::sample** inputs, iplug::sample** outputs, const size_t numChannels, const size_t numFrames);
@@ -154,6 +158,8 @@ private:
std::atomic<bool> mShouldRemoveIR = false;
std::atomic<bool> mNewModelLoadedInDSP = false;
+ // Flag to check whether the playback sample rate is correct for the model being used.
+ std::atomic<bool> mCheckSampleRateWarning = true;
// Tone stack modules
recursive_linear_filter::LowShelf mToneBass;
diff --git a/NeuralAmpModeler/NeuralAmpModelerControls.h b/NeuralAmpModeler/NeuralAmpModelerControls.h
@@ -430,6 +430,29 @@ public:
}
};
+const IText _WARNING_TEXT(DEFAULT_TEXT_SIZE + 3.f, COLOR_RED, "Roboto-Regular", EAlign::Near);
+
+class NAMSampleRateWarningControl : public ITextControl
+{
+public:
+ NAMSampleRateWarningControl(const IRECT& bounds)
+ : ITextControl(bounds, "WARNING: Run NAM at sample rate 48kHz!", _WARNING_TEXT)
+ {
+ }
+ void SetDisabled(bool disable) override
+ {
+ {
+ mBlend.mWeight = (disable ? mDisabledBlend : mEnabledBlend);
+ mDisabled = disable;
+ SetDirty(false);
+ }
+ }
+
+protected:
+ float mDisabledBlend = 0.0f; // when this is disabled, it's completely gone.
+ float mEnabledBlend = 1.0f; // Like normal
+};
+
class NAMAboutBoxControl : public IContainerBase
{
public: