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

[FEATURE] Display model sample rate on settings page #522

Merged
merged 7 commits into from
Nov 8, 2024
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
24 changes: 20 additions & 4 deletions NeuralAmpModeler/NeuralAmpModeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
const auto outputMeterArea = contentArea.GetFromRight(30).GetHShifted(20).GetMidVPadded(100).GetVShifted(-25);

// Misc Areas
const auto settingsButtonArea = mainArea.GetFromTRHC(50, 50).GetCentredInside(20, 20);
const auto settingsButtonArea = CornerButtonArea(b);

// Model loader button
auto loadModelCompletionHandler = [&](const WDL_String& fileName, const WDL_String& path) {
Expand Down Expand Up @@ -250,7 +250,8 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
},
gearSVG));

pGraphics->AttachControl(new NAMSettingsPageControl(b, backgroundBitmap, style), kCtrlTagSettingsBox)->Hide(true);
pGraphics->AttachControl(new NAMSettingsPageControl(b, backgroundBitmap, crossSVG, style), kCtrlTagSettingsBox)
->Hide(true);

pGraphics->ForAllControlsFunc([](IControl* pControl) {
pControl->SetMouseEventsWhenDisabled(true);
Expand Down Expand Up @@ -377,9 +378,23 @@ void NeuralAmpModeler::OnIdle()
if (mNewModelLoadedInDSP)
{
if (auto* pGraphics = GetUI())
{
pGraphics->GetControlWithTag(kCtrlTagOutNorm)->SetDisabled(!mModel->HasLoudness());

mNewModelLoadedInDSP = false;
ModelInfo modelInfo;
modelInfo.sampleRate = mModel->GetEncapsulatedSampleRate();
modelInfo.knownSampleRate = true;
static_cast<NAMSettingsPageControl*>(pGraphics->GetControlWithTag(kCtrlTagSettingsBox))->SetModelInfo(modelInfo);
mNewModelLoadedInDSP = false;
}
}
if (mModelCleared)
{
if (auto* pGraphics = GetUI())
{
pGraphics->GetControlWithTag(kCtrlTagOutNorm)->SetDisabled(false);
static_cast<NAMSettingsPageControl*>(pGraphics->GetControlWithTag(kCtrlTagSettingsBox))->ClearModelInfo();
mModelCleared = false;
}
}
}

Expand Down Expand Up @@ -534,6 +549,7 @@ void NeuralAmpModeler::_ApplyDSPStaging()
mModel = nullptr;
mNAMPath.Set("");
mShouldRemoveModel = false;
mModelCleared = true;
_UpdateLatency();
}
if (mShouldRemoveIR)
Expand Down
1 change: 1 addition & 0 deletions NeuralAmpModeler/NeuralAmpModeler.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class NeuralAmpModeler final : public iplug::Plugin
std::atomic<bool> mShouldRemoveIR = false;

std::atomic<bool> mNewModelLoadedInDSP = false;
std::atomic<bool> mModelCleared = false;

// Tone stack modules
std::unique_ptr<dsp::tone_stack::AbstractToneStack> mToneStack;
Expand Down
101 changes: 97 additions & 4 deletions NeuralAmpModeler/NeuralAmpModelerControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
using namespace iplug;
using namespace igraphics;

// Where the corner button on the plugin (settings, close settings) goes
// :param rect: Rect for the whole plugin's UI
IRECT CornerButtonArea(const IRECT& rect)
{
const auto mainArea = rect.GetPadded(-20);
return mainArea.GetFromTRHC(50, 50).GetCentredInside(20, 20);
};

class NAMSquareButtonControl : public ISVGButtonControl
{
public:
Expand Down Expand Up @@ -449,7 +457,7 @@ class IContainerBaseWithNamedChildren : public IContainerBase
{
// Make sure we haven't already used this name
assert(mChildNameIndexMap.find(name) == mChildNameIndexMap.end());
mChildNameIndexMap[name] = (int)mChildNameIndexMap.size();
mChildNameIndexMap[name] = NChildren();
return AddChildControl(control);
};

Expand All @@ -464,18 +472,86 @@ class IContainerBaseWithNamedChildren : public IContainerBase
std::unordered_map<std::string, int> mChildNameIndexMap;
}; // class IContainerBaseWithNamedChildren

struct ModelInfo
{
bool knownSampleRate = false;
double sampleRate = 0.0;
};

class ModelInfoControl : public IContainerBaseWithNamedChildren
{
public:
ModelInfoControl(const IRECT& bounds, const IVStyle& style)
: IContainerBaseWithNamedChildren(bounds)
, mStyle(style) {};

void ClearModelInfo()
{
static_cast<IVLabelControl*>(GetNamedChild(mControlNames.sampleRate))->SetStr("");
mHasInfo = false;
};

void Hide(bool hide) override
{
// Don't show me unless I have info to show!
IContainerBase::Hide(hide || (!mHasInfo));
};

void OnAttached() override
{
AddChildControl(new IVLabelControl(GetRECT().GetGridCell(0, 0, 2, 1), "Model information:", mStyle));
AddNamedChildControl(new IVLabelControl(GetRECT().GetGridCell(1, 0, 2, 1), "", mStyle), mControlNames.sampleRate);
};

// Click through me
void OnMouseDown(float x, float y, const IMouseMod& mod) override { GetParent()->OnMouseDown(x, y, mod); }

void SetModelInfo(const ModelInfo& modelInfo)
{
std::stringstream ss;
ss << "Sample rate: ";
if (modelInfo.knownSampleRate)
{
ss << (int)modelInfo.sampleRate;
}
else
{
ss << "(Unknown)";
}
static_cast<IVLabelControl*>(GetNamedChild(mControlNames.sampleRate))->SetStr(ss.str().c_str());
mHasInfo = true;
};

private:
const IVStyle mStyle;
struct
{
const std::string sampleRate = "sampleRate";
} mControlNames;
// Do I have info?
bool mHasInfo = false;
};

class NAMSettingsPageControl : public IContainerBaseWithNamedChildren
{
public:
NAMSettingsPageControl(const IRECT& bounds, const IBitmap& bitmap, const IVStyle& style)
NAMSettingsPageControl(const IRECT& bounds, const IBitmap& bitmap, ISVG closeSVG, const IVStyle& style)
: IContainerBaseWithNamedChildren(bounds)
, mAnimationTime(0)
, mBitmap(bitmap)
, mStyle(style)
, mCloseSVG(closeSVG)
{
mIgnoreMouse = false;
}

void ClearModelInfo()
{
auto* modelInfoControl = static_cast<ModelInfoControl*>(GetNamedChild(mControlNames.modelInfo));
assert(modelInfoControl != nullptr);
modelInfoControl->ClearModelInfo();
}

bool OnKeyDown(float x, float y, const IKeyPress& key) override
{
if (key.VK == kVK_ESCAPE)
Expand All @@ -487,8 +563,6 @@ class NAMSettingsPageControl : public IContainerBaseWithNamedChildren
return false;
}

void OnMouseDown(float x, float y, const IMouseMod& mod) override { HideAnimated(true); }

void HideAnimated(bool hide)
{
mWillHide = hide;
Expand Down Expand Up @@ -564,6 +638,16 @@ class NAMSettingsPageControl : public IContainerBaseWithNamedChildren
//
// }, mStyle, IVColorSwatchControl::ECellLayout::kHorizontal, {kFG}, {""}));

AddNamedChildControl(new ModelInfoControl(GetRECT().GetPadded(-20.0f).GetFromBottom(75.0f).GetFromTop(30.0f),
style.WithValueText(style.valueText.WithAlign(EAlign::Near))),
mControlNames.modelInfo);

auto closeAction = [&](IControl* pCaller) {
static_cast<NAMSettingsPageControl*>(pCaller->GetParent())->HideAnimated(true);
};
AddNamedChildControl(
new NAMSquareButtonControl(CornerButtonArea(GetRECT()), closeAction, mCloseSVG), mControlNames.close);

OnResize();
}

Expand All @@ -587,10 +671,17 @@ class NAMSettingsPageControl : public IContainerBaseWithNamedChildren
}
}

void SetModelInfo(const ModelInfo& modelInfo)
{
auto* modelInfoControl = static_cast<ModelInfoControl*>(GetNamedChild(mControlNames.modelInfo));
assert(modelInfoControl != nullptr);
modelInfoControl->SetModelInfo(modelInfo);
};

private:
IBitmap mBitmap;
IVStyle mStyle;
ISVG mCloseSVG;
int mAnimationTime = 200;
bool mWillHide = false;

Expand All @@ -601,7 +692,9 @@ class NAMSettingsPageControl : public IContainerBaseWithNamedChildren
const std::string bitmap = "bitmap";
const std::string byAuthor = "by author";
const std::string buildInfo = "build info";
const std::string close = "close";
const std::string development = "development";
const std::string modelInfo = "model info";
const std::string title = "title";
const std::string website = "website";
} mControlNames;
Expand Down
2 changes: 1 addition & 1 deletion NeuralAmpModeler/ToneStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BasicNamToneStack : public AbstractToneStack
DSP_SAMPLE** Process(DSP_SAMPLE** inputs, const int numChannels, const int numFrames);
virtual void Reset(const double sampleRate, const int maxBlockSize) override;
// :param val: Assumed to be between 0 and 10, 5 is "noon"
void SetParam(const std::string name, const double val);
virtual void SetParam(const std::string name, const double val) override;


protected:
Expand Down
Loading