ncblair / NTHN_TEMPLATE_PLUGIN

a starting point for real-time safe JUCE plugins
MIT License
76 stars 2 forks source link

StateManager: Only one parameter updating when using load_preset #2

Open JamesWenlock opened 11 months ago

JamesWenlock commented 11 months ago

Hey! Using the template to build a preset manager and when attempting to load presets, the UI only updates one parameter. Should have time this week to debug.

ncblair commented 11 months ago

Have you copied this pattern for each of your UI elements?

ncblair commented 11 months ago

The code should end up looking something like this

void AudioPluginAudioProcessorEditor::timerCallback() {
    ...

    // handle parameter values in the UI (repaint relevant components)
    if (state->any_parameter_changed.exchange(false)) {
        if (state->get_parameter_modified(PARAM::GAIN)) {
            gain_slider->repaint();
        }
        if (state->get_parameter_modified(PARAM::PARAM2)) {
            parameter_2_slider->repaint();
        }
    }
    ...`
}
JamesWenlock commented 11 months ago

At the moment I'm repainting all of the sliders upon any parameter change so I don't think it's an issue on the UI side. I have some time tonight to do some digging. I'll let you know what I find.

JamesWenlock commented 11 months ago
Screen Shot 2023-08-23 at 6 24 26 PM

Confirmed, save_preset is only saving the gain parameter. I'll let you know when I have a fix.

ncblair commented 10 months ago

@JamesWenlock Have you resolved this? Is the issue that save_preset didn't register your other parameters, so load_preset also didn't update the other parameters?

save_preset should just get param info from get_state(), so it's weird that would be missing anything. Maybe it was a plugin version issue?

JamesWenlock commented 10 months ago

Not sure! My current hacky fix is to build a new ValueTree in the get_state method rather than copying from the APVST.

juce::ValueTree StateManager::get_state() {
    state_tree = juce::ValueTree(STATE_ID);
    juce::ValueTree paramTree (PARAMETERS_ID);
    for (auto p_id = 0; p_id < TOTAL_NUMBER_PARAMETERS; ++p_id)
    {
        juce::ValueTree thisParam (PARAMETER_HEADER);
        thisParam.setProperty(ID, PARAMETER_IDS[p_id].toString(), nullptr);
        thisParam.setProperty(VALUE, param_value(p_id), nullptr);
        paramTree.addChild(thisParam, p_id, nullptr);
    }
    state_tree.appendChild(paramTree, nullptr);
    state_tree.appendChild(property_tree.createCopy(), nullptr);
    state_tree.appendChild(preset_tree.createCopy(), nullptr);
    return state_tree;
}

Not sure why the other parameters aren't showing up when copying the state of the APVTS, especially considering they're showing up in Reaper.