render¶
- maelzel.core.offline.render(outfile='', events=None, sr=None, wait=None, ksmps=None, verbose=None, nchnls=None, workspace=None, tail=None, run=True, endtime=0.0, show=False, tempfolder='', fmt='wav', **kws)[source]¶
Render to a soundfile / creates a context manager to render offline
When not used as a context manager the events / objects must be given. The soundfile will be generated immediately.
When used as a context manager the
events
argument should be left unset. Within this context any call tomaelzel.core.MObj.play()
will be redirected to the offline renderer and at the exit of the context all events will be rendered to a soundfile. Also, any pure csound events scheduled viaplaySession()._sched(...)
will also be redirected to be renderer offline.This enables to use the exact same code when doing realtime and offline rendering.
- Parameters:
outfile – the generated file. If None, a file inside the recording path is created (see
recordPath
). Use “?” to save via a GUI dialog orevents (
Optional
[Sequence
[Union
[SynthEvent
,MObj
,Event
,Sequence
[MObj
|SynthEvent
]]]]) – the events/objects to play. This can only be left unset if usingrender
as a context manager (see example).sr (
Optional
[int
]) – sample rate of the soundfile (config ‘rec.sr’)ksmps (
Optional
[int
]) – number of samples per cycle (config ‘rec.ksmps’)nchnls (
Optional
[int
]) – number of channels of the rendered soundfilewait (
Optional
[bool
]) – if True, wait until recording is finished. If None, use the config ‘rec.blocking’verbose (
Optional
[bool
]) – if True, show the output generated by the csound subprocesstail (
Optional
[float
]) – extra time added at the end of the render, usefull when rendering reverbs or long decaying sound. If None, uses use config ‘rec.extratime’run – if True, perform the render itself
tail – extra time at the end, usefull when rendering reverbs or long deaying sounds
endtime – if given, sets the end time of the rendered segment. A value of 0. indicates to render everything. A value is needed if there are endless events
workspace (
Optional
[Workspace
]) – if given, this workspace overrides the active workspace
- Return type:
- Returns:
the
OfflineRenderer
used to render the events. If the outfile was not given, the path of the recording can be retrieved fromrenderer.outfile
Example
>>> a = Chord("A4 C5", start=1, dur=2) >>> b = Note("G#4", dur=4) >>> render("out.wav", events=[ ... a.events(chain=1), ... b.events(chan=2, gain=0.2) ... ])
This function can be also used as a context manager, similar to
maelzel.playback.play()
. In that caseevents
must beNone
:>>> from maelzel.core import * >>> scale = Chain([Note(n) for n in "4C 4D 4E 4F 4G".split()]) >>> playSession().defInstr('reverb', r''' ... |kfeedback=0.6| ... amon1, amon2 monitor ... a1, a2 reverbsc amon1, amon2, kfeedback, 12000, sr, 0.6 ... outch 1, a1-amon1, 2, a2-amon2 ... ''') >>> with render() as r: ... scale.play('.piano') # .play here is redirected to the offline renderer ... r.sched('reverb', priority=2)
See also
OfflineRenderer
,maelzel.playback.play()