commit 9c968896020d98af4a7a11ecf2a47e805164d708
parent 3a5a9efb187fe10c3861db71c2acafa5c9c7895e
Author: Steven Atkinson <steven@atkinson.mn>
Date: Fri, 16 Dec 2022 19:26:00 -0800
Fix initialization issues
Display restores to the correct state when UI is re-opened (Issue 3)
Model re-loads when the session re-initializes (Issue 4)
Diffstat:
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/NeuralAmpModeler/NeuralAmpModeler.cpp b/NeuralAmpModeler/NeuralAmpModeler.cpp
@@ -116,6 +116,8 @@ public:
NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPresets))
{
+ this->mDSP = NULL;
+ this->mStagedDSP = NULL;
GetParam(kInputGain)->InitGain("Input", 0.0, -20.0, 20.0, 0.1);
GetParam(kOutputGain)->InitGain("Output", 0.0, -20.0, 20.0, 0.1);
@@ -289,10 +291,7 @@ void NeuralAmpModeler::GetDSP(const WDL_String& modelPath)
previousModelPath = mModelPath;
auto dspPath = std::filesystem::path(modelPath.Get());
mStagedDSP = get_dsp(dspPath);
- mModelPath = modelPath;
- std::stringstream ss;
- ss << "Loaded " << dspPath.parent_path().filename();
- SendControlMsgFromDelegate(kCtrlTagModelName, 0, int(strlen(ss.str().c_str())), ss.str().c_str());
+ this->_SetModelMsg(modelPath);
}
catch (std::exception& e) {
std::stringstream ss;
@@ -307,6 +306,15 @@ void NeuralAmpModeler::GetDSP(const WDL_String& modelPath)
}
}
+void NeuralAmpModeler::_SetModelMsg(const WDL_String& modelPath)
+{
+ auto dspPath = std::filesystem::path(modelPath.Get());
+ mModelPath = modelPath;
+ std::stringstream ss;
+ ss << "Loaded " << dspPath.parent_path().filename();
+ SendControlMsgFromDelegate(kCtrlTagModelName, 0, int(strlen(ss.str().c_str())), ss.str().c_str());
+}
+
bool NeuralAmpModeler::SerializeState(IByteChunk& chunk) const
{
// Model directory (don't serialize the model itself; we'll just load it again when we unserialize)
@@ -321,3 +329,15 @@ int NeuralAmpModeler::UnserializeState(const IByteChunk& chunk, int startPos)
mDSP = nullptr;
return UnserializeParams(chunk, startPos);
}
+
+void NeuralAmpModeler::OnUIOpen()
+{
+ Plugin::OnUIOpen();
+ if (!this->_HaveModel()) {
+ if (this->mModelPath.GetLength())
+ this->GetDSP(this->mModelPath);
+ this->GetUI()->SetAllControlsDirty();
+ }
+ else if (this->mModelPath.GetLength())
+ this->_SetModelMsg(this->mModelPath);
+}
+\ No newline at end of file
diff --git a/NeuralAmpModeler/NeuralAmpModeler.h b/NeuralAmpModeler/NeuralAmpModeler.h
@@ -35,9 +35,14 @@ public:
bool SerializeState(IByteChunk& chunk) const override;
int UnserializeState(const IByteChunk& chunk, int startPos) override;
+ void OnUIOpen() override;
private:
void GetDSP(const WDL_String& dspPath);
+ void _SetModelMsg(const WDL_String& dspPath);
+ bool _HaveModel() const {
+ return this->mDSP == NULL;
+ };
// The DSP actually being used:
std::unique_ptr<DSP> mDSP;
// Manages switching what DSP is being used.