Skip to content

Synth resource port integration (kMethcla_ResourcePort) #151

Description

@kaoskorobase

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:

  1. Releases the old resource (if any).
  2. Acquires the new resource.
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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