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 used

  • config (Optional[CoreConfig]) – the active config for this workspace. If None, a copy of the root config is used

  • updates (Optional[dict]) – if given, these are applied to the config

  • dynamicCurve (Optional[DynamicCurve]) – a DynamicCurve used to map amplitude to dynamic expressions

  • active – 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

a4

The reference frequency in this Workspace

active

The currently active workspace.

config

The CoreConfig for this workspace

root

The root workspace.

scorestruct

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

deactivate()

Deactivates this Workspace and sets the previous Workspace as active

getActive()

rtype:

Workspace

getConfig()

Get the active config

getTempo([measureNum])

Get the quarternote tempo at the given measure

isActive()

Is this the active Workspace?

presetsPath()

Returns the path where instrument presets are read/written

recordPath()

The path where temporary recordings are saved

rootConfig()

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:

Workspace

Example

>>> from maelzel.core import *
>>> from pitchtools import *
>>> w = Workspace(updates={'A4': 432}).activate()
>>> n2f("A4")
432
>>> w.deactivate()
>>> n2f("A4")
442
amp2dyn(amp)[source]
Return type:

str

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 scorestruct

  • active – if True, activate the cloned Workspace

Return type:

Workspace

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 getActive()[source]
Return type:

Workspace

static getConfig()[source]

Get the active config

Return type:

CoreConfig

getTempo(measureNum=0)[source]

Get the quarternote tempo at the given measure

Return type:

float

isActive()[source]

Is this the active Workspace?

Return type:

bool

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

static rootConfig()[source]
setDynamicsCurve(shape='expon(0.5)', mindb=-80, maxdb=0)[source]

Set a new dynamics curve for this Workspace

Parameters:
  • shape – the shape of the curve

  • mindb – the db value mapped to the softest dynamic

  • maxdb – the db value mapped to the loudest dynamic

Return type:

Workspace

Returns:

self

setRecordPath(path, persist=False)[source]
Return type:

None