Skip to content

Commit

Permalink
Get expected sample rate from model for warning message (#338)
Browse files Browse the repository at this point in the history
* Plugin listens to models for sample rate warning message

* Includes cleanup
  • Loading branch information
sdatkinson authored Jul 15, 2023
1 parent 7ffbf3f commit 8011348
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 6 additions & 2 deletions NeuralAmpModeler/NeuralAmpModeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
13 changes: 12 additions & 1 deletion NeuralAmpModeler/NeuralAmpModelerControls.h
Original file line number Diff line number Diff line change
@@ -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())
Expand Down Expand Up @@ -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
{
Expand All @@ -449,6 +452,14 @@ class NAMSampleRateWarningControl : public ITextControl
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.
Expand Down

0 comments on commit 8011348

Please sign in to comment.