sc3nb.sc_objects.synthdef

Module to for using SuperCollider SynthDefs and Synths in Python

Module Contents

Class List

SynthDefinitionCommand

OSC Commands for Synth Definitions

SynthDef

Wrapper for SuperCollider SynthDef

Content

class sc3nb.sc_objects.synthdef.SynthDefinitionCommand[source]

Bases: str, enum.Enum

OSC Commands for Synth Definitions

Initialize self. See help(type(self)) for accurate signature.

RECV = '/d_recv'[source]
LOAD = '/d_load'[source]
LOAD_DIR = '/d_loadDir'[source]
FREE = '/d_free'[source]
class sc3nb.sc_objects.synthdef.SynthDef(name: str, definition: str, sc: sc3nb.sc.SC | None = None)[source]

Wrapper for SuperCollider SynthDef

Create a dynamic synth definition in sc.

Parameters:
namestring

default name of the synthdef creation. The naming convention will be name+int, where int is the amount of already created synths of this definition

definitionstring

Pass the default synthdef definition here. Flexible content should be in double brackets (”…{{flexibleContent}}…”). This flexible content, you can dynamic replace with set_context()

scSC object

SC instance where the synthdef should be created, by default use the default SC instance

synth_descs[source]
synth_defs[source]

Overview:

get_description

Get Synth description

send

Send a SynthDef as bytes.

load

Load SynthDef file at path.

load_dir

Load all SynthDefs from directory.

reset

Reset the current synthdef configuration to the self.definition value.

set_context

Set context in SynthDef.

set_contexts

Set multiple values at onces when you give a dictionary.

unset_remaining

This method will remove all existing placeholders in the current def.

add

This method will add the current_def to SuperCollider.s

free

Free this SynthDef from the server.

__repr__

Return repr(self).

classmethod get_description(name: str, lang: sc3nb.sclang.SCLang | None = None) Dict[str, sc3nb.sclang.SynthArgument] | None[source]

Get Synth description

Parameters:
namestr

name of SynthDef

Returns:
Dict

dict with SynthArguments

classmethod send(synthdef_bytes: bytes, server: sc3nb.sc_objects.server.SCServer | None = None)[source]

Send a SynthDef as bytes.

Parameters:
synthdef_bytesbytes

SynthDef bytes

waitbool

If True wait for server reply.

serverSCServer, optional

Server instance that gets the SynthDefs, by default use the SC default server

classmethod load(synthdef_path: str, server: sc3nb.sc_objects.server.SCServer | None = None)[source]

Load SynthDef file at path.

Parameters:
synthdef_pathstr

Path with the SynthDefs

serverSCServer, optional

Server that gets the SynthDefs, by default use the SC default server

classmethod load_dir(synthdef_dir: str | None = None, completion_msg: bytes | None = None, server: sc3nb.sc_objects.server.SCServer | None = None)[source]

Load all SynthDefs from directory.

Parameters:
synthdef_dirstr, optional

directory with SynthDefs, by default sc3nb default SynthDefs

completion_msgbytes, optional

Message to be executed by the server when loaded, by default None

serverSCServer, optional

Server that gets the SynthDefs, by default use the SC default server

reset() SynthDef[source]

Reset the current synthdef configuration to the self.definition value.

After this you can restart your configuration with the same root definition

Returns:
object of type SynthDef

the SynthDef object

set_context(searchpattern: str, value) SynthDef[source]

Set context in SynthDef.

This method will replace a given key (format: “…{{key}}…”) in the synthdef definition with the given value.

Parameters:
searchpatternstring

search pattern in the current_def string

valuestring or something with can parsed to string

Replacement of search pattern

Returns:
selfobject of type SynthDef

the SynthDef object

set_contexts(dictionary: Dict[str, Any]) SynthDef[source]

Set multiple values at onces when you give a dictionary.

Because dictionaries are unsorted, keep in mind, that the order is sometimes ignored in this method.

Parameters:
dictionarydict

{searchpattern: replacement}

Returns:
selfobject of type SynthDef

the SynthDef object

unset_remaining() SynthDef[source]

This method will remove all existing placeholders in the current def.

You can use this at the end of definition to make sure, that your definition is clean. Hint: This method will not remove pyvars

Returns:
selfobject of type SynthDef

the SynthDef object

add(pyvars=None, name: str | None = None, server: sc3nb.sc_objects.server.SCServer | None = None) str[source]

This method will add the current_def to SuperCollider.s

If a synth with the same definition was already in sc, this method will only return the name.

Parameters:
pyvarsdict

SC pyvars dict, to inject python variables

namestr, optional

name which this SynthDef will get

serverSCServer, optional

Server where this SynthDef will be send to, by default use the SC default server

Returns:
str

Name of the SynthDef

free() SynthDef[source]

Free this SynthDef from the server.

Returns:
selfobject of type SynthDef

the SynthDef object

__repr__()[source]

Return repr(self).