PresetDef

class maelzel.core.presetdef.PresetDef(name, code, init='', includes=None, epilogue='', args=None, numsignals=None, numouts=None, description='', builtin=False, properties=None, envelope=True, routing=True, aliases=None)[source]

An instrument preset definition

Normally a user does not create a PresetDef directly. A PresetDef is created when calling defPreset() .

A Preset is aware of the pitch and amplitude of a SynthEvent and generates all the interface code regarding play parameters like panning position, fadetime, fade shape, gain, etc. The user only needs to define the audio generating code and any init code needed (global code needed by the instrument, like soundfiles which need to be loaded, buffers which need to be allocated, etc). A Preset can define any number of extra parameters (transposition, filter cutoff frequency, etc.).

Parameters:
  • name (str) – the name of the preset

  • code (str) – the audio generating code

  • init – any init code (global code)

  • includes (Optional[list[str]]) – #include files

  • epilogue (str) – code to include after any other code. Needed when using turnoff, since calling turnoff in the middle of an instrument can cause undefined behaviour.

  • args (Optional[Dict[str, float]]) – a dict(arg1: value1, arg2: value2, …). Parameter names need to follow csound’s naming: init-only parameters need to start with ‘i’, variable parameters need to start with ‘k’, string parameters start with ‘S’.

  • description – a description of this instr definition

  • envelope – If True, apply an envelope as determined by the fadein/fadeout play arguments.

  • routing – if True code is generated to output the audio to its corresponding channel. If False the audiogen code should be responsible for applying panning and sending the audio to an output channel, bus, etc.

  • aliases (Optional[dict[str, str]]) – an optional dict mapping alias parameters to their real name as csound variables. This is used, for example, in a Clip to provide coherence between names of python parameters (‘speed’) and their controls within the generated synth (‘kspeed’).

Example

>>> from maelzel.core import *
# defPreset returns a PresetDef and makes the preset available for synthesis
>>> defPreset('moogsaw', r'''
... |kcutoff=3000, kresonance=0.9|
... asig = vco2(kamp, kfreq)   ; kamp and kfreq are always available within a preset
... aout1 = moogladder2:a(asig, kcutoff, kresonance)
... ''')
>>> synthgroup = Chord(["4C", "4E", "4G"], 8).play(instr='moogsaw')
>>> synthgroup.automate('kcutoff', (0, 500, synthgroup.dur, 4000))
aliases

Dict mapping aliases to real csound parameters

args: dict[str, float] | None

Named args, if present

body

The body of the instrument with all generated code

code

The original audio code itself

description

An optional description

dynamicParams(aliases=True, aliased=False)[source]

All dynamic params of this preset

This includes the dynamic arguments of the preset plus the builtin arguments common to all presets (position, …)

Parameters:
  • aliases – include aliases

  • aliased – include aliased names

Return type:

dict[str, float | str]

Returns:

a dict of all dynamic params of this preset and their default values

epilogue

Code run after any other code

getInstr()[source]

Returns the csoundengine’s Instr corresponding to this PresetDef

This method is cached, the Instr is constructed only the first time

Return type:

Instr

Returns:

the csoundengine.Instr corresponding to this PresetDef

includes

Include files needed

init

Code run before any instance is created

instrname

The name of the corresponding Instrument

isSoundFont()[source]

Is this Preset based on a soundfont?

Return type:

bool

Returns:

True if this Preset is based on a soundfont

name

Name of this preset

numouts

Number of outputs

numsignals

Number of audio signals used in the audiogen (aout1, aout2, …)

parsedAudiogen: ParsedAudiogen

The parsed audiogen (a ParsedAudiogen instance)

properties: dict[str, Any]

A dict to place user defined properties

routing

Does this PresetDef need routing (panning, output) code to be generated?

save()[source]

Save this preset to disk

All presets are saved to the presets path. Saved presets will be available in a future session :rtype: str

See also

maelzel.core.workspace.presetsPath()

userDefined

Is this PresetDef user defined?