SynthDefFactory

class supriya.tools.synthdeftools.SynthDefFactory(channel_count=1, **kwargs)[source]

A factory class for building SynthDefs with common signal flow structures.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)
>>> synthdef = factory.build()
>>> graph(synthdef)  
>>> synthdef = factory.build(iterations=4)
>>> graph(synthdef)  
>>> synthdef = factory.build(channel_count=2)
>>> graph(synthdef)  

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_synthdeftools { graph [label=synthdeftools]; "supriya.tools.synthdeftools.SynthDefFactory.SynthDefFactory" [color=black, fontcolor=white, group=1, label=<<B>SynthDefFactory</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_systemtools { graph [label=systemtools]; "supriya.tools.systemtools.SupriyaObject.AbstractBase" [color=3, group=2, label=AbstractBase, shape=box]; "supriya.tools.systemtools.SupriyaObject.SupriyaObject" [color=3, group=2, label=SupriyaObject, shape=box]; "supriya.tools.systemtools.SupriyaObject.AbstractBase" -> "supriya.tools.systemtools.SupriyaObject.SupriyaObject"; } "builtins.object" -> "supriya.tools.systemtools.SupriyaObject.AbstractBase"; "supriya.tools.systemtools.SupriyaObject.SupriyaObject" -> "supriya.tools.synthdeftools.SynthDefFactory.SynthDefFactory"; }

Bases

Attribute summary

build([name]) Build the SynthDef.
with_channel_count(channel_count) Return a new factory configured with channel_count.
with_feedback_loop([block_function]) Return a new factory configured with a feedback loop.
with_gate([attack_time, release_time]) Return a new factory configured with a gate.
with_initial_state(**state) Return a new factory configured with an inital state comprised of key/value pairs.
with_input([windowed]) Return a new factory configured with a bus input.
with_output([crossfaded, leveled, ...]) Return a new factory configured with a bus output.
with_parameter_block(block_function) Return a new factory configured with a parameter block function.
with_rand_id([rand_id]) Return a new factory configured with a random number generator ID.
with_signal_block(block_function) Return a new factory configured with an additional signal block function.
with_silence_detection() Return a new factory configured with silence detection.
__eq__(expr) Is true when ID of expr equals ID of Supriya object.
__format__([format_specification]) Formats Supriya object.
__hash__() Hashes Supriya object.
__repr__() Gets interpreter representation of Supriya object.

Methods

SynthDefFactory.build(name=None, **kwargs)[source]

Build the SynthDef.

SynthDefFactory.with_channel_count(channel_count)[source]

Return a new factory configured with channel_count.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with 4 channels:

>>> factory = factory.with_channel_count(4)
>>> synthdef = factory.build()
>>> graph(synthdef)  

Channel count can be overridden at build time:

>>> synthdef = factory.build(channel_count=3)
>>> graph(synthdef)  
SynthDefFactory.with_feedback_loop(block_function=None)[source]

Return a new factory configured with a feedback loop.

Feedback block functions follow the same guidelines as other signal block functions.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with a basic feedback loop:

>>> factory = factory.with_feedback_loop()
>>> synthdef = factory.build()
>>> graph(synthdef)  

Configure the factory with a modulated feedback loop via a signal block function:

>>> def feedback_block(builder, source, state):
...     return source * ugentools.SinOsc.kr(frequency=0.3)
... 
>>> factory = factory.with_feedback_loop(feedback_block)
>>> synthdef = factory.build()
>>> graph(synthdef)  
SynthDefFactory.with_gate(attack_time=0.02, release_time=0.02)[source]

Return a new factory configured with a gate.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with a gate envelope and corresponding gate parameter:

>>> factory = factory.with_gate()
>>> synthdef = factory.build()
>>> graph(synthdef)  
SynthDefFactory.with_initial_state(**state)[source]

Return a new factory configured with an inital state comprised of key/value pairs.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with an initial state consisting of a single key/value pair which can be accessed in the previously configured signal block function:

>>> factory = factory.with_initial_state(iterations=4)
>>> synthdef = factory.build()
>>> graph(synthdef)  
SynthDefFactory.with_input(windowed=False)[source]

Return a new factory configured with a bus input.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_signal_block(signal_block)
>>> factory = factory.with_output()

Configure the factory with a basic bus input:

>>> factory = factory.with_input()
>>> synthdef = factory.build()
>>> graph(synthdef)  

Configure the factory with a windowed bus input:

>>> factory = factory.with_input(windowed=True)
>>> synthdef = factory.build()
>>> graph(synthdef)  

A factory configured with both a windowed bus input and output will re-use the windowing signal:

>>> factory = factory.with_input(windowed=True)
>>> factory = factory.with_output(windowed=True)
>>> synthdef = factory.build()
>>> graph(synthdef)  
SynthDefFactory.with_output(crossfaded=False, leveled=False, replacing=False, windowed=False)[source]

Return a new factory configured with a bus output.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with a basic bus output:

>>> factory = factory.with_output()
>>> synthdef = factory.build()
>>> graph(synthdef)  

Configure the factory with a windowed bus output:

>>> factory = factory.with_output(windowed=True)
>>> synthdef = factory.build()
>>> graph(synthdef)  

Configure the factory with a crossfade-able bus output:

>>> factory = factory.with_output(crossfaded=True)
>>> synthdef = factory.build()
>>> graph(synthdef)  

Configure the factory with a basic bus output preceded by an amplitude level control:

>>> factory = factory.with_output(leveled=True)
>>> synthdef = factory.build()
>>> graph(synthdef)  

A factory configured with a crossfaded and windowed bus output will use the windowing signal to control the crossfade:

>>> factory = factory.with_output(
...     crossfaded=True,
...     windowed=True,
...     )
>>> synthdef = factory.build()
>>> graph(synthdef)  

A level-control can be combined with the windowing and crossfading:

>>> factory = factory.with_output(
...     crossfaded=True,
...     leveled=True,
...     windowed=True,
...     )
>>> synthdef = factory.build()
>>> graph(synthdef)  

A factory configured with both a windowed bus input and output will re-use the windowing signal:

>>> factory = factory.with_input(windowed=True)
>>> synthdef = factory.build()
>>> graph(synthdef)  
SynthDefFactory.with_parameter_block(block_function)[source]

Return a new factory configured with a parameter block function.

Use parameter block functions to build repetitive sets of SynthDef parameters, e.g. each set of band parameters for a multi-band compressor.

Parameter block functions take two parameters:

builder
the SynthDef builder instance
state
a dictionary of arbitrary key/value pairs for parameterizing the signal and parameter block functions

The return values of parameter block functions are ignored.

A factory configured to build multi-band compressor SynthDefs, using frequency bands split at frequencies:

>>> def parameter_block(builder, state):
...     frequencies = state['frequencies']
...     band_count = len(frequencies) + 1
...     for i in range(band_count):
...         band_name = 'band_{}_'.format(i + 1)
...         builder._add_parameter(band_name + 'pregain', 0)
...         builder._add_parameter(band_name + 'clamp_time', 0.01)
...         builder._add_parameter(band_name + 'relax_time', 0.1)
...         builder._add_parameter(band_name + 'threshold', -6)
...         builder._add_parameter(band_name + 'slope_above', 0.5)
...         builder._add_parameter(band_name + 'slope_below', 1.0)
...         builder._add_parameter(band_name + 'postgain', 0)
... 
>>> def signal_block(builder, source, state):
...     bands = []
...     frequencies = state['frequencies']
...     for frequency in frequencies:
...         band = ugentools.LPF.ar(source=source, frequency=frequency)
...         bands.append(band)
...         source -= band
...     bands.append(source)
...     compressors = []
...     for i, band in enumerate(bands):
...         band_name = 'band_{}_'.format(i + 1)
...         band *= builder[band_name + 'pregain'].db_to_amplitude()
...         band = ugentools.CompanderD.ar(
...             source=band,
...             clamp_time=builder[band_name + 'clamp_time'],
...             relax_time=builder[band_name + 'relax_time'],
...             slope_above=builder[band_name + 'slope_above'],
...             slope_below=builder[band_name + 'slope_below'],
...             threshold=builder[band_name + 'threshold'].db_to_amplitude(),
...             )
...         band *= builder[band_name + 'postgain'].db_to_amplitude()
...         compressors.extend(band)
...     source = ugentools.Mix.multichannel(
...         compressors,
...         state['channel_count'],
...         )
...     return source
... 
>>> factory = synthdeftools.SynthDefFactory()
>>> factory = factory.with_initial_state(frequencies=(300, 1200, 9600))
>>> factory = factory.with_parameter_block(parameter_block)
>>> factory = factory.with_input()
>>> factory = factory.with_signal_block(signal_block)
>>> factory = factory.with_output(crossfaded=True)
>>> synthdef = factory.build()
>>> graph(synthdef)  

The above factory can be parameterized to use smaller or larger numbers of bands during the build stage:

>>> frequencies = (150, 300, 600, 1200, 2400, 4800, 9600)
>>> synthdef = factory.build(frequencies=frequencies)
>>> graph(synthdef)  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/joberholtzer/.virtualenvs/supriya/lib/python3.5/site-packages/abjad/tools/abjadbooktools/CodeBlock.py", line 438, in graph
    image_render_specifier=self.image_render_specifier,
  File "/Users/joberholtzer/.virtualenvs/supriya/lib/python3.5/site-packages/abjad/tools/abjadbooktools/GraphvizOutputProxy.py", line 223, in __init__
    graphviz_graph = pickle.loads(pickle.dumps(payload.__graph__()))
  File "/Users/joberholtzer/.virtualenvs/supriya/lib/python3.5/site-packages/abjad/tools/abctools/AbjadObject.py", line 56, in __getstate__
    for class_ in type(self).__mro__:
RecursionError: maximum recursion depth exceeded while calling a Python object
SynthDefFactory.with_rand_id(rand_id=0)[source]

Return a new factory configured with a random number generator ID.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with a random number generator ID, defaulting to 23:

>>> factory = factory.with_rand_id(rand_id=23)
>>> synthdef = factory.build()
>>> graph(synthdef)  
SynthDefFactory.with_signal_block(block_function)[source]

Return a new factory configured with an additional signal block function.

Signal block functions take three parameters:

builder
the SynthDef builder instance
source
a UGenMethodMixin representing the signal flow
state
a dictionary of arbitrary key/value pairs for parameterizing the signal and parameter block functions

Signal block functions should return a UGenMethodMixin.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with an additional signal block:

>>> def signal_block_post(builder, source, state):
...     source = ugentools.LeakDC.ar(source=source)
...     source = ugentools.Limiter.ar(
...         duration=ugentools.Rand.ir(0.005, 0.015),
...         source=source,
...         )
...     return source
... 
>>> factory = factory.with_signal_block(signal_block_post)
>>> synthdef = factory.build()
>>> graph(synthdef)  
SynthDefFactory.with_silence_detection()[source]

Return a new factory configured with silence detection.

>>> factory = synthdeftools.SynthDefFactory()
>>> def signal_block(builder, source, state):
...     iterations = state.get('iterations') or 2
...     for _ in range(iterations):
...         source = ugentools.AllpassC.ar(
...             decay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             delay_time=ugentools.ExpRand.ir(0.01, 0.1),
...             source=source,
...             maximum_delay_time=0.1,
...             )
...     return source
... 
>>> factory = factory.with_input()
>>> factory = factory.with_output()
>>> factory = factory.with_signal_block(signal_block)

Configure the factory with silence detection.

>>> factory = factory.with_silence_detection()
>>> synthdef = factory.build()
>>> graph(synthdef)  

Silence detection is applied before any output leveling or windowing.

>>> factory = factory.with_output(
...     leveled=True,
...     windowed=True,
...     )
>>> synthdef = factory.build()
>>> graph(synthdef)  

Special methods

(SupriyaObject).__eq__(expr)

Is true when ID of expr equals ID of Supriya object. Otherwise false.

Returns boolean.

(SupriyaObject).__format__(format_specification='')

Formats Supriya object.

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

Returns string.

(SupriyaObject).__hash__()

Hashes Supriya object.

Required to be explicitely re-defined on Python 3 if __eq__ changes.

Returns integer.

(SupriyaObject).__repr__()

Gets interpreter representation of Supriya object.

Returns string.