Skip to content
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
66 changes: 66 additions & 0 deletions NeuralAmpModeler/NeuralAmpModeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
GetParam(kCalibrateInput)->InitBool(kCalibrateInputParamName.c_str(), kDefaultCalibrateInput);
GetParam(kInputCalibrationLevel)
->InitDouble(kInputCalibrationLevelParamName.c_str(), kDefaultInputCalibrationLevel, -60.0, 60.0, 0.1, "dBu");
GetParam(kSlim)->InitDouble("Slim", 1.0, 0.0, 1.0, 0.01);

mNoiseGateTrigger.AddListener(&mNoiseGateGain);

Expand Down Expand Up @@ -126,6 +127,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
const auto modelIconSVG = pGraphics->LoadSVG(MODEL_ICON_FN);
const auto irIconOnSVG = pGraphics->LoadSVG(IR_ICON_ON_FN);
const auto irIconOffSVG = pGraphics->LoadSVG(IR_ICON_OFF_FN);
const auto slimIconSVG = pGraphics->LoadSVG(SLIMMABLE_ICON_FN);

const auto backgroundBitmap = pGraphics->LoadBitmap(BACKGROUND_FN);
const auto fileBackgroundBitmap = pGraphics->LoadBitmap(FILEBACKGROUND_FN);
Expand Down Expand Up @@ -166,6 +168,8 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
const auto irYOffset = 38.0f;
const auto modelArea =
contentArea.GetFromBottom((2.0f * fileHeight)).GetFromTop(fileHeight).GetMidHPadded(fileWidth).GetVShifted(-1);
const auto slimIconArea =
IRECT(modelArea.R + 6.f, modelArea.MH() - 14.f, modelArea.R + 6.f + 2.f * 28.f, modelArea.MH() + 14.f);
const auto modelIconArea = modelArea.GetFromLeft(30).GetTranslated(-40, 10);
const auto irArea = modelArea.GetVShifted(irYOffset);
const auto irSwitchArea = irArea.GetFromLeft(30.0f).GetHShifted(-40.0f).GetScaledAboutCentre(0.6f);
Expand Down Expand Up @@ -230,6 +234,30 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
loadModelCompletionHandler, style, fileSVG, crossSVG, leftArrowSVG, rightArrowSVG,
fileBackgroundBitmap, globeSVG, "Get NAM Models", getUrl),
kCtrlTagModelFileBrowser);

auto hideSlimOverlay = [](IControl* pCaller) {
IGraphics* ui = pCaller->GetUI();
if (auto* backdrop = ui->GetControlWithTag(kCtrlTagSlimOverlayBackdrop))
backdrop->Hide(true);
if (auto* knob = ui->GetControlWithTag(kCtrlTagSlimKnob))
knob->Hide(true);
ui->SetAllControlsDirty();
};
auto showSlimOverlay = [](IControl* pCaller) {
IGraphics* ui = pCaller->GetUI();
if (auto* backdrop = ui->GetControlWithTag(kCtrlTagSlimOverlayBackdrop))
backdrop->Hide(false);
if (auto* knob = ui->GetControlWithTag(kCtrlTagSlimKnob))
knob->Hide(false);
ui->SetAllControlsDirty();
};

pGraphics
->AttachControl(
new NAMSquareButtonControl(slimIconArea, DefaultClickActionFunc, slimIconSVG), kCtrlTagSlimmableIcon)
->SetAnimationEndActionFunction(showSlimOverlay)
->Hide(true);

pGraphics->AttachControl(new ISVGSwitchControl(irSwitchArea, {irIconOffSVG, irIconOnSVG}, kIRToggle));
pGraphics->AttachControl(
new NAMFileBrowserControl(irArea, kMsgTagClearIR, defaultIRString.c_str(), "wav", loadIRCompletionHandler, style,
Expand Down Expand Up @@ -269,6 +297,13 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
kCtrlTagSettingsBox)
->Hide(true);

const auto slimKnobArea = b.GetCentredInside(100.f, NAM_KNOB_HEIGHT + 24.f);
pGraphics->AttachControl(new NAMSlimOverlayBackdropControl(b, hideSlimOverlay), kCtrlTagSlimOverlayBackdrop)
->Hide(true);
pGraphics
->AttachControl(new NAMKnobControl(slimKnobArea, kSlim, "Slim", style, knobBackgroundBitmap), kCtrlTagSlimKnob)
->Hide(true);

pGraphics->ForAllControlsFunc([](IControl* pControl) {
pControl->SetMouseEventsWhenDisabled(true);
pControl->SetMouseOverWhenDisabled(true);
Expand Down Expand Up @@ -400,6 +435,13 @@ void NeuralAmpModeler::OnIdle()
// FIXME -- need to disable only the "normalized" model
// pGraphics->GetControlWithTag(kCtrlTagOutputMode)->SetDisabled(false);
static_cast<NAMSettingsPageControl*>(pGraphics->GetControlWithTag(kCtrlTagSettingsBox))->ClearModelInfo();
if (auto* p = pGraphics->GetControlWithTag(kCtrlTagSlimmableIcon))
p->Hide(true);
if (auto* p = pGraphics->GetControlWithTag(kCtrlTagSlimOverlayBackdrop))
p->Hide(true);
if (auto* p = pGraphics->GetControlWithTag(kCtrlTagSlimKnob))
p->Hide(true);
pGraphics->SetAllControlsDirty();
mModelCleared = false;
}
}
Expand Down Expand Up @@ -479,6 +521,7 @@ void NeuralAmpModeler::OnParamChange(int paramIdx)
case kToneBass: mToneStack->SetParam("bass", GetParam(paramIdx)->Value()); break;
case kToneMid: mToneStack->SetParam("middle", GetParam(paramIdx)->Value()); break;
case kToneTreble: mToneStack->SetParam("treble", GetParam(paramIdx)->Value()); break;
case kSlim: _ApplySlimParamToLoadedNAMs(); break;
default: break;
}
}
Expand Down Expand Up @@ -686,6 +729,19 @@ void NeuralAmpModeler::_SetOutputGain()
mOutputGain = DBToAmp(gainDB);
}

void NeuralAmpModeler::_ApplySlimParamToLoadedNAMs()
{
const double v = GetParam(kSlim)->Value();
auto apply = [v](ResamplingNAM* p) {
if (p == nullptr)
return;
if (nam::SlimmableModel* s = p->GetSlimmableModel())
s->SetSlimmableSize(v);
};
apply(mModel.get());
apply(mStagedModel.get());
}

std::string NeuralAmpModeler::_StageModel(const WDL_String& modelPath)
{
WDL_String previousNAMPath = mNAMPath;
Expand All @@ -707,6 +763,10 @@ std::string NeuralAmpModeler::_StageModel(const WDL_String& modelPath)

std::unique_ptr<ResamplingNAM> temp = std::make_unique<ResamplingNAM>(std::move(model), GetSampleRate());
temp->Reset(GetSampleRate(), GetBlockSize());
if (nam::SlimmableModel* slimmable = temp->GetSlimmableModel())
{
slimmable->SetSlimmableSize(GetParam(kSlim)->Value());
}
mStagedModel = std::move(temp);
mNAMPath = modelPath;
SendControlMsgFromDelegate(kCtrlTagModelFileBrowser, kMsgTagLoadedModel, mNAMPath.GetLength(), mNAMPath.Get());
Expand Down Expand Up @@ -895,6 +955,12 @@ void NeuralAmpModeler::_UpdateControlsFromModel()
c->SetNormalizedDisable(!mModel->HasLoudness());
c->SetCalibratedDisable(!mModel->HasOutputLevel());
}

if (auto* pSlimIcon = pGraphics->GetControlWithTag(kCtrlTagSlimmableIcon))
{
const bool show = mModel->GetSlimmableModel() != nullptr;
pSlimIcon->Hide(!show);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions NeuralAmpModeler/NeuralAmpModeler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../AudioDSPTools/dsp/wav.h"
#include "../AudioDSPTools/dsp/ResamplingContainer/ResamplingContainer.h"
#include "../NeuralAmpModelerCore/NAM/dsp.h"
#include "../NeuralAmpModelerCore/NAM/slimmable.h"

#include "Colors.h"
#include "ToneStack.h"
Expand Down Expand Up @@ -45,6 +46,7 @@ enum EParams
kCalibrateInput,
kInputCalibrationLevel,
kOutputMode,
kSlim,
kNumParams
};

Expand All @@ -60,6 +62,9 @@ enum ECtrlTags
kCtrlTagOutputMode,
kCtrlTagCalibrateInput,
kCtrlTagInputCalibrationLevel,
kCtrlTagSlimmableIcon,
kCtrlTagSlimOverlayBackdrop,
kCtrlTagSlimKnob,
kNumCtrlTags
};

Expand Down Expand Up @@ -167,6 +172,12 @@ class ResamplingNAM : public nam::DSP
// So that we can let the world know if we're resampling (useful for debugging)
double GetEncapsulatedSampleRate() const { return GetNAMSampleRate(mEncapsulated); };

nam::SlimmableModel* GetSlimmableModel() { return dynamic_cast<nam::SlimmableModel*>(mEncapsulated.get()); }
const nam::SlimmableModel* GetSlimmableModel() const
{
return dynamic_cast<const nam::SlimmableModel*>(mEncapsulated.get());
}

private:
bool NeedToResample() const { return GetExpectedSampleRate() != GetEncapsulatedSampleRate(); };
// The encapsulated NAM
Expand Down Expand Up @@ -244,6 +255,7 @@ class NeuralAmpModeler final : public iplug::Plugin

void _SetInputGain();
void _SetOutputGain();
void _ApplySlimParamToLoadedNAMs();

// See: Unserialization.cpp
void _UnserializeApplyConfig(nlohmann::json& config);
Expand Down
22 changes: 22 additions & 0 deletions NeuralAmpModeler/NeuralAmpModelerControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ class NAMCircleButtonControl : public ISVGButtonControl
}
};

/// Full-window dim layer; click dismisses (used for Slim overlay).
class NAMSlimOverlayBackdropControl : public IControl
{
public:
NAMSlimOverlayBackdropControl(const IRECT& bounds, IActionFunction dismiss)
: IControl(bounds, dismiss)
, mDismiss(dismiss)
{
}

void Draw(IGraphics& g) override { g.FillRect(COLOR_BLACK.WithOpacity(0.45f), mRECT); }

void OnMouseDown(float x, float y, const IMouseMod& mod) override
{
if (mDismiss)
mDismiss(this);
}

private:
IActionFunction mDismiss;
};

class NAMKnobControl : public IVKnobControl, public IBitmapBase
{
public:
Expand Down
37 changes: 35 additions & 2 deletions NeuralAmpModeler/Unserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,40 @@ void _RenameKeys(nlohmann::json& j, std::unordered_map<std::string, std::string>
}
}

// v0.7.14

void _UpdateConfigFrom_0_7_14(nlohmann::json& config)
{
// Fill me in once something changes!
}

int _GetConfigFrom_0_7_14(const iplug::IByteChunk& chunk, int startPos, nlohmann::json& config)
{
std::vector<std::string> paramNames{"Input",
"Threshold",
"Bass",
"Middle",
"Treble",
"Output",
"NoiseGateActive",
"ToneStack",
"IRToggle",
"CalibrateInput",
"InputCalibrationLevel",
"OutputMode",
"Slim"};

int pos = _UnserializePathsAndExpectedKeys(chunk, startPos, config, paramNames);
_UpdateConfigFrom_0_7_14(config);
return pos;
}

// v0.7.12

void _UpdateConfigFrom_0_7_12(nlohmann::json& config)
{
// Fill me in once something changes!
config["Slim"] = 1.0;
_UpdateConfigFrom_0_7_14(config);
}

int _GetConfigFrom_0_7_12(const iplug::IByteChunk& chunk, int startPos, nlohmann::json& config)
Expand Down Expand Up @@ -248,7 +277,11 @@ int NeuralAmpModeler::_UnserializeStateWithKnownVersion(const iplug::IByteChunk&
_Version version(versionStr);
// Act accordingly
nlohmann::json config;
if (version >= _Version(0, 7, 12))
if (version >= _Version(0, 7, 14))
{
pos = _GetConfigFrom_0_7_14(chunk, pos, config);
}
else if (version >= _Version(0, 7, 12))
{
pos = _GetConfigFrom_0_7_12(chunk, pos, config);
}
Expand Down
1 change: 1 addition & 0 deletions NeuralAmpModeler/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#define IR_ICON_ON_FN "IRIconOn.svg"
#define IR_ICON_OFF_FN "IRIconOff.svg"
#define GLOBE_ICON_FN "Globe.svg"
#define SLIMMABLE_ICON_FN "SlimmableIcon.svg"

#define BACKGROUND_FN "Background.jpg"
#define BACKGROUND2X_FN "Background@2x.jpg"
Expand Down
Loading
Loading