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:

CsoundConverter(path, csound_orchestra_path, ...)

Generate audio files with Csound.

CsoundScoreConverter(path, **pfield)

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.Converter

Generate audio files with Csound.

Parameters

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.EventConverter

Class 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.

CsoundScoreConverter extracts 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 duration attribute of the event

If p2 shall be assigned to the absolute entry delay of the event, it has to be set to None.

The CsoundScoreConverter ignores 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, CsoundScoreConverter automatically 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, mutwo adds annotations when a new SequentialEvent or a new SimultaneousEvent starts.

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)