Hi,
I’m stuck!
I’m using a AudioProcessorValueTreeState for all my audio parameters and everything is working as expected with my sliders, combo boxes, Buttons, … with their respective attachments.
However I also need to store the plug-in window size and want to recall it with plug-in presets.
Storing the window width and height is working, but when recalling a preset the editor doesn’t get refreshed automatically, I have to close and reopen the window to have the window resized correctly.
I tried adding a AudioProcessorValueTreeState::Listener (which isn’t working at all) and also repaint() from AudioProcessor::setStateInformation which is working but also throwing JUCE assertions to the console.
JUCE Assertion failure in juce_Component.cpp:1839
JUCE Assertion failure in juce_Component.cpp:1068
2020-02-08 15:10:04.828033+0100 Pro Tools[38342:1143196] -[DFW_NSPanel displayIfNeeded:]: unrecognized selector sent to instance 0x600000423000
2020-02-08 15:10:04.828229+0100 Pro Tools[38342:1143196] [General] -[DFW_NSPanel displayIfNeeded:]: unrecognized selector sent to instance 0x600000423000
That doesn’t seem to be thread safe and therefore a really bad idea.
This is what I have so far:
AudioProcessor.h
// ...
private:
AudioProcessorValueTreeState parameters {*this, nullptr, Identifier("Parameters"), {
std::make_unique<AudioParameterInt>("windowWidth", "Window Width", 100, 1800, 460),
std::make_unique<AudioParameterInt>("windowHeight", "Window Height", 100, 1800, 460)
}};
AudioProcessor.cpp
void AudioProcessor::getStateInformation (MemoryBlock& destData)
{
auto state = parameters.copyState();
auto xml(state.createXml());
copyXmlToBinary(*xml, destData);
}
void AudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
auto xmlState(getXmlFromBinary(data, sizeInBytes));
if (xmlState.get() != nullptr && xmlState->hasTagName("Parameters")) parameters.replaceState(ValueTree::fromXml(*xmlState));
int w = parameters.state.getProperty("windowWidth", 460);
int h = parameters.state.getProperty("windowHeight", 460);
// this would work but also throwing a lot of JUCE Assertion failures
// if (auto editor = getActiveEditor()) {
// editor->setSize(w, h);
// editor->repaint();
// }
}
AudioProcessorEditor.h
public:
//...
virtual void parameterChanged (const String& parameterID, float newValue) override;
private:
ValueTreePlugInTestAudioProcessor& processor;
AudioProcessorValueTreeState& processorVts;
Rectangle<int> windowRect {460, 460};
and finally AudioProcessorEditor.cpp
AudioProcessorEditor::AudioProcessorEditor (ValueTreePlugInTestAudioProcessor& p, AudioProcessorValueTreeState& vts)
: AudioProcessorEditor (&p), processor (p), processorVts(vts)
{
processorVts.addParameterListener("windowWidth", this);
processorVts.addParameterListener("windowHeight", this);
setResizable(true, true);
setSize(processorVts.state.getProperty("windowWidth", 460), processorVts.state.getProperty("windowHeight", 460));
}
AudioProcessorEditor::~AudioProcessorEditor()
{
processorVts.removeParameterListener("windowWidth", this);
processorVts.removeParameterListener("windowHeight", this);
}
void ValueTreePlugInTestAudioProcessorEditor::resized()
{
processorVts.state.setProperty("windowWidth", getWidth(), nullptr);
processorVts.state.setProperty("windowHeight", getHeight(), nullptr);
}
// this won't ever get called
void ValueTreePlugInTestAudioProcessorEditor::parameterChanged (const String& parameterID, float newValue) {
if (parameterID == "windowWidth") {
windowRect.setWidth(newValue);
setSize(windowRect.getWidth(), windowRect.getHeight());
}
else if (parameterID == "windowHeight") {
windowRect.setHeight(newValue);
setSize(windowRect.getWidth(), windowRect.getHeight());
}
}
What am I doing wrong?
I’m sure the solution is very simple, but I’m running in circle for days now and don’t have a clue where to find a solution.
Thanks in advance.
Stefan