Skip to content

Migrate patch_cable PatchCable to the C++ wrapper API #141

Description

@kaoskorobase

Context

plugins/patch_cable.cpp currently registers two SynthDefs:

  • PatchCable — implemented against the raw C API (Methcla_SynthDef with construct/connect/process/destroy function pointers).
  • Amplifier — already uses the C++ wrapper API (StaticSynthDef).

plugins/README.md declares the wrapper "preferred". This issue brings PatchCable in line.

Outcome: patch_cable.cpp uses the wrapper for both synths; ~50 lines of raw-C boilerplate dropped.

Scope

Replace the raw-C PatchCable synth (lines 25–92 of plugins/patch_cable.cpp) with a wrapper class alongside the existing Amplifier. Update the loader to call kPatchCableDef(host, METHCLA_PLUGINS_PATCH_CABLE_URI).

typedef NoOptions PatchCableOptions;

class PatchCablePorts
{
public:
    enum Port { kInput, kOutput };
    static constexpr size_t numPorts() { return 2; }
    static Methcla_PortDescriptor descriptor(Port port)
    {
        switch (port)
        {
            case kInput:  return PortDescriptor::audioInput();
            case kOutput: return PortDescriptor::audioOutput();
            default:
                throw std::runtime_error(METHCLA_PLUGINS_PATCH_CABLE_URI
                                         ": Invalid port index");
        }
    }
};

class PatchCable
{
    float* m_ports[PatchCablePorts::numPorts()];
public:
    PatchCable(const World<PatchCable>&, const Methcla_SynthDef*,
               const PatchCableOptions&) {}
    void connect(PatchCablePorts::Port port, void* data)
    {
        m_ports[port] = static_cast<float*>(data);
    }
    void process(const World<PatchCable>&, size_t numFrames)
    {
        const float* src = m_ports[PatchCablePorts::kInput];
        float*       dst = m_ports[PatchCablePorts::kOutput];
        std::copy(src, src + numFrames, dst);
    }
};

StaticSynthDef<PatchCable, PatchCableOptions, PatchCablePorts> kPatchCableDef;

Files

  • plugins/patch_cable.cpp — replace the raw-C PatchCable synth
  • plugins/README.md — update the "Implementation styles" table row for patch_cable.cpp (already lists wrapper for Amplifier; both synths now use wrapper)
  • CHANGELOG.md — add a ### Changed entry under ## [Unreleased] referencing this issue

Verification

pre-commit run --all-files
cmake --preset debug         # or whatever preset name is in CMakePresets.json
cmake --build build/debug
ctest --test-dir build/debug --output-on-failure

Confirm methcla_plugin_patch_cable builds. Existence + load is sufficient — no nontrivial state to behaviourally diff.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions