Settings File#
pysndlib can be customized with a settings file – an ordinary python
file that is executed when pysndlib.clm is imported. It is the
analog of clm’s ~/.clm-init.lisp: typically a sequence of
assignments to the default namespace, e.g.:
default.srate = 48000
The file is executed in the pysndlib.clm module namespace, so bare
default.x = ... statements (as well as any ordinary python) work.
It can also be re-loaded at any time with
pysndlib.clm.load_rc():
>>> import pysndlib.clm as clm
>>> clm.load_rc() # search the default locations again
True
>>> clm.load_rc("my_settings.py") # load a specific file
True
load_rc returns True if a file was found and executed.
Where the file can be located#
The first existing file in the following order is used:
Priority |
Location |
Notes |
|---|---|---|
1 |
|
explicit override: a path to any file |
2 |
Windows: |
Roaming profile (fallback: |
2 |
macOS: |
|
2 |
Linux: |
default: |
3 |
|
legacy location; works on every platform |
Errors in the settings file are reported as warnings rather than
breaking the import; a broken file can never make importing pysndlib
fail. Set $PYSNDLIB_RC_STRICT=1 to make errors fatal instead.
Tracebacks name the settings file, so errors are easy to find.
Options#
The settings are attributes of the pysndlib.clm.default
namespace. All of the following can be set in the settings file:
Option |
Default |
Meaning |
|---|---|---|
|
|
default output sampling rate |
|
|
default number of output channels |
|
|
default output sample type |
|
|
default output header type |
|
|
default output file name |
|
platform-dependent (see below) |
player used by |
|
|
default wavetable size |
|
|
file I/O buffer size |
|
|
locsig interpolation type |
|
|
whether output is clipped |
|
|
default for |
|
|
default for |
|
|
verbose output |
|
|
default reverb channel count |
|
|
default reverb instrument parameters |
|
|
default intermediate reverb file |
|
|
remove the intermediate reverb file when done |
The player option#
default.player is invoked as a subprocess to play the rendered
sound when Sound(play=True) (see Sound Context Manager). It can be:
a string: the name of an executable that receives the sound file as its only argument –
'afplay'on macOS,'aplay'on Linux, or any player you have installed (e.g.'ffplay').a list: a command where a
'{file}'element is replaced by the (single-quote escaped) sound file name; if no element uses the placeholder, the file name is appended as the last argument. This form is needed for players with flags, e.g.:default.player = ['ffplay', '-nodisp', '-autoexit', '-loglevel', 'quiet']
The default on Windows is a list-form command that hosts the Windows
Media Player COM engine through PowerShell – it plays float WAVs,
runs headless, and waits for playback to finish. There is no default
player equivalent of afplay/aplay on Windows stock installs,
so the PowerShell command is used; Sound(play=True) raises a
RuntimeError if default.player is set to None.
Examples#
A settings file for 48 kHz output with statistics on:
default.srate = 48000
default.statistics = True
Cross-platform settings (e.g. a different player per OS):
import sys
if sys.platform == 'darwin':
default.player = 'afplay'
elif sys.platform.startswith('linux'):
default.player = 'aplay'
else:
default.player = ['ffplay', '-nodisp', '-autoexit']
Since the file is ordinary python, imports, conditionals, and any other logic are available.
Environment variables#
PYSNDLIB_RCPath to the settings file to use, overriding all locations above.
PYSNDLIB_RC_STRICTSet to
1to make errors in the settings file raise at import time instead of warning.