Workspace¶
- class maelzel.core.workspace.Workspace(config=None, scorestruct=None, dynamicCurve=None, updates=None, active=False)[source]¶
Bases:
object
Create a new Workspace
- Parameters:
scorestruct (
Optional
[ScoreStruct
]) – the ScoreStruct. If None, a default scorestruct (4/4, q=60) is usedconfig (
Optional
[CoreConfig
]) – the active config for this workspace. If None, a copy of the root config is usedupdates (
Optional
[dict
]) – if given, these are applied to the configdynamicCurve (
Optional
[DynamicCurve
]) – a DynamicCurve used to map amplitude to dynamic expressionsactive – if True, make this Workpsace active
A Workspace can also be used as a context manager, in which case it will be activated when entering the context and deactivated at exit
from maelzel.core import * scorestruct = ScoreStruct(r''' 4/4, 60 . 3/4 5/8, 72 ''') notes = Chain([Note(m, start=i) for i, m in enumerate(range(60, 72))]) # Create a temporary Workspace with the given scorestruct and a clone # of the active config with Workspace(scorestruct=scorestruct, config=getConfig()) as w: notes.show()
Attributes Summary
The reference frequency in this Workspace
The currently active workspace.
The CoreConfig for this workspace
The root workspace.
The default ScoreSctruct for this Workspace
Methods Summary
activate
()Make this the active Workspace
amp2dyn
(amp)- rtype:
str
clone
([config, scorestruct, active])Clone this Workspace
Deactivates this Workspace and sets the previous Workspace as active
- rtype:
Get the active config
getTempo
([measureNum])Get the quarternote tempo at the given measure
isActive
()Is this the active Workspace?
Returns the path where instrument presets are read/written
The path where temporary recordings are saved
setDynamicsCurve
([shape, mindb, maxdb])Set a new dynamics curve for this Workspace
setRecordPath
(path[, persist])- rtype:
None
Attributes Documentation
- a4¶
The reference frequency in this Workspace
-
active:
Workspace
|None
= Workspace(scorestruct=ScoreStruct(tempo=60, timesig=4/4), config={}, dynamicCurve=DynamicCurve(shape=expon(0.3), mindb=-60.0, maxdb=0.0))¶ The currently active workspace. Never None after the class has been initialized
- config¶
The CoreConfig for this workspace
-
root:
Workspace
|None
= Workspace(scorestruct=ScoreStruct(tempo=60, timesig=4/4), config={}, dynamicCurve=DynamicCurve(shape=expon(0.3), mindb=-60.0, maxdb=0.0))¶ The root workspace. This is the workspace active at the start of a session and is always kept alive since it holds a reference to the root config. It should actually never be None
- scorestruct¶
The default ScoreSctruct for this Workspace
Methods Documentation
- activate()[source]¶
Make this the active Workspace
This method returns self in order to allow chaining
- Return type:
Example
>>> from maelzel.core import * >>> from pitchtools import * >>> w = Workspace(updates={'A4': 432}).activate() >>> n2f("A4") 432 >>> w.deactivate() >>> n2f("A4") 442
- clone(config=None, scorestruct=None, active=False)[source]¶
Clone this Workspace
- Parameters:
config (
Optional
[CoreConfig
]) – the config to use. Leave unset to clone this Workspace’s config.scorestruct (
Optional
[ScoreStruct
]) – if unset, use this Workspace’s scorestructactive – if True, activate the cloned Workspace
- Return type:
- Returns:
the cloned Workspace
Example
>>> from maelzel.core import * >>> myworkspace = getWorkspace().clone() >>> myworkspace.config['A4'] = 432 >>> with myworkspace as w: ... # This will activate the workspace and deactivate it at exit ... # Now do something baroque
- deactivate()[source]¶
Deactivates this Workspace and sets the previous Workspace as active
Note
There is always an active Workspace. An attempt to deactivate the root Workspace will be ignored
- Return type:
None
- Returns:
the now active workspace
- static presetsPath()[source]¶
Returns the path where instrument presets are read/written
- Return type:
str
Example
Running in linux
>>> from maelzel.core import * >>> path = getWorkspace().presetsPath() >>> path '/home/XXX/.local/share/maelzel/core/presets' >>> os.listdir(path) ['.click.yaml', 'click.yaml', 'noise.yaml', 'accordion.yaml', 'piano.yaml', 'voiceclick.yaml']
- recordPath()[source]¶
The path where temporary recordings are saved
We do not use the temporary folder because it is wiped regularly and the user might want to access a recording after rebooting. The returned folder is guaranteed to exist
The default record path can be customized by modifying the config ‘rec.path’
- Return type:
str