iPlug2 / iPlug2

C++ Audio Plug-in Framework for desktop, mobile and web
https://iplug2.github.io
Other
1.9k stars 282 forks source link

Beat-sync toggle switch state is not correctly recalled in IPlugInstrument example #998

Closed chrisherb closed 1 year ago

chrisherb commented 1 year ago

There's a bug in the IPlugInstrument example regarding the toggle state for the beat synced LFO. Steps to reproduce:

I found that the action function attached to the IVSlideSwitchControl is not called during startup. Setting it dirty will call it during startup but it then does not contain the saved control value.

Tested on Windows 11 and Reaper v6.68 with the included Reaper project loading the VST3 build. Visual Studio solution has not been touched other than updating it to the latest VS version. Used (at time of writing) up to date iPlug2 master branch (commit a8f3246).

olilarkin commented 1 year ago

Thanks, fixed in e23c212

chrisherb commented 1 year ago

Awesome, thank you! One issue remains though: after toggling the switch you have to wiggle the rate knob so the knob's value is applied to the LFO. I fixed it by modifying OnParamChangeUI in the following way:

void IPlugInstrument::OnParamChangeUI(int paramIdx, EParamSource source)
{
    if (auto pGraphics = GetUI()) {
        if (paramIdx == kParamLFORateMode) {
            const auto sync = GetParam(kParamLFORateMode)->Bool();
            pGraphics->HideControl(kParamLFORateHz, sync);
            pGraphics->HideControl(kParamLFORateTempo, !sync);

            if (sync) {
                pGraphics->GetControlWithParamIdx(kParamLFORateTempo)->SetDirty();
            } else {
                pGraphics->GetControlWithParamIdx(kParamLFORateHz)->SetDirty();
            }
        }
    }
}

But I'm not sure if that's the cleanest way to do it. Best, Chris