Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 49 additions & 23 deletions src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,39 @@ tresult PLUGIN_API ClapAsVst3::canProcessSampleSize(int32 symbolicSampleSize)

tresult PLUGIN_API ClapAsVst3::setState(IBStream *state)
{
return (_plugin->load(CLAPVST3StreamAdapter(state)) ? Steinberg::kResultOk : Steinberg::kResultFalse);
auto raise = _plugin->AlwaysMainThread();
_param_rescan_has_been_called = false; // detect rescan/reload during load

auto result =
(_plugin->load(CLAPVST3StreamAdapter(state)) ? Steinberg::kResultOk : Steinberg::kResultFalse);

// if the state was loaded correctly, values must be updated
if (result == kResultOk && !_param_rescan_has_been_called)
{
syncParameterValuesFromClap();
}
return result;
}

void ClapAsVst3::syncParameterValuesFromClap()
{
if (!_plugin->_ext._params) return;

auto len = parameters.getParameterCount();
for (decltype(len) i = 0; i < len; ++i)
{
auto p = static_cast<Vst3Parameter *>(parameters.getParameterByIndex(i));
if (p->isMidi) continue;
double val;
if (_plugin->_ext._params->get_value(_plugin->_plugin, p->id, &val))
{
auto newval = p->asVst3Value(val);
if (p->getNormalized() != newval)
{
p->setNormalized(newval);
}
}
}
}

tresult PLUGIN_API ClapAsVst3::getState(IBStream *state)
Expand Down Expand Up @@ -1212,32 +1244,26 @@ void ClapAsVst3::param_rescan(clap_param_rescan_flags flags)

if (vstflags == 0) return;

// check this in ::setState
_param_rescan_has_been_called = true;

// update parameter values in our own tree
auto len = parameters.getParameterCount();
for (decltype(len) i = 0; i < len; ++i)
syncParameterValuesFromClap();

if (flags & CLAP_PARAM_RESCAN_INFO)
{
auto p = static_cast<Vst3Parameter *>(parameters.getParameterByIndex(i));
if (!p->isMidi)
// In this case, the name and module can also change.
// For now, don't rebuild the unit tree with modules but
// do rescan the name
auto len = parameters.getParameterCount();
for (decltype(len) i = 0; i < len; ++i)
{
double val;
if (_plugin->_ext._params->get_value(_plugin->_plugin, p->id, &val))
auto p = static_cast<Vst3Parameter *>(parameters.getParameterByIndex(i));
if (p->isMidi) continue;
clap_param_info_t info;
if (_plugin->_ext._params->get_info(_plugin->_plugin, p->param_index_for_clap_get_info, &info))
{
auto newval = p->asVst3Value(val);
if (p->getNormalized() != newval)
{
p->setNormalized(newval);
}
}
if (flags & CLAP_PARAM_RESCAN_INFO)
{
// In this case, the name and module can also change.
// For now, don't rebuild the unit tree with modules but
// do rescan the name
clap_param_info_t info;
if (_plugin->_ext._params->get_info(_plugin->_plugin, p->param_index_for_clap_get_info, &info))
{
str8ToStr16(p->getInfo().title, info.name, str16BufferSize(p->getInfo().title));
}
str8ToStr16(p->getInfo().title, info.name, str16BufferSize(p->getInfo().title));
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/wrapasvst3.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect,
Vst::UnitID getOrCreateUnitInfo(const char *modulename);
std::map<std::string, Vst::UnitID> _moduleToUnit;

// pulls current values from the CLAP plugin's params extension into our VST3 parameter tree
// (used by both setState and param_rescan)
void syncParameterValuesFromClap();

Clap::Library *_library = nullptr;
int _libraryIndex = 0;
std::shared_ptr<Clap::Plugin> _plugin;
Expand Down Expand Up @@ -417,6 +421,8 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect,
// the queue from audiothread to UI thread
ClapWrapper::detail::shared::fixedqueue<queueEvent, 8192> _queueToUI;

bool _param_rescan_has_been_called{false};

// for IMidiMapping
bool _useIMidiMapping = false;
Vst::ParamID _IMidiMappingIDs[16][Vst::ControllerNumbers::kCountCtrlNumber] =
Expand Down
Loading