Skip to content

Commit

Permalink
More stuff pushed to sst-plugininfra (#140)
Browse files Browse the repository at this point in the history
if sharing is caring, this commit cares. Move the stateload/restore
and param setup to patch generic codes in plugin infra
  • Loading branch information
baconpaul authored Jan 18, 2025
1 parent c8237be commit 46bb6ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 72 deletions.
81 changes: 10 additions & 71 deletions src/clap/six-sines-clap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <clap/helpers/host-proxy.hxx>

#include <memory>
#include "sst/plugininfra/patch-support/patch_base_clap_adapter.h"

#include "sst/voicemanager/midi1_to_voicemanager.h"
#include "sst/clap_juce_shim/clap_juce_shim.h"

Expand Down Expand Up @@ -230,49 +232,13 @@ struct SixSinesClap : public plugHelper_t, sst::clap_juce_shim::EditorProvider
bool stateSave(const clap_ostream *ostream) noexcept override
{
engine->prepForStream();
auto ss = engine->patch.toState();
auto c = ss.c_str();
auto s = ss.length() + 1; // write the null terminator
while (s > 0)
{
auto r = ostream->write(ostream, c, s);
if (r < 0)
return false;
s -= r;
c += r;
}
return true;
return sst::plugininfra::patch_support::patchToOutStream(engine->patch, ostream);
}
bool stateLoad(const clap_istream *istream) noexcept override
{
static constexpr uint32_t initSize = 1 << 16, chunkSize = 1 << 8;
std::vector<char> buffer;
buffer.resize(initSize);

int64_t rd{0};
int64_t totalRd{0};
auto bp = buffer.data();

while ((rd = istream->read(istream, bp, chunkSize)) > 0)
{
bp += rd;
totalRd += rd;
if (totalRd >= buffer.size() - chunkSize - 1)
{
buffer.resize(buffer.size() * 2);
bp = buffer.data() + totalRd;
}
}
buffer[totalRd] = 0;

if (totalRd == 0)
{
SXSNLOG("Received stream size 0. Invalid state");
if (!sst::plugininfra::patch_support::inStreamToPatch(istream, engine->patch))
return false;
}

auto data = std::string(buffer.data());
engine->patch.fromState(data);
engine->postLoad();
_host.paramsRequestFlush();
return true;
Expand All @@ -282,49 +248,22 @@ struct SixSinesClap : public plugHelper_t, sst::clap_juce_shim::EditorProvider
uint32_t paramsCount() const noexcept override { return engine->patch.params.size(); }
bool paramsInfo(uint32_t paramIndex, clap_param_info *info) const noexcept override
{
auto *param = engine->patch.params[paramIndex];
auto &md = param->meta;
md.toClapParamInfo<CLAP_NAME_SIZE, clap_param_info_t>(info);
info->cookie = (void *)param;
return true;
return sst::plugininfra::patch_support::patchParamsInfo(paramIndex, info, engine->patch);
}
bool paramsValue(clap_id paramId, double *value) noexcept override
{
*value = engine->patch.paramMap[paramId]->value;
return true;
return sst::plugininfra::patch_support::patchParamsValue(paramId, value, engine->patch);
}
bool paramsValueToText(clap_id paramId, double value, char *display,
uint32_t size) noexcept override
{
auto it = engine->patch.paramMap.find(paramId);
if (it == engine->patch.paramMap.end())
{
return false;
}
auto valdisp = it->second->meta.valueToString(value);
if (!valdisp.has_value())
return false;

strncpy(display, valdisp->c_str(), size);
display[size - 1] = 0;
return true;
return sst::plugininfra::patch_support::patchParamsValueToText(paramId, value, display,
size, engine->patch);
}
bool paramsTextToValue(clap_id paramId, const char *display, double *value) noexcept override
{
auto it = engine->patch.paramMap.find(paramId);
if (it == engine->patch.paramMap.end())
{
return false;
}
std::string err;
auto val = it->second->meta.valueFromString(display, err);
if (!val.has_value())
{
SXSNLOG("Error converting '" << display << "' : " << err);
return false;
}
*value = *val;
return true;
return sst::plugininfra::patch_support::patchParamsTextToValue(paramId, display, value,
engine->patch);
}
void paramsFlush(const clap_input_events *in, const clap_output_events *out) noexcept override
{
Expand Down

0 comments on commit 46bb6ab

Please sign in to comment.