diff --git a/libs/clap b/libs/clap index 55ee06f..af1e05c 160000 --- a/libs/clap +++ b/libs/clap @@ -1 +1 @@ -Subproject commit 55ee06f776669b94d63247a9c1dcb7dfa6056587 +Subproject commit af1e05ce6487151c6b36003fdb47566dbb50194e diff --git a/libs/clap-helpers b/libs/clap-helpers index 716cdf4..fc56ccf 160000 --- a/libs/clap-helpers +++ b/libs/clap-helpers @@ -1 +1 @@ -Subproject commit 716cdf49cc6eb7999bad44c084b363bbde907937 +Subproject commit fc56ccff5c1cd54f8afb17f249da7da7b0b60bf0 diff --git a/src/airwin-to-clap.cpp b/src/airwin-to-clap.cpp index 31ed668..59ce2b3 100644 --- a/src/airwin-to-clap.cpp +++ b/src/airwin-to-clap.cpp @@ -23,9 +23,11 @@ struct aw2cWrapper : public clap::helpers::Plugin(desc, host), underlyer(effect) { - assert(underlyer); + assert(underlyer); + } + ~aw2cWrapper() { + delete underlyer; } - ~aw2cWrapper() = default; bool activate(double sampleRate, uint32_t minFrameCount, uint32_t maxFrameCount) noexcept override @@ -70,6 +72,30 @@ struct aw2cWrapper : public clap::helpers::PlugingetParameterDisplay(paramId - paramOff, display); return true; } + void paramsFlush(const clap_input_events *ev, const clap_output_events *) noexcept override + { + auto sz = ev->size(ev); + + for (size_t i=0; iget(ev, i); + + if (nextEvent->space_id == CLAP_CORE_EVENT_SPACE_ID) + { + switch (nextEvent->type) + { + case CLAP_EVENT_PARAM_VALUE: + { + auto pevt = reinterpret_cast(nextEvent); + underlyer->setParameter(pevt->param_id - paramOff, pevt->value); + break; + } + default: + break; + } + } + } + } bool implementsAudioPorts() const noexcept override { return true; } uint32_t audioPortsCount(bool isInput) const noexcept override @@ -82,6 +108,7 @@ struct aw2cWrapper : public clap::helpers::Pluginid = isInput ? 2112 : 90210; + info->in_place_pair = !isInput ? 2112 : 90210; strncpy(info->name, "main", sizeof(info->name)); info->flags = CLAP_AUDIO_PORT_IS_MAIN; info->channel_count = 2; @@ -89,6 +116,7 @@ struct aw2cWrapper : public clap::helpers::Pluginframes_count; @@ -152,18 +180,27 @@ struct aw2cWrapper : public clap::helpers::PlugingetChunk((void**)&data, false); + if (s && data) + { + auto c = data; + while (s > 0) + { + auto r = stream->write(stream, c, s); + if (r < 0) + return false; + s -= r; + c += r; + } + free(data); + } - auto c = data; - while (s > 0) + // But no state is fine when we have no params + if (!s && !data) { - auto r = stream->write(stream, c, s); - if (r < 0) + assert(paramsCount() == 0); + if (paramsCount() > 0) return false; - s -= r; - c += r; } - free(data); - return true; } bool stateLoad(const clap_istream *stream) noexcept override @@ -189,6 +226,9 @@ static const clap_plugin *clap_create_plugin(const clap_plugin_factory *f, const const char *plugin_id) { auto [fx, desc] = aw2c_get_aeffInstance(host, plugin_id); + if (!fx) + return nullptr; + auto wr = new aw2cWrapper(host, desc, fx); return wr->clapPlugin(); } @@ -199,7 +239,11 @@ const CLAP_EXPORT struct clap_plugin_factory aw2c_factory = { clap_create_plugin, }; -static const void *get_factory(const char *factory_id) { return &aw2c_factory; } +static const void *get_factory(const char *factory_id) { + if (strcmp(factory_id, CLAP_PLUGIN_FACTORY_ID) == 0) + return &aw2c_factory; + return 0; +} // clap_init and clap_deinit are required to be fast, but we have nothing we need to do here bool clap_init(const char *p) { return true; }