Summary
Integrates the resource system from #147 into the Synth layer: declares resource ports in Methcla_SynthDef, acquires/releases resource handles on synth construction/destruction, and extends /node/set to accept integer resource ids for resource ports.
Depends on
Scope
New port type
Add kMethcla_ResourcePort to the Methcla_PortType enum in include/methcla/plugin.h.
Port direction is informational metadata for resource ports; the engine does not enforce mutability against direction. Methcla_PortDescriptor stays unchanged.
Synth memory layout
Extend Synth::construct() static factory (src/Methcla/Audio/Synth.cpp) to count kMethcla_ResourcePort descriptors, then append a ResourcePortConnection[] array to the single synth allocation block:
[Synth C++ object]
[AudioInputConnection[]]
[AudioOutputConnection[]]
[ResourcePortConnection[]] // ← new
[control buffers]
[audio buffers]
struct ResourcePortConnection {
Methcla_PortCount index;
Methcla_ResourceId resourceId;
void* data; // cached from resource_acquire
};
Acquire / release lifecycle
- During
Synth::construct(): for each resource port, call methcla_world_resource_acquire(world, id, def), store the result in ResourcePortConnection.data, call synthDef.connect(synth, portIndex, data).
- If any acquire fails,
construct() fails gracefully (releases already-acquired resources).
- During
Synth::~Synth(): call methcla_world_resource_release(world, id) for each resource port with non-null data.
Dynamic re-assignment
Extend /node/set to accept i:value (integer) when the port at portIndex is kMethcla_ResourcePort. The engine:
- Releases the old resource (if any).
- Acquires the new resource.
- Calls
synthDef.connect(synth, portIndex, newData).
Using f:value against a resource port returns replyError unchanged.
C++ helper
ResourceRef<T> (defined in #147, include/methcla/plugin.hpp) works as the per-synth-lifetime RAII wrapper for plugins that prefer a C++ interface over explicit acquire/release in construct/destroy.
Files to modify
| File |
Change |
include/methcla/plugin.h |
Add kMethcla_ResourcePort to Methcla_PortType |
src/Methcla/Audio/Synth.hpp |
Add ResourcePortConnection, extend Synth members |
src/Methcla/Audio/Synth.cpp |
Count resource ports, adjust memory layout, acquire/release |
src/Methcla/Audio/EngineImpl.cpp |
Extend /node/set handler for resource ports |
tests/resource_tests.cpp |
Add synth integration test cases |
CHANGELOG.md |
Entry under [Unreleased] |
docs/osc-api.md |
Document i:value form for /node/set on resource ports |
Summary
Integrates the resource system from #147 into the Synth layer: declares resource ports in
Methcla_SynthDef, acquires/releases resource handles on synth construction/destruction, and extends/node/setto accept integer resource ids for resource ports.Depends on
Scope
New port type
Add
kMethcla_ResourcePortto theMethcla_PortTypeenum ininclude/methcla/plugin.h.Port direction is informational metadata for resource ports; the engine does not enforce mutability against direction.
Methcla_PortDescriptorstays unchanged.Synth memory layout
Extend
Synth::construct()static factory (src/Methcla/Audio/Synth.cpp) to countkMethcla_ResourcePortdescriptors, then append aResourcePortConnection[]array to the single synth allocation block:Acquire / release lifecycle
Synth::construct(): for each resource port, callmethcla_world_resource_acquire(world, id, def), store the result inResourcePortConnection.data, callsynthDef.connect(synth, portIndex, data).construct()fails gracefully (releases already-acquired resources).Synth::~Synth(): callmethcla_world_resource_release(world, id)for each resource port with non-null data.Dynamic re-assignment
Extend
/node/setto accepti:value(integer) when the port atportIndexiskMethcla_ResourcePort. The engine:synthDef.connect(synth, portIndex, newData).Using
f:valueagainst a resource port returnsreplyErrorunchanged.C++ helper
ResourceRef<T>(defined in #147,include/methcla/plugin.hpp) works as the per-synth-lifetime RAII wrapper for plugins that prefer a C++ interface over explicit acquire/release inconstruct/destroy.Files to modify
include/methcla/plugin.hkMethcla_ResourcePorttoMethcla_PortTypesrc/Methcla/Audio/Synth.hppResourcePortConnection, extendSynthmemberssrc/Methcla/Audio/Synth.cppsrc/Methcla/Audio/EngineImpl.cpp/node/sethandler for resource portstests/resource_tests.cppCHANGELOG.md[Unreleased]docs/osc-api.mdi:valueform for/node/seton resource ports