Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get expected sample rate from model for warning message #338

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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