mutwo.converters.frontends.csound module¶
Render sound files from mutwo data via Csound.
Csound is a “domain-specific computer programming language for audio programming”.
Classes:
|
Generate audio files with Csound. |
|
Class to convert mutwo events to a Csound score file. |
- class CsoundConverter(path, csound_orchestra_path, csound_score_converter, *flag, remove_score_file=False)[source]¶
Bases:
mutwo.converters.abc.ConverterGenerate audio files with Csound.
- Parameters
path (str) – where to write the sound file
csound_orchestra_path (str) – Path to the csound orchestra (.orc) file.
csound_score_converter (mutwo.converters.frontends.csound.CsoundScoreConverter) – The
CsoundScoreConverterthat shall be used to render the csound score file (.sco) from a mutwo event.*flag –
Flag that shall be added when calling csound. Several of the supported csound flags can be found in
mutwo.converters.frontends.csound_constants.remove_score_file (bool) – Set to True if
CsoundConvertershall remove the csound score file after rendering. Defaults to False.flag (str) –
Disclaimer: Before using the
CsoundConverter, make sure Csound has been correctly installed on your system.Methods:
convert(event_to_convert)Render sound file from the mutwo event.
- convert(event_to_convert)[source]¶
Render sound file from the mutwo event.
- Parameters
event_to_convert (mutwo.events.abc.Event) – The event that shall be rendered.
- Return type
None
- class CsoundScoreConverter(path, **pfield)[source]¶
Bases:
mutwo.converters.abc.EventConverterClass to convert mutwo events to a Csound score file.
- Parameters
path (str) – where to write the csound score file
pfield (Callable[[mutwo.events.basic.SimpleEvent], Union[float, fractions.Fraction, str]]) – p-field / p-field-extraction-function pairs.
This class helps generating score files for the “domain-specific computer programming language for audio programming” Csound.
CsoundScoreConverterextracts data from mutwo Events and assign it to specific p-fields. The mapping of Event attributes to p-field values has to be defined by the user via keyword arguments during class initialization.By default, mutwo already maps the following p-fields to the following values:
p1 (instrument name) to 1
p2 (start time) to the absolute start time of the event
p3 (duration) to the
durationattribute of the event
If p2 shall be assigned to the absolute entry delay of the event, it has to be set to None.
The
CsoundScoreConverterignores any p-field that returns any unsupported p-field type (anything else than a string or a number). If the returned type is a string,CsoundScoreConverterautomatically adds quotations marks around the string in the score file.All p-fields can be overwritten in the following manner:
>>> my_converter = CsoundScoreConverter( >>> path="my_csound_score.sco", >>> p1=lambda event: 2, >>> p4=lambda event: event.pitch.frequency, >>> p5=lambda event: event.volume >>> )
For easier debugging of faulty score files,
mutwoadds annotations when a newSequentialEventor a newSimultaneousEventstarts.Methods:
convert(event_to_convert)Render csound score file (.sco) from the passed event.
- convert(event_to_convert)[source]¶
Render csound score file (.sco) from the passed event.
- Parameters
event_to_convert (mutwo.events.abc.Event) – The event that shall be rendered to a csound score file.
- Return type
None
>>> import random >>> from mutwo.parameters import pitches >>> from mutwo.events import basic >>> from mutwo.converters.frontends import csound >>> converter = csound.CsoundScoreConverter( >>> path="score.sco", p4=lambda event: event.pitch.frequency >>> ) >>> events = basic.SequentialEvent( >>> [ >>> basic.SimpleEvent(random.uniform(0.3, 1.2)) for _ in range(15) >>> ] >>> ) >>> for event in events: >>> event.pitch = pitches.DirectPitch(random.uniform(100, 500)) >>> converter.convert(events)