Skip to content

Migrate sampler plugin to the C++ wrapper API #143

@kaoskorobase

Description

@kaoskorobase

Context

plugins/sampler.cpp is implemented against the raw C API (namespaced Methcla_SynthDef with C function pointers + a host-command lifecycle for buffer loading). plugins/README.md declares the C++ wrapper API "preferred". This issue migrates Sampler to StaticSynthDef using kSynthDefHasCleanup.

Outcome: sampler.cpp uses the wrapper API; load → silence-until-loaded → play → synthDone semantics preserved.

Scope

Convert synth boilerplate. Keep load_sound_file, set_buffer, free_buffer_cb, hermite1, resample as free helpers (they run on host or are state-free templates). Use kSynthDefHasCleanup — cleanup runs free_buffer_cb via world.performCommand.

SamplerOptions constructor mirrors current configure (sampler.cpp:100–112) verbatim, just sourcing args from the ArgStream passed in. Preserve the existing size_t numFrames with -1 sentinel (surgical; the original quirk stays).

Construct moves the variable-length LoadMessage allocation (sampler.cpp:203–212) into the C++ constructor using world.alloc(). set_buffer writes back via a Sampler::setBuffer(...) member (keeps fields private).

process_interp (sampler.cpp:328) becomes a private member function Sampler::processInterp(...). freeBuffer(world, self) becomes inline:

world.performCommand(free_buffer_cb, m_buffer);
m_buffer = nullptr;

and methcla_world_synth_done(world, self) becomes world.synthDone(this).

Update LoadMessage::synth from Synth* to Sampler*.

Register:

StaticSynthDef<Sampler, SamplerOptions, SamplerPorts, kSynthDefHasCleanup>
    kSamplerDef;

Files

  • plugins/sampler.cpp — convert synth boilerplate; kSynthDefHasCleanup
  • plugins/README.md — update the "Implementation styles" table row to move sampler.cpp under the wrapper category (the table currently mis-classifies it under C API, which this issue corrects).
  • CHANGELOG.md — add a ### Changed entry under ## [Unreleased] referencing this issue.

Verification

pre-commit run --all-files
cmake --preset debug
cmake --build build/debug
ctest --test-dir build/debug --output-on-failure

Confirm methcla_plugin_sampler builds. Run any test exercising sampler load-and-play (check tests/ for what exists).

Behavioural equivalence (no audible / log diff expected):

  • Load → silence-until-loaded → play → synthDone on end (non-loop).

This plugin requires a Soundfile API Plugin to be registered (see plugins/README.md).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions