mutwo.core_converters¶
Convert data from and to mutwo.
Object |
Documentation |
|---|---|
Extract from a chronon an attribute. |
|
|
dict() -> new empty dictionary |
Extract from a dict of mutwo parameters specific objects. |
|
Extract from a dict of mutwo parameters the duration. |
|
Convert a dict of mutwo parameters to a |
|
Apply tempo on an |
|
Apply tempo of event on copy of itself |
- class ChrononToAttribute(attribute_name, exception_value)[source]¶
Bases:
ConverterExtract from a chronon an attribute.
- Parameters:
attribute_name (str) – The name of the attribute which is fetched from a
mutwo.core_events.Chronon.exception_value (Any) – This value is returned in case an AttributeError raises .
Public Methods:
convert(chronon_to_convert)Extract from a
mutwo.core_events.Chrononan attribute.Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- convert(chronon_to_convert)[source]¶
Extract from a
mutwo.core_events.Chrononan attribute.- Parameters:
chronon_to_convert (mutwo.core_events.Chronon) – The
mutwo.core_events.Chrononfrom which an attribute shall be extracted.- Return type:
Any
Example:
>>> from mutwo import core_converters >>> from mutwo import core_events >>> chronon = core_events.Chronon(duration=10.0) >>> chronon_to_duration = core_converters.ChrononToAttribute( ... 'duration', 0 ... ) >>> chronon_to_duration.convert(chronon) DirectDuration(10.0) >>> chronon_to_pasta = core_converters.ChrononToAttribute( ... 'pasta', 'spaghetti' ... ) >>> chronon_to_pasta.convert(chronon) 'spaghetti' >>> chronon.pasta = 'tagliatelle' >>> chronon_to_pasta.convert(chronon) 'tagliatelle'
- class MutwoParameterDictToKeywordArgument(mutwo_parameter_to_search_name, keyword=None)[source]¶
Bases:
ConverterExtract from a dict of mutwo parameters specific objects.
- Parameters:
mutwo_parameter_to_search_name (str) – The parameter name which should be fetched from the MutwoParameterDict (if it exists).
keyword (Optional[str]) – The keyword string to return. If no argument is given it will use the same value as :param:`mutwo_parameter_to_search_name`.
Example:
>>> from mutwo import core_converters >>> from mutwo import core_parameters >>> mutwo_parameter_dict_to_keyword_argument = core_converters.MutwoParameterDictToKeywordArgument('duration') >>> mutwo_parameter_dict_to_keyword_argument.convert( ... {'duration': core_parameters.DirectDuration(1.0)} ... ) ('duration', DirectDuration(1.0))
Public Methods:
convert(mutwo_parameter_dict_to_convert)Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- class MutwoParameterDictToDuration(duration_to_search_name=None, duration_keyword_name=None)[source]¶
Bases:
MutwoParameterDictToKeywordArgumentExtract from a dict of mutwo parameters the duration.
- Parameters:
duration_to_search_name (Optional[str]) – The name of the duration which shall be searched for in the
MutwoParameterDict. If None the value of the global constantsmutwo.core_converters.configurations.DEFAULT_DURATION_TO_SEARCH_NAMEwill be used. Default to None.duration_keyword_name (typing.Optional[str]
mutwo.core_converters.configurations.DEFAULT_DURATION_KEYWORD_NAME.) – The name of the duration keyword for the event. If None the value of the global constantsmutwo.core_converters.configurations.DEFAULT_DURATION_KEYWORD_NAMEwill be used. Default to None.
Public Methods:
Inherited from
MutwoParameterDictToKeywordArgumentconvert(mutwo_parameter_dict_to_convert)Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- class MutwoParameterDictToChronon(mutwo_parameter_dict_to_keyword_argument_sequence=None, chronon_class=<class 'mutwo.core_events.basic.Chronon'>)[source]¶
Bases:
ConverterConvert a dict of mutwo parameters to a
mutwo.core_events.Chronon- Parameters:
mutwo_parameter_dict_to_keyword_argument_sequence (Optional[Sequence[MutwoParameterDictToKeywordArgument]]) – A sequence of
MutwoParameterDictToKeywordArgument. If set to None a sequence withMutwoParameterDictToDurationwill be created. Default to None.chronon_class (Type[core_events.Chronon]) – Default to
mutwo.core_events.Chronon.
Public Methods:
convert(mutwo_parameter_dict_to_convert)Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- class TempoConverter(tempo, apply_converter_on_events_tempo=True)[source]¶
Bases:
EventConverterApply tempo on an
Event.- Parameters:
Example:
>>> from mutwo import core_converters >>> from mutwo import core_parameters >>> tempo = core_parameters.FlexTempo( ... [[0, core_parameters.DirectTempo(60)], [3, 60], [3, 30], [5, 50]], ... ) >>> c = core_converters.TempoConverter(tempo)
Public Methods:
convert(event_to_convert)Apply tempo curve of the converter on copy of 'event_to_convert'.
Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- convert(event_to_convert)[source]¶
Apply tempo curve of the converter on copy of ‘event_to_convert’.
- Parameters:
event_to_convert (Event) – The event to convert. Can be any object that inherits from
mutwo.core_events.abc.Event. If the event that shall be converted is longer than the tempo curve of theTempoConverter, then the last tempo of the curve is hold.- Returns:
A new
Eventwhich duration has been adapted by the tempo curve of theTempoConverter.- Return type:
Example:
>>> from mutwo import core_converters >>> from mutwo import core_events >>> from mutwo import core_parameters >>> tempo = core_parameters.FlexTempo( ... [[0, core_parameters.DirectTempo(60)], [3, 60], [3, 30], [5, 50]], ... ) >>> my_tempo_converter = core_converters.TempoConverter(tempo) >>> my_events = core_events.Consecution([core_events.Chronon(d) for d in (3, 2, 5)]) >>> my_tempo_converter.convert(my_events) Consecution([Chronon(duration=DirectDuration(3.0)), Chronon(duration=DirectDuration(3.2)), Chronon(duration=DirectDuration(6.0))])
- class EventToMetrizedEvent(skip_level_count=None, maxima_depth_count=None)[source]¶
Bases:
SymmetricalEventConverterApply tempo of event on copy of itself
Public Methods:
convert(event_to_convert)Apply tempo of event on copy of itself
Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- Parameters:
skip_level_count (Optional[int]) –
maxima_depth_count (Optional[int]) –
mutwo.core_converters.abc¶
Defining the public API for any converter class.
- class Converter[source]¶
Bases:
MutwoObject,ABCAbstract base class for all Converter classes.
Converter classes are defined as classes that convert data between two different encodings. Their only public method (besides initialisation) should be a convert method. The first argument of the convert method should be the data to convert.
- class EventConverter[source]¶
Bases:
ConverterAbstract base class for Converter which handle mutwo events.
This class helps building new classes which convert mutwo events with few general private methods (and without adding any new public method). Converting mutwo event often involves the same pattern: due to the nested structure of an Event, the converter has to iterate through the different layers until it reaches leaves (any class that inherits from
mutwo.core_events.Chronon). This common iteration process and the different time treatment betweenmutwo.core_events.Consecutionandmutwo.core_events.Concurrenceare implemented inEventConverter. For writing a new EventConverter class, one only has to override the abstract method_convert_chronon()and the abstract methodconvert()(where one will perhaps call_convert_event().).Example:
The following example defines a dummy class for demonstrating how to use EventConverter.
>>> from mutwo import core_converters >>> class DurationPrintConverter(core_converters.abc.EventConverter): ... def _convert_chronon(self, event_to_convert, absolute_time): ... return "{}: {}".format(absolute_time, event_to_convert.duration), ... def convert(self, event_to_convert): ... data_per_event = self._convert_event(event_to_convert, 0) ... [print(data) for data in data_per_event] >>> # now test with random event >>> import random >>> from mutwo import core_events >>> random.seed(100) >>> random_event = core_events.Concurrence( ... [ ... core_events.Consecution( ... [ ... core_events.Chronon(random.uniform(0.5, 2)) ... for _ in range(random.randint(2, 5)) ... ] ... ) ... for _ in range(random.randint(1, 3)) ... ] ... ) >>> DurationPrintConverter().convert(random_event) D(0.0): D(1.1823905068) D(1.1823905068): D(1.6561757085) D(2.8385662153): D(1.5582698404) D(4.3968360557): D(1.5979384595) D(5.9947745152): D(1.1502716523)
- class SymmetricalEventConverter[source]¶
Bases:
EventConverterAbstract base class for Converter which handle mutwo core_events.
This converter is a more specified version of the
EventConverter. It helps for building converters which aim to return mutwo core_events.
mutwo.core_converters.configurations¶
Configure mutwo.core_converters
- DEFAULT_DURATION_KEYWORD_NAME = 'duration'¶
Default value for
duration_keyword_nameparameter inmutwo.core_converters.MutwoParameterDictToDuration
- DEFAULT_DURATION_TO_SEARCH_NAME = 'duration'¶
Default value for
duration_to_search_nameparameter inmutwo.core_converters.MutwoParameterDictToDuration