mutwo.converters.symmetrical.tempos module

Apply tempo curve on any Event and convert TempoPoint to beat-length-in-seconds.

Classes:

TempoConverter(tempo_envelope)

Class for applying tempo curves on mutwo events.

TempoPointConverter()

Convert a TempoPoint with BPM to beat-length-in-seconds.

class TempoConverter(tempo_envelope)[source]

Bases: mutwo.converters.abc.EventConverter

Class for applying tempo curves on mutwo events.

Parameters

tempo_envelope (expenvelope.envelope.Envelope) – The tempo curve that shall be applied on the mutwo events. This is expected to be a expenvelope.Envelope which levels arefilled with numbers that will be interpreted as BPM [beats per minute]) or with mutwo.parameters.tempos.TempoPoint objects.

Example:

>>> import expenvelope
>>> from mutwo.converters import symmetrical
>>> from mutwo.parameters import tempos
>>> tempo_envelope = expenvelope.Envelope.from_levels_and_durations(
>>>     levels=[tempos.TempoPoint(60), 60, 30, 50],
>>>     durations=[3, 0, 2],
>>> )
>>> my_tempo_converter = symmetrical.tempos.TempoConverter(tempo_envelope)

Methods:

convert(event_to_convert)

Apply tempo curve of the converter to the entered event.

convert(event_to_convert)[source]

Apply tempo curve of the converter to the entered event.

The method doesn’t change the original event, but returns a copied version with different values for its duration attributes depending on the tempo curve.

Parameters

event_to_convert (mutwo.events.abc.Event) – The event to convert. Can be any object that inherits from mutwo.events.abc.Event. If the event that shall be converted is longer than the tempo curve of the TempoConverter, then the last tempo of the curve will be hold.

Returns

A new Event object which duration property has been adapted by the tempo curve of the TempoConverter.

Return type

mutwo.events.abc.Event

Example:

>>> import expenvelope
>>> from mutwo.events import basic
>>> from mutwo.parameters import tempos
>>> from mutwo.converters import symmetrical
>>> tempo_envelope = expenvelope.Envelope.from_levels_and_durations(
>>>     levels=[tempos.TempoPoint(60), 60, 120, 120],
>>>     durations=[3, 2, 5],
>>> )
>>> my_tempo_converter = symmetrical.tempos.TempoConverter(tempo_envelope)
>>> my_events = basic.SequentialEvent([basic.SimpleEvent(d) for d in (3, 2, 5)])
>>> my_tempo_converter.convert(my_events)
SequentialEvent([SimpleEvent(duration = 3.0), SimpleEvent(duration = 1.5), SimpleEvent(duration = 2.5)])
class TempoPointConverter[source]

Bases: mutwo.converters.abc.Converter

Convert a TempoPoint with BPM to beat-length-in-seconds.

A TempoPoint is defined as an object that has a particular tempo in beats per seconds (BPM) and a reference value (1 for a quarter note, 4 for a whole note, etc.). Besides elaborate mutwo.parameters.tempos.TempoPoint objects, any number can also be interpreted as a TempoPoint. In this case the number simply represents the BPM number and the reference will be set to 1. The returned beat-length-in-seconds always indicates the length for one quarter note.

Example:

>>> from mutwo.converters import symmetrical
>>> tempo_point_converter = symmetrical.tempos.TempoPointConverter()

Methods:

convert(tempo_point_to_convert)

Converts a TempoPoint to beat-length-in-seconds.

convert(tempo_point_to_convert)[source]

Converts a TempoPoint to beat-length-in-seconds.

Parameters

tempo_point_to_convert (Union[mutwo.parameters.tempos.TempoPoint, float, fractions.Fraction]) – A tempo point defines the active tempo from which the beat-length-in-seconds shall be calculated. The argument can either be any number (which will be interpreted as beats per minute [BPM]) or a mutwo.parameters.tempos.TempoPoint object.

Returns

The duration of one beat in seconds within the passed tempo.

Return type

float

Example:

>>> from mutwo.converters import symmetrical
>>> converter = symmetrical.tempos.TempoPointConverter()
>>> converter.convert(60)  # one beat in tempo 60 bpm takes 1 second
1
>>> converter.convert(120)  # one beat in tempo 120 bpm takes 0.5 second
0.5