mutwo.csound_converters§
Object |
Documentation |
---|---|
Class to convert mutwo events to a Csound score file. |
|
Generate audio files with Csound. |
- class EventToCsoundScore(**pfield)[source]§
Class to convert mutwo events to a Csound score file.
- Parameters:
pfield (Callable[[SimpleEvent], Union[float, Fraction, int, 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.frequency, >>> p5=lambda event: event.volume >>> )
For easier debugging of faulty score files,
mutwo
adds annotations when a newSequentialEvent
or a newSimultaneousEvent
starts.Public Methods:
__init__
(**pfield)convert
(event_to_convert, path)Render csound score file (.sco) from the passed event.
Inherited from
Converter
convert
(event_to_convert, path)Render csound score file (.sco) from the passed event.
__call__
(*args, **kwargs)Call self as a function.
Private Data Attributes:
_default_p_field_dict
_abc_impl
Inherited from
EventConverter
_abc_impl
Inherited from
Converter
_abc_impl
Inherited from
ABC
_abc_impl
- 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 >>> from mutwo import music_parameters >>> converter = csound_converters.EventToCsoundScore( >>> p4=lambda event: event.pitch.frequency >>> ) >>> events = core_events.SequentialEvent( >>> [ >>> core_events.SimpleEvent(random.uniform(0.3, 1.2)) for _ in range(15) >>> ] >>> ) >>> for event in events: >>> event.pitch = music_parameters.DirectPitch(random.uniform(100, 500)) >>> converter.convert(events, 'score.sco')
- class EventToSoundFile(csound_orchestra_path, event_to_csound_score, *flag, remove_score_file=False)[source]§
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:
__init__
(csound_orchestra_path, ...[, ...])convert
(event_to_convert, path[, score_path])Render sound file from the mutwo event.
Inherited from
Converter
convert
(event_to_convert, path[, score_path])Render sound file from the mutwo event.
__call__
(*args, **kwargs)Call self as a function.
Private Data Attributes:
_abc_impl
Inherited from
Converter
_abc_impl
Inherited from
ABC
_abc_impl
- 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
.
- N_EMPTY_LINES_AFTER_COMPLEX_EVENT = 1§
How many empty lines shall be written to a Csound Score file after a
ComplexEvent
.
- SEQUENTIAL_EVENT_ANNOTATION = ';; NEW SEQUENTIAL EVENT\n;;'§
Annotation in Csound Score files when a new
SequentialEvent
starts.
- SIMULTANEOUS_EVENT_ANNOTATION = ';; NEW SIMULTANEOUS EVENT\n;;'§
Annotation in Csound Score files when a new
SimultaneousEvent
starts.
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.