VST3: Keep preset in sync with plugin GUI

When a user loads a preset using the plugin's own GUI, update
Ardour's preset dropdown.
This commit is contained in:
Robin Gareus
2020-10-25 19:50:22 +01:00
parent 6c14e568f0
commit da1782d56e
2 changed files with 20 additions and 2 deletions

View File

@@ -115,7 +115,8 @@ public:
Vst::IUnitInfo* unit_info ();
FUID const& fuid() const { return _fuid; }
Vst::ParameterInfo const& program_change_port() const { return _program_change_port; }
void set_n_factory_presets (size_t n) { _n_factory_presets = n; }
void set_n_factory_presets (size_t n) { _n_factory_presets = n; }
size_t n_factory_presets () const { return _n_factory_presets; }
/* API for Ardour -- Ports */
uint32_t designated_bypass_port () const { return _port_id_bypass; }

View File

@@ -122,6 +122,16 @@ VST3Plugin::parameter_change_handler (VST3PI::ParameterChange t, uint32_t param,
break;
case VST3PI::PresetChange:
PresetsChanged (unique_id (), this, false); /* EMIT SIGNAL */
size_t n_presets = _plug->n_factory_presets (); // ths may be old, invalidated count
if (_plug->program_change_port ().id != Vst::kNoParamId) {
int pgm = value * (n_presets > 1 ? (n_presets - 1) : 1);
std::string uri = string_compose (X_("VST3-P:%1:%2"), unique_id (), std::setw(4), std::setfill('0'), pgm);
const Plugin::PresetRecord* pset = Plugin::preset_by_uri (uri);
if (pset && n_presets == _plug->n_factory_presets ()) {
Plugin::load_preset (*pset);
// XXX TODO notify replicated instances, unless plugin implements ISlaveControllerHandler
}
}
break;
}
}
@@ -1346,7 +1356,13 @@ VST3PI::notifyUnitSelection (Vst::UnitID unitId)
tresult
VST3PI::notifyProgramListChange (Vst::ProgramListID, int32)
{
OnParameterChange (PresetChange, 0, 0); /* EMIT SIGNAL */
float v = 0;
Vst::ParamID id = _program_change_port.id;
if (id != Vst::kNoParamId) {
v = _controller->getParamNormalized (id);
DEBUG_TRACE (DEBUG::VST3Config, "VST3PI::notifyProgramListChange: val: %1 (norm: %2)\n", v, _controller->normalizedParamToPlain (id, v));
}
OnParameterChange (PresetChange, 0, v); /* EMIT SIGNAL */
return kResultOk;
}
@@ -1719,6 +1735,7 @@ VST3PI::set_program (int pgm, int32 sample_off)
value /= (_n_factory_presets - 1.f);
}
#endif
DEBUG_TRACE (DEBUG::VST3Config, "VST3PI::set_program pgm: %1 val: %2 (norm: %3)\n", pgm, value, _controller->plainParamToNormalized (id, pgm));
int32 index;
_input_param_changes.addParameterData (id, index)->addPoint (sample_off, value, index);