sc3nb.util
Module with utlilty functions - especially for handling code snippets
Module Contents
Function List
Removes all c-style comments from code. |
|
Looks through call stack and finds values of variables. |
|
Replaces python variables with SuperCollider literals in code. |
|
Converts python objects to SuperCollider code literals. |
Content
- sc3nb.util.remove_comments(code: str) str [source]
Removes all c-style comments from code.
This removes //single-line or /* multi-line */ comments.
- Parameters:
- codestr
Code where comments should be removed.
- Returns:
- str
code string without comments
- sc3nb.util.parse_pyvars(code: str, frame_nr: int = 2)[source]
Looks through call stack and finds values of variables.
- Parameters:
- codestr
SuperCollider command to be parsed
- frame_nrint, optional
on which frame to start, by default 2 (grandparent frame)
- Returns:
- dict
{variable_name: variable_value}
- Raises:
- NameError
If the variable value could not be found.
- sc3nb.util.replace_vars(code: str, pyvars: dict) str [source]
Replaces python variables with SuperCollider literals in code.
This replaces the pyvars preceded with ^ in the code with a SC literal. The conversion is done with convert_to_sc.
- Parameters:
- codestr
SuperCollider Code with python injections.
- pyvarsdict
Dict with variable names and values.
- Returns:
- str
Code with injected variables.
- sc3nb.util.convert_to_sc(obj: Any) str [source]
Converts python objects to SuperCollider code literals.
This supports currently:
numpy.ndarray -> SC Array representation
complex type -> SC Complex
- strings -> if starting with sc3: it will be used as SC code
if it starts with a (single escaped backward slash) it will be used as symbol else it will be inserted as string
For unsupported types the __repr__ will be used.
- Parameters:
- objAny
object that should be converted to a SuperCollider code literal.
- Returns:
- str
SuperCollider Code literal