std
This module contains the most common and basic functions. Those functions are always available and don't require a custom import.
Functions
print( *args )
The standard Python print function.
debug( value )
Similar to print
, but handles musical sequences differently (iterating over them and printing the notes/music events inside them).
discard( value )
Simply consumes the value but does not return it. Useful when the value is a musical expression, since musical expressions that are used as statements are implicitly played.
1 2 3 4 5 6 |
|
While using this function with literal musical values might seem pointless, it can be useful when calling custom functions that might return music but also have some sort of side effects. With discard, we can execute those side effects without playing the music.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
using( variable )
When running code inside a function, any variable assignment is assumed to refer to a local variables (similar to the behavior of functions in Python). However, if we wanted to use a global variable inside our function, we need to specifically state we are using it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
mod ( n : float, d : float )
Calculates the modulo. Similar to the %
python operator.
1 2 |
|
div ( n : float, d : float )
Calculates the integer division. Similar to the //
python operator.
1 2 |
|
ord ( char : str )
Returns an integer corresponding to the character provided.
1 |
|
chr ( n : integer )
Returns the character corresponding to the integer provided.
1 |
|
gettime ()
Return the current timestamp in milliseconds
settime ( time : int )
Set the current timestamp to time
, in milliseconds. Use with care so as to not break the principle or ordered events.
getctx()
Returns the current context object.
1 2 |
|
withctx(ctx, expr)
Evaluates the expression on the second argument with the context provided in the first argument.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
ast ( expr : any )
Instead of evaluating the expression that is passed to it, simply returns the AST Node object of the argument.
1 2 3 4 5 6 |
|
ast_to_code ( node : Node, ident : int = 4 )
Converts an AST node to a string representing the source code. Useful for debugging.
parse ( code : str )
Similar to the ast function, but takes a string instead of an expression. Is useful to create code dynamically at runtime.
1 2 3 4 5 6 |
|
eval ( code : str | Node )
Evaluates a snippet of Musikla code with the current context. If a string is provided, parses it first.
1 2 3 4 5 6 |
|
pyeval ( code : str )
Allows executing arbitrary strings of Python code. Follows the same rules as embedding python expressions, which means Musikla variables can be read from.
1 2 3 4 |
|
pyexec ( code : str )
Allows executing arbitrary strings of Python code. Follows the same rules as embedding python blocks, which means Musikla variables can be read/written to. Also allows exporting functions or other variables from the Python code.
1 2 3 4 5 6 7 |
|
pymodule ( module : str, variables : str | List[str] = none )
Loads a python module. If variables is a string, returns only that symbol. If it is a list, returns a tuple with the symbols.
1 2 3 4 5 6 7 8 |
|
getcwd()
Returns the current working directory