SynthDef

class supriya.tools.synthdeftools.SynthDef(ugens, name=None, optimize=True, parameter_names=None, **kwargs)[source]

A synth definition.

>>> from supriya.tools import synthdeftools
>>> from supriya.tools import ugentools
>>> with synthdeftools.SynthDefBuilder(frequency=440) as builder:
...     sin_osc = ugentools.SinOsc.ar(frequency=builder['frequency'])
...     out = ugentools.Out.ar(bus=0, source=sin_osc)
...
>>> synthdef = builder.build()
>>> graph(synthdef)  
>>> from supriya import servertools
>>> server = servertools.Server().boot()
>>> synthdef.allocate(server=server)
<SynthDef: 9c4eb4778dc0faf39459fa8a5cd45c19>
>>> synthdef in server
True
>>> synthdef.free()
>>> synthdef in server
False
>>> server.quit()
<Server: offline>

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=1, group=0, label=object, shape=box]; } subgraph cluster_servertools { graph [label=servertools]; "supriya.tools.servertools.ServerObjectProxy.ServerObjectProxy" [color=2, group=1, label=ServerObjectProxy, shape=oval, style=bold]; } subgraph cluster_synthdeftools { graph [label=synthdeftools]; "supriya.tools.synthdeftools.SynthDef.SynthDef" [color=black, fontcolor=white, group=2, label=<<B>SynthDef</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_systemtools { graph [label=systemtools]; "supriya.tools.systemtools.SupriyaObject.AbstractBase" [color=4, group=3, label=AbstractBase, shape=box]; "supriya.tools.systemtools.SupriyaObject.SupriyaObject" [color=4, group=3, label=SupriyaObject, shape=box]; "supriya.tools.systemtools.SupriyaObject.AbstractBase" -> "supriya.tools.systemtools.SupriyaObject.SupriyaObject"; } "builtins.object" -> "supriya.tools.systemtools.SupriyaObject.AbstractBase"; "supriya.tools.servertools.ServerObjectProxy.ServerObjectProxy" -> "supriya.tools.synthdeftools.SynthDef.SynthDef"; "supriya.tools.systemtools.SupriyaObject.SupriyaObject" -> "supriya.tools.servertools.ServerObjectProxy.ServerObjectProxy"; }

Bases

Attribute summary

actual_name
allocate([server])
anonymous_name
audio_channel_count
audio_input_channel_count Gets audio input channel count of synthdef.
audio_output_channel_count Gets audio output channel count of synthdef.
compile([use_anonymous_name])
constants
control_channel_count
control_input_channel_count Gets control input channel count of synthdef.
control_output_channel_count Gets control output channel count of synthdef.
control_ugens
done_actions
free()
has_gate
indexed_parameters
input_ugens
is_allocated
name
output_ugens
parameter_names
parameters
play([add_action, target_node]) Plays the synthdef on the server.
server
to_dict() Convert SynthDef to JSON-serializable dictionay.
ugens
__eq__(expr)
__format__([format_specification]) Formats Supriya object.
__graph__() Graphs SynthDef.
__hash__()
__repr__()
__str__() Gets string representation of synth definition.

Read-only properties

SynthDef.actual_name
SynthDef.anonymous_name
SynthDef.audio_channel_count
SynthDef.audio_input_channel_count

Gets audio input channel count of synthdef.

>>> with SynthDefBuilder() as builder:
...     audio_in = ugentools.In.ar(channel_count=1)
...     control_in = ugentools.In.kr(channel_count=2)
...     sin = ugentools.SinOsc.ar(
...          frequency=audio_in,
...          )
...     source = audio_in * control_in[1]
...     audio_out = ugentools.Out.ar(source=[source] * 4)
...
>>> synthdef = builder.build()
>>> graph(synthdef)  
>>> synthdef.audio_input_channel_count
1

Returns integer.

SynthDef.audio_output_channel_count

Gets audio output channel count of synthdef.

>>> with SynthDefBuilder() as builder:
...     audio_in = ugentools.In.ar(channel_count=1)
...     control_in = ugentools.In.kr(channel_count=2)
...     sin = ugentools.SinOsc.ar(
...          frequency=audio_in,
...          )
...     source = audio_in * control_in[1]
...     audio_out = ugentools.Out.ar(source=[source] * 4)
...
>>> synthdef = builder.build()
>>> graph(synthdef)  
>>> synthdef.audio_output_channel_count
4

Returns integer.

SynthDef.constants
SynthDef.control_channel_count
SynthDef.control_input_channel_count

Gets control input channel count of synthdef.

>>> with SynthDefBuilder() as builder:
...     audio_in = ugentools.In.ar(channel_count=1)
...     control_in = ugentools.In.kr(channel_count=2)
...     sin = ugentools.SinOsc.ar(
...          frequency=audio_in,
...          )
...     source = audio_in * control_in[1]
...     audio_out = ugentools.Out.ar(source=[source] * 4)
...
>>> synthdef = builder.build()
>>> graph(synthdef)  
>>> synthdef.control_input_channel_count
2

Returns integer.

SynthDef.control_output_channel_count

Gets control output channel count of synthdef.

>>> with SynthDefBuilder() as builder:
...     audio_in = ugentools.In.ar(channel_count=1)
...     control_in = ugentools.In.kr(channel_count=2)
...     sin = ugentools.SinOsc.ar(
...          frequency=audio_in,
...          )
...     source = audio_in * control_in[1]
...     audio_out = ugentools.Out.ar(source=[source] * 4)
...
>>> synthdef = builder.build()
>>> graph(synthdef)  
>>> synthdef.control_output_channel_count
0

Returns integer.

SynthDef.control_ugens
SynthDef.done_actions
SynthDef.has_gate
SynthDef.indexed_parameters
SynthDef.input_ugens
SynthDef.is_allocated
SynthDef.name
SynthDef.output_ugens
SynthDef.parameter_names
SynthDef.parameters
(ServerObjectProxy).server
SynthDef.ugens

Methods

SynthDef.allocate(server=None)[source]
SynthDef.compile(use_anonymous_name=False)[source]
SynthDef.free()[source]
SynthDef.play(add_action=None, target_node=None, **kwargs)[source]

Plays the synthdef on the server.

>>> server = Server().boot()
>>> synthdef = synthdefs.default
>>> synth = synthdef.play()
>>> server = server.quit()
SynthDef.to_dict()[source]

Convert SynthDef to JSON-serializable dictionay.

>>> import json
>>> result = synthdefs.default.to_dict()
>>> result = json.dumps(
...     result,
...     indent=4,
...     separators=(',', ': '),
...     sort_keys=True,
...     )
>>> print(result)
{
    "synthdef": {
        "hash": "da0982184cc8fa54cf9d288a0fe1f6ca",
        "name": "default",
        "parameters": {
            "amplitude": {
                "range": [
                    0,
                    1
                ],
                "rate": "control",
                "unit": null,
                "value": 0.1
            },
            "frequency": {
                "range": [
                    0,
                    1
                ],
                "rate": "control",
                "unit": null,
                "value": 440.0
            },
            "gate": {
                "range": [
                    0,
                    1
                ],
                "rate": "control",
                "unit": null,
                "value": 1.0
            },
            "out": {
                "range": [
                    0,
                    1
                ],
                "rate": "scalar",
                "unit": null,
                "value": 0.0
            },
            "pan": {
                "range": [
                    0,
                    1
                ],
                "rate": "control",
                "unit": null,
                "value": 0.5
            }
        }
    }
}

Special methods

SynthDef.__eq__(expr)[source]
(SupriyaObject).__format__(format_specification='')

Formats Supriya object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

SynthDef.__graph__()[source]

Graphs SynthDef.

>>> print(synthdef.__graph__())
digraph synthdef_default {
    graph [bgcolor=transparent,
        color=lightslategrey,
        dpi=72,
        fontname=Arial,
        outputorder=edgesfirst,
        overlap=prism,
        penwidth=2,
        rankdir=LR,
        ranksep=1,
        splines=spline,
        style="dotted, rounded"];
    node [fontname=Arial,
        fontsize=12,
        penwidth=2,
        shape=Mrecord,
        style="filled, rounded"];
    edge [penwidth=2];
    ugen_0 [fillcolor=lightsalmon2,
        label="<f_0> Control\n(scalar) | { { <f_1_0_0> out:\n0.0 } }"];
    ugen_1 [fillcolor=lightgoldenrod2,
        label="<f_0> Control\n(control) | { { <f_1_0_0> amplitude:\n0.1 | <f_1_0_1> frequency:\n440.0 | <f_1_0_2> gate:\n1.0 | <f_1_0_3> pan:\n0.5 } }"];
    ugen_10 [fillcolor=lightsteelblue2,
        label="<f_0> Sum3\n(audio) | { { <f_1_0_0> input_one | <f_1_0_1> input_two | <f_1_0_2> input_three } | { <f_1_1_0> 0 } }"];
    ugen_11 [fillcolor=lightsteelblue2,
        label="<f_0> BinaryOpUGen\n[MULTIPLICATION]\n(audio) | { { <f_1_0_0> left | <f_1_0_1> right:\n0.3 } | { <f_1_1_0> 0 } }"];
    ugen_12 [fillcolor=lightsalmon2,
        label="<f_0> Rand\n(scalar) | { { <f_1_0_0> minimum:\n4000.0 | <f_1_0_1> maximum:\n5000.0 } | { <f_1_1_0> 0 } }"];
    ugen_13 [fillcolor=lightsalmon2,
        label="<f_0> Rand\n(scalar) | { { <f_1_0_0> minimum:\n2500.0 | <f_1_0_1> maximum:\n3200.0 } | { <f_1_1_0> 0 } }"];
    ugen_14 [fillcolor=lightgoldenrod2,
        label="<f_0> XLine\n(control) | { { <f_1_0_0> start | <f_1_0_1> stop | <f_1_0_2> duration:\n1.0 | <f_1_0_3> done_action:\n0.0 } | { <f_1_1_0> 0 } }"];
    ugen_15 [fillcolor=lightsteelblue2,
        label="<f_0> LPF\n(audio) | { { <f_1_0_0> source | <f_1_0_1> frequency } | { <f_1_1_0> 0 } }"];
    ugen_16 [fillcolor=lightsteelblue2,
        label="<f_0> BinaryOpUGen\n[MULTIPLICATION]\n(audio) | { { <f_1_0_0> left | <f_1_0_1> right } | { <f_1_1_0> 0 } }"];
    ugen_17 [fillcolor=lightsteelblue2,
        label="<f_0> BinaryOpUGen\n[MULTIPLICATION]\n(audio) | { { <f_1_0_0> left | <f_1_0_1> right } | { <f_1_1_0> 0 } }"];
    ugen_18 [fillcolor=lightsteelblue2,
        label="<f_0> Pan2\n(audio) | { { <f_1_0_0> source | <f_1_0_1> position | <f_1_0_2> level:\n1.0 } | { <f_1_1_0> 0 | <f_1_1_1> 1 } }"];
    ugen_19 [fillcolor=lightsteelblue2,
        label="<f_0> OffsetOut\n(audio) | { { <f_1_0_0> bus | <f_1_0_1> source | <f_1_0_2> } }"];
    ugen_2 [fillcolor=lightsteelblue2,
        label="<f_0> VarSaw\n(audio) | { { <f_1_0_0> frequency | <f_1_0_1> initial_phase:\n0.0 | <f_1_0_2> width:\n0.3 } | { <f_1_1_0> 0 } }"];
    ugen_3 [fillcolor=lightgoldenrod2,
        label="<f_0> Linen\n(control) | { { <f_1_0_0> gate | <f_1_0_1> attack_time:\n0.01 | <f_1_0_2> sustain_level:\n0.7 | <f_1_0_3> release_time:\n0.3 | <f_1_0_4> done_action:\n2.0 } | { <f_1_1_0> 0 } }"];
    ugen_4 [fillcolor=lightsalmon2,
        label="<f_0> Rand\n(scalar) | { { <f_1_0_0> minimum:\n-0.4 | <f_1_0_1> maximum:\n0.0 } | { <f_1_1_0> 0 } }"];
    ugen_5 [fillcolor=lightgoldenrod2,
        label="<f_0> BinaryOpUGen\n[ADDITION]\n(control) | { { <f_1_0_0> left | <f_1_0_1> right } | { <f_1_1_0> 0 } }"];
    ugen_6 [fillcolor=lightsteelblue2,
        label="<f_0> VarSaw\n(audio) | { { <f_1_0_0> frequency | <f_1_0_1> initial_phase:\n0.0 | <f_1_0_2> width:\n0.3 } | { <f_1_1_0> 0 } }"];
    ugen_7 [fillcolor=lightsalmon2,
        label="<f_0> Rand\n(scalar) | { { <f_1_0_0> minimum:\n0.0 | <f_1_0_1> maximum:\n0.4 } | { <f_1_1_0> 0 } }"];
    ugen_8 [fillcolor=lightgoldenrod2,
        label="<f_0> BinaryOpUGen\n[ADDITION]\n(control) | { { <f_1_0_0> left | <f_1_0_1> right } | { <f_1_1_0> 0 } }"];
    ugen_9 [fillcolor=lightsteelblue2,
        label="<f_0> VarSaw\n(audio) | { { <f_1_0_0> frequency | <f_1_0_1> initial_phase:\n0.0 | <f_1_0_2> width:\n0.3 } | { <f_1_1_0> 0 } }"];
    ugen_0:f_1_0_0:e -> ugen_19:f_1_0_0:w [color=salmon];
    ugen_1:f_1_0_0:e -> ugen_17:f_1_0_1:w [color=goldenrod];
    ugen_1:f_1_0_1:e -> ugen_2:f_1_0_0:w [color=goldenrod];
    ugen_1:f_1_0_1:e -> ugen_5:f_1_0_0:w [color=goldenrod];
    ugen_1:f_1_0_1:e -> ugen_8:f_1_0_0:w [color=goldenrod];
    ugen_1:f_1_0_2:e -> ugen_3:f_1_0_0:w [color=goldenrod];
    ugen_1:f_1_0_3:e -> ugen_18:f_1_0_1:w [color=goldenrod];
    ugen_10:f_1_1_0:e -> ugen_11:f_1_0_0:w [color=steelblue];
    ugen_11:f_1_1_0:e -> ugen_15:f_1_0_0:w [color=steelblue];
    ugen_12:f_1_1_0:e -> ugen_14:f_1_0_0:w [color=salmon];
    ugen_13:f_1_1_0:e -> ugen_14:f_1_0_1:w [color=salmon];
    ugen_14:f_1_1_0:e -> ugen_15:f_1_0_1:w [color=goldenrod];
    ugen_15:f_1_1_0:e -> ugen_16:f_1_0_0:w [color=steelblue];
    ugen_16:f_1_1_0:e -> ugen_17:f_1_0_0:w [color=steelblue];
    ugen_17:f_1_1_0:e -> ugen_18:f_1_0_0:w [color=steelblue];
    ugen_18:f_1_1_0:e -> ugen_19:f_1_0_1:w [color=steelblue];
    ugen_18:f_1_1_1:e -> ugen_19:f_1_0_2:w [color=steelblue];
    ugen_2:f_1_1_0:e -> ugen_10:f_1_0_0:w [color=steelblue];
    ugen_3:f_1_1_0:e -> ugen_16:f_1_0_1:w [color=goldenrod];
    ugen_4:f_1_1_0:e -> ugen_5:f_1_0_1:w [color=salmon];
    ugen_5:f_1_1_0:e -> ugen_6:f_1_0_0:w [color=goldenrod];
    ugen_6:f_1_1_0:e -> ugen_10:f_1_0_1:w [color=steelblue];
    ugen_7:f_1_1_0:e -> ugen_8:f_1_0_1:w [color=salmon];
    ugen_8:f_1_1_0:e -> ugen_9:f_1_0_0:w [color=goldenrod];
    ugen_9:f_1_1_0:e -> ugen_10:f_1_0_2:w [color=steelblue];
}

Returns Graphviz graph.

SynthDef.__hash__()[source]
SynthDef.__repr__()[source]
SynthDef.__str__()[source]

Gets string representation of synth definition.

>>> from supriya.tools import synthdeftools
>>> from supriya.tools import ugentools
>>> with synthdeftools.SynthDefBuilder() as builder:
...     sin_one = ugentools.SinOsc.ar()
...     sin_two = ugentools.SinOsc.ar(frequency=443)
...     source = sin_one + sin_two
...     out = ugentools.Out.ar(bus=0, source=source)
...
>>> synthdef = builder.build(name='test')
>>> graph(synthdef)  
>>> print(synthdef)
SynthDef test {
    const_0:440.0 -> 0_SinOsc[0:frequency]
    const_1:0.0 -> 0_SinOsc[1:phase]
    const_2:443.0 -> 1_SinOsc[0:frequency]
    const_1:0.0 -> 1_SinOsc[1:phase]
    0_SinOsc[0] -> 2_BinaryOpUGen:ADDITION[0:left]
    1_SinOsc[0] -> 2_BinaryOpUGen:ADDITION[1:right]
    const_1:0.0 -> 3_Out[0:bus]
    2_BinaryOpUGen:ADDITION[0] -> 3_Out[1:source]
}

Returns string.