The Workspace Model¶
Workspace¶
maelzel.core is organized on the idea of a Workspace
.
A workspace contains the current state: the active config, the active scorestrucutre,
a playback engine, etc. Many actions, like note playback, notation rendering, etc.,
use the active workspace to determine tempo, score structure, default playback instrument,
etc.
At any moment there is always an active workspace. This can be accessed via
getWorkspace()
.
At the start of a session a workspace (the ‘root’ workspace) is created, based on the root
config and a default score structure.
config: Active Configuration¶
The active configuration determines many aspects of maelzel, like the default instrument used for playback, the audio backend used, the quantization complexity used when rendering a score, etc.
At module initialization a rootConfig
is created. This is an instance of
CoreConfig
, updated with any customizations persisted
from previous sessions (see CoreConfig.save()
).
See Also
Example Notebooks¶
Example¶
A simple chromatic scale. The default Workspace includes a default ScoreStruct with a time signature
of 4/4
and a tempo of quarternote=60
from maelzel.core import *
notes = Chain([Note(m, start=i) for i, m in enumerate(range(60, 72))])
notes.show()
You can either modify the current Workspace, for example, by setting a new ScoreStruct via
setScoreStruct()
or setting its scorestruct
attribute:
setScoreStruct(ScoreStruct.fromTimesig((3, 4), quarterTempo=72))
# The same can be achieved by:
w = getWorkspace()
w.scorestruct = ScoreStruct.fromTimesig((3, 4), quarterTempo=72)
notes
For specific tasks it might be useful to create a Workspace with custom settings. In the following example we create a new Workpsace using the current ScoreStruct and a modified configuration.
w = Workspace(updates={'play.instr': 'piano'},
scorestruct=getScoreStruct(),
active=True)
notes.play()
# Deactivate will set the previous Workspace as active
w.deactivate()
A temporary Workpsace can be created as a context manager. In this case an ad-hoc score struct and a copy of the active config are used:
scorestruct = ScoreStruct(r'''
4/4, 60
3/4
5/8, 72
6/8
''')
with Workspace(scorestruct=scorestruct, config=getConfig()) as w:
notes.show()
Functions¶
Get the active workspace |
|
Return the active config. |
|
|
Activate this config |
Returns the active ScoreStruct (which defines tempo and time signatures) |
|
|
Sets the current score structure |
|
Set the current tempo. |
Classes¶
|
Create a new Workspace |