Find /u_cmd synthIndex automatically?


I’m working on a UGen for interpreting bytebeat expressions on the fly. I’m using a UnitCmd to send strings containing expressions to the UGen for parsing.

On the sclang side, the interface looks like this:

(\bytebeat, {
    var t =;,

b = ByteBeatController(\bytebeat), 2);

The second parameter of ByteBeatController is the index of the ByteBeat UGen in the Synth. The controller uses this to send the UnitCmd to the UGen: synth.server.sendMsg('/u_cmd', synth.nodeID, synthIndex, cmd, *args).

I’d like to avoid having to manually provide the index. Is it possible to determine it automatically from the Synth instance?


Have a look at, specifically the optimiozeGraph and synthIndex_ method. sc/classes/ · develop · Pure Data libraries / vstplugin · GitLab

The basic idea is to store the index in the SynthDef metadata, so it can also survive serialization from/to disk (needed for!). Also, has an (optional) id parameter, in case you want to have more than one instance in the same SynthDef. VSTPluginController can use this ID to look up the index of a specific VSTPlugin instance. If no ID is given, it simple takes the first (and only) entry.

Hope that helps. Feel free to ask if you have any more questions.

1 Like