sc3nb.sclang
Module for handling a SuperCollider language (sclang) process.
Module Contents
Class List
Synth argument, rate and default value |
|
Class to control the SuperCollider Language Interpreter (sclang). |
Content
- exception sc3nb.sclang.SCLangError(message, sclang_output=None)[source]
Bases:
ExceptionException for Errors related to SuperColliders sclang.
Initialize self. See help(type(self)) for accurate signature.
- class sc3nb.sclang.SCLang[source]
Class to control the SuperCollider Language Interpreter (sclang).
Creates a python representation of sclang.
- Raises:
- NotImplementedError
When an unsupported OS was found.
- process: sc3nb.process_handling.Process = None[source]
- _server: sc3nb.sc_objects.server.SCServer | None = None[source]
Overview:
Start and initilize the sclang process.
Initialize sclang for sc3nb usage.
Load SynthDef files from path.
Kill this sclang instance.
Send code to sclang to execute it.
cmd with verbose=True
cmd with verbose=False, i.e. silent
cmd with get_result=True
Reads SuperCollider output from the process output queue.
Empties sc output queue.
Get a SynthDesc like description via sclang's global SynthDescLib.
Connect this sclang instance to the SuperCollider server.
- start(sclang_path: str | None = None, console_logging: bool = True, kill_others: bool = True, allowed_parents: Sequence[str] = ALLOWED_PARENTS, timeout: float = 10) None[source]
Start and initilize the sclang process.
This will also kill sclang processes that does not have allowed parents.
- Parameters:
- sclang_pathOptional[str], optional
Path with the sclang executable, by default None
- console_loggingbool, optional
If True log sclang output to console, by default True
- allowed_parentsSequence[str], optional
parents name of processes to keep, by default ALLOWED_PARENTS
- timeoutfloat, optional
timeout in seconds for starting the executable, by default 10
- Raises:
- SCLangError
When starting or initilizing sclang failed.
- init()[source]
Initialize sclang for sc3nb usage.
This will register the /return callback in sclang and load the SynthDefs from sc3nb.
This is done automatically by running start.
- load_synthdefs(synthdefs_path: str | None = None) None[source]
Load SynthDef files from path.
- Parameters:
- synthdefs_pathstr, optional
Path where the SynthDef files are located. If no path provided, load default sc3nb SynthDefs.
- cmd(code: str, pyvars: dict | None = None, verbose: bool = True, discard_output: bool = True, get_result: bool = False, print_error: bool = True, get_output: bool = False, timeout: int = 1) Any[source]
Send code to sclang to execute it.
This also allows to get the result of the code or the corresponding output.
- Parameters:
- codestr
SuperCollider code to execute.
- pyvarsdict, optional
Dictionary of name and value pairs of python variables that can be injected via ^name, by default None
- verbosebool, optional
If True print output, by default True
- discard_outputbool, optional
If True clear output buffer before passing command, by default True
- get_resultbool, optional
If True receive and return the evaluation result from sclang, by default False
- print_errorbool, optional
If this and get_result is True and code execution fails the output from sclang will be printed.
- get_outputbool, optional
If True return output. Does not override get_result If verbose this will be True, by default False
- timeoutint, optional
Timeout in seconds for code execution return result, by default 1
- Returns:
- Any
- if get_result=True,
Result from SuperCollider code, not all SC types supported. When type is not understood this will return the datagram from the OSC packet.
- if get_output or verbose
Output from SuperCollider code.
- if get_output and get_result=True
(result, output)
- else
None
- Raises:
- RuntimeError
If get_result is True but no OSCCommunication instance is set.
- SCLangError
When an error with sclang occurs.
- read(expect: str | None = None, timeout: float = 1, print_error: bool = True) str[source]
Reads SuperCollider output from the process output queue.
- Parameters:
- expectOptional[str], optional
Try to read this expected string, by default None
- timeoutfloat, optional
How long we try to read the expected string in seconds, by default 1
- print_errorbool, optional
If True this will print a message when timed out, by default True
- Returns:
- str
output from sclang process.
- Raises:
- timeout
If expected output string could not be read before timeout.
- get_synth_description(synth_def)[source]
Get a SynthDesc like description via sclang’s global SynthDescLib.
- Parameters:
- synth_defstr
SynthDef name
- Returns:
- dict
{argument_name: SynthArgument(rate, default)}
- Raises:
- ValueError
When SynthDesc of synth_def can not be found.
- connect_to_server(server: sc3nb.sc_objects.server.SCServer | None = None)[source]
Connect this sclang instance to the SuperCollider server.
This will set Server.default and s to the provided remote server.
- Parameters:
- serverSCServer, optional
SuperCollider server to connect. If None try to reconnect.
- Raises:
- ValueError
If something different from an SCServer or None was provided
- SCLangError
If sclang failed to register to the server.