mutwo.csound_converters

Object

Documentation

mutwo.csound_converters.EventToCsoundScore

Class to convert mutwo events to a Csound score file.

mutwo.csound_converters.EventToSoundFile

Generate audio files with Csound.

class EventToCsoundScore(**pfield)[source]

Bases: EventConverter

Class to convert mutwo events to a Csound score file.

Parameters:

pfield (Callable[[Chronon], Union[float, Fraction, int, 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.

EventToCsoundScore 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 EventToCsoundScore 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, EventToCsoundScore automatically adds quotations marks around the string in the score file.

All p-fields can be overwritten in the following manner:

>>> from mutwo import csound_converters
>>> my_converter = csound_converters.EventToCsoundScore(
...     p1=lambda event: 2,
...     p4=lambda event: event.pitch.hertz,
...     p5=lambda event: event.volume
... )

For easier debugging of faulty score files, mutwo adds annotations when a new Consecution or a new Concurrence starts.

Public Methods:

convert(event_to_convert, path)

Render csound score file (.sco) from the passed event.

Inherited from Converter

convert(...)

Inherited from MutwoObject

copy()

Return a deep copy of mutwo object.


convert(event_to_convert, path)[source]

Render csound score file (.sco) from the passed event.

Parameters:
  • event_to_convert (core_events.abc.Event) – The event that shall be rendered to a csound score file.

  • path (str) – where to write the csound score file

Return type:

None

>>> import random
>>> from mutwo import core_events
>>> from mutwo import csound_converters
>>> converter = csound_converters.EventToCsoundScore(
...    p4=lambda event: event.tempo_envelope.duration
... )
>>> event = core_events.Consecution(
...    [
...        core_events.Chronon(
...             random.uniform(0.3, 1.2)
...        ) for _ in range(15)
...    ]
... )
>>> for e in event:
...     e.tempo = core_parameters.FlexTempo(
...         [[0, 1], [random.uniform(10, 20), 0]]
...     )
>>> converter.convert(event, 'score.sco')
class EventToSoundFile(csound_orchestra_path, event_to_csound_score, *flag, remove_score_file=False)[source]

Bases: Converter

Generate audio files with Csound.

Parameters:
  • csound_orchestra_path (str) – Path to the csound orchestra (.orc) file.

  • event_to_csound_score (EventToCsoundScore) – The EventToCsoundScore that shall be used to render the csound score file (.sco) from a mutwo event.

  • *flag (str) –

    Flag that shall be added when calling csound. Several of the supported csound flags can be found in mutwo.csound_converters.constants.

  • remove_score_file (bool) – Set to True if EventToSoundFile shall remove the csound score file after rendering. Defaults to False.

Disclaimer: Before using the EventToSoundFile, make sure Csound has been correctly installed on your system.

Public Methods:

convert(event_to_convert, path[, score_path])

Render sound file from the mutwo event.

Inherited from Converter

convert(...)

Inherited from MutwoObject

copy()

Return a deep copy of mutwo object.


convert(event_to_convert, path, score_path=None)[source]

Render sound file from the mutwo event.

Parameters:
  • event_to_convert (core_events.abc.Event) – The event that shall be rendered.

  • path (str) – where to write the sound file

  • score_path (Optional[str]) – where to write the score file

Return type:

None

mutwo.csound_converters.configurations

Configure the behaviour of mutwo.csound_converters.

CONCURRENCE_ANNOTATION = ';; NEW CONCURRENCE\n;;'

Annotation in Csound Score files when a new Concurrence starts.

CONSECUTION_ANNOTATION = ';; NEW CONSECUTION\n;;'

Annotation in Csound Score files when a new Consecution starts.

CSOUND_BINARY = 'csound'

Path to csound binary.

N_EMPTY_LINES_AFTER_COMPOUND = 1

How many empty lines shall be written to a Csound Score file after a Compound.

mutwo.csound_converters.constants

Constants to be used for and with mutwo.csound_converters.

The file mostly contains different flags for running Csound. The flag definitions are documented here.

FORMAT_24BIT = '--format=24bit'

Flag for rendering sound files in 24bit.

FORMAT_64BIT = '--format=double'

Flag for rendering sound files in 64bit floating point.

FORMAT_8BIT = '--format=uchar'

Flag for rendering sound files in 8bit.

FORMAT_FLOAT = '--format=float'

Flag for rendering sound files in single-format float audio samples.

FORMAT_IRCAM = '--format=ircam'

Flag for rendering sound files in IRCAM format.

FORMAT_WAV = '--format=wav'

Flag for rendering sound files in wav file format.

SILENT_FLAG = '-O null'

Flag for preventing Csound from printing any information while rendering.