Plug:
Filter:
ddwPlug/Classes (extension) | Server > Nodes | Server > Abstractions

Plug
ExtensionExtension

A signal argument for Syn

Description

Plug must be used in a Syn argument list. It represents a signal that will be initiated synchronously with the Syn's primary nodes, and connected to a Syn or Plug using a server bus.

A Plug's signal comes either from a SynthDef (identified by name) or a Function. The Plug also defines an argument list. This may itself contain Plugs, forming a tree structure.

Syn is designed for polyphony. Accordingly, everywhere that a Plug appears in an argument list will produce its own unique signal. This is done by copying the Plug at the moment of rendering it into the server messages. This means you cannot manipulate a Plug object by reference to the original. You will need to access the actual, performing Plug using Syn: -argAt or Plug: -argAt. *shared will suppress the copy so that a single Plug can route its signal to multiple inputs.

See Syn for usage details.

Plugs based on Functions

A Function needs to be converted into a SynthDef before playing it. This is an asynchronous operation.

If the Syn is played with messaging latency (see ServerTiming.html), the Plug will prepare the SynthDef immediately, wait for completion (Server: -sync), and then adjust the messaging latency so that the audio begins on time. In this case, if latency is too short, or there are too many Functions to prepare, the final bundle may be late. For performance, it is recommended to use prepared SynthDefs whenever practical.

If it's played without latency, it will still server.sync, and the audio will be produced as soon as possible after that. Timing accuracy will be lost (but not any worse than Function: -play).

April 2025: If several Plugs reuse the same function definition, they may be able to reuse the temporary SynthDef.

Caching depends on functions sharing the same (identical) FunctionDef and the same "context." In ex. A, the two Plugs are based on physically distinct functions; hence their definitions are not identical, and two SynthDefs are generated. In ex. B, the two Plugs use one function object and share one SynthDef. (Executing the same block of code twice produces all-new function definitions; cache cannot be used across multiple interpreter invocations.)

Open functions may cause the "context" to be different, also preventing cache use (ex. C). Instead, if a function passes a parameter into a Plug's argument list, then the Plug function can be closed and share context, hitting cache (ex. D). Ex. E and F show the same distinction in a Pattern context.

Using a named SynthDef guarantees reuse, of course.

Class Methods

.new

Create a new Plug instance.

Arguments:

source

A Symbol (SynthDef name) or Function, defining the signal's source.

args

A Synth-style argument list (which may itself contain Plugs).

rate

Optional. In general, you should not need to specify this; Plug will attempt to determine the rate from the Function or SynthDef. (This assumes that the SynthDef has been added by SynthDef: -add.)

numChannels

Optional. In general, you should not need to specify this; Plug will attempt to determine the number of channels from the Function or SynthDef.

map

Optional. See Syn.html: Three-point%20modulation for details.

Returns:

A new Plug instance.

.shared

Create a new Plug instance, which is marked to avoid copying itself.

Arguments:

source

A Symbol (SynthDef name) or Function, defining the signal's source.

args

A Synth-style argument list (which may itself contain Plugs).

rate

Optional. In general, you should not need to specify this; Plug will attempt to determine the rate from the Function or SynthDef. (This assumes that the SynthDef has been added by SynthDef: -add.)

numChannels

Optional. In general, you should not need to specify this; Plug will attempt to determine the number of channels from the Function or SynthDef.

map

Optional. See Syn.html: Three-point%20modulation for details.

Returns:

A new Plug instance.

Instance Methods

Repatching the source

.source

Get or set the current Plug source. The current Plug instance will remain in place. Its prior Synth node will be replaced by a new Synth in the same location in the node tree, with the same argument values.

Arguments:

src

Currently supported sources are: a string or symbol naming a SynthDef, or a function that creates UGens.

latency

Server messaging latency.

Control

Note that in general, users should interact with the owner Syn object, and not call these methods directly.

.set

Change the Plug's input values.

Arguments:

... args

A Synth-style argument list.

.setMsg

Produce an OSC message to set the input values.

Arguments:

... args

A Synth-style argument list.

Returns:

An OSC message (array).

.setn

Change the Plug's input values.

Arguments:

... args

A Synth-style argument list.

.setMsg

Produce an OSC message to Node: -setn the input values.

Arguments:

... args

A Synth-style argument list.

Returns:

An OSC message (array).

.free

Destroy this Plug, and release resources.

Arguments:

latency

Messaging latency in seconds.

Properties

.bus

If the Plug is active, return the bus that has been allocated.

.group

Returns the owner Syn's target group.

.node

Returns the Synth node producing the Plug's signal.

.isConcrete

If true, this Plug represents a concrete signal. If false, it only defines an expected behavior (and will be copied at render time).

.rate

Returns \audio or \control.

.numChannels

Returns the number of channels for this Plug.

.server

Returns the server object where this Plug is running.

.concreteArgs

Returns the actual argument list being used. Plugs in the original argument list may have been copied. This array will contain the copies.

.controlNames

Array of symbols, listing the synth's control input names.

.map

Get the dictionary mapping parent-level control names onto a different control name belonging to this Plug. See Syn.html: Three-point%20modulation for details.

.dest

Returns the top-level Syn object.

.argAt

Access the object from the argument list corresponding to the named input.

Arguments:

key

An input name belonging to the Plug synth.

Returns:

A value from the argument list.

Structure

.antecedents

An IdentitySet of Plugs feeding directly into this Plug.

antecedents and descendents can be used to iterate over the tree structure.

.descendants

An IdentitySet of Plugs receiving this Plug's signal.

.predecessor

Points to the Plug object immediately preceding this one in the server's node tree.

.asControlInput

Returns the Plug's bus mapping string(s).

.asMap

Returns the Plug's bus mapping string(s).

.node

Returns the Plug's synth node.

.concreteInstance

Make the concrete, performing instance (unique signal) -- basically "copy."

Examples

See Syn: examples.