music.Sequencer¶
- class music.Sequencer(sample_rate=44100, events=<factory>)[source]¶
Bases:
objectSchedules notes and renders them as audio.
- Attributes:
- sample_rate
integer The sampling frequency in Hertz, used for every note rendered and for turning each event’s start time into a sample offset.
- events
listofNoteEvent The scheduled notes. Normally built with
add_note()rather than passed in, and rendered in order of their start times rather than the order they were added.
- sample_rate
- Raises:
ValueErrorIf
sample_rateis not positive. At zero every note rendered as no samples, and the sequence as silence of no length.
- Parameters:
See also
music.StimulationSessionphases in sequence rather than notes at offsets, for stimulation protocols.
Examples
>>> seq = Sequencer() >>> for i, freq in enumerate([440, 550, 660]): ... seq.add_note(freq, start=i * 0.25, duration=1.0) >>> len(seq.events) 3 >>> seq.write("chord.wav")
- __init__(sample_rate=44100, events=<factory>)¶
Methods
__init__([sample_rate, events])add_note(freq, start, duration[, ...])Add a note event to the sequencer.
render()Render all scheduled events and return the audio array.
write(filename[, bit_depth])Write the rendered audio to a WAV file.
Attributes
- add_note(freq, start, duration, vibrato_freq=0.0, max_pitch_dev=0.0, adsr_params=None, spatial=None)[source]¶
Add a note event to the sequencer.
- Parameters:
- freqscalar
The note’s frequency in Hertz.
- startscalar
When it starts, in seconds from the start of the sequence.
- durationscalar
How long it lasts, in seconds.
- vibrato_freqscalar
The rate of a vibrato in Hertz. With
max_pitch_dev, both nonzero, the note is rendered bynote_with_vibrato().- max_pitch_devscalar
The depth of that vibrato.
- adsr_params
dict,optional Arguments for
adsr(), applied to the note.- spatial
dict,optional Arguments for
localize(), which makes the note stereo.
- Raises:
ValueErrorIf
startis negative or not finite, oradsr_paramsorspatialnamessonic_vectororsample_rate, which the sequencer supplies itself. A negative start was placed at a negative sample offset and failed with a broadcasting error, NaN and infinity failed inround()when rendering, and a secondsample_rateas aTypeErrorthere.
- Parameters:
- Return type:
None
- write(filename, bit_depth=16)[source]¶
Write the rendered audio to a WAV file.
- Raises:
ValueErrorIf there are no notes to write. The empty render reached the normalization, which blamed a duration computed as zero.
- Parameters:
- Return type:
None