mutwo.converters.frontends.abjad module

Build Lilypond scores via Abjad from Mutwo data.

The following converter classes help to quantize and translate Mutwo data to Western notation. Due to the complex nature of this task, Mutwo tries to offer as many optional arguments as possible through which the user can affect the conversion routines. The most important class and best starting point for organising a conversion setting is SequentialEventToAbjadVoiceConverter.

Classes:

ComplexTempoEnvelopeToAbjadAttachmentTempoConverter()

Convert tempo envelope to Tempo.

MutwoPitchToAbjadPitchConverter()

Convert Mutwo Pitch objects to Abjad Pitch objects.

MutwoPitchToHEJIAbjadPitchConverter([...])

Convert Mutwo JustIntonationPitch objects to Abjad Pitch objects.

MutwoVolumeToAbjadAttachmentDynamicConverter()

Convert Mutwo Volume objects to Dynamic.

SequentialEventToAbjadVoiceConverter([...])

Convert SequentialEvent to abjad.Voice.

SequentialEventToDurationLineBasedQuantizedAbjadContainerConverter([...])

Quantize SequentialEvent objects via abjadext.nauert.

SequentialEventToQuantizedAbjadContainerConverter([...])

Quantize SequentialEvent objects via abjadext.nauert.

TempoEnvelopeToAbjadAttachmentTempoConverter()

Convert tempo envelope to Tempo.

class ComplexTempoEnvelopeToAbjadAttachmentTempoConverter[source]

Bases: mutwo.converters.frontends.abjad.TempoEnvelopeToAbjadAttachmentTempoConverter

Convert tempo envelope to Tempo.

This object tries to intelligently set correct tempo attachments to an abjad.Voice object, appropriate to Western notation standards. Therefore it will not repeat tempo indications if they are merely repetitions of previous tempo indications and it will write ‘a tempo’ when returning to the same tempo after ritardandi or accelerandi.

Methods:

convert(tempo_envelope_to_convert)

convert(tempo_envelope_to_convert)[source]
Parameters

tempo_envelope_to_convert (expenvelope.envelope.Envelope) –

Return type

Tuple[Tuple[Union[float, fractions.Fraction], mutwo.converters.frontends.abjad_attachments.Tempo], …]

class MutwoPitchToAbjadPitchConverter[source]

Bases: mutwo.converters.abc.Converter

Convert Mutwo Pitch objects to Abjad Pitch objects.

This default class simply checks if the passed Mutwo object belongs to mutwo.parameters.pitches.WesternPitch. If it does, Mutwo will initialise the Abjad Pitch from the name attribute. Otherwise Mutwo will simply initialise the Abjad Pitch from the objects frequency attribute.

If users desire to make more complex conversions (for instance due to scordatura or transpositions of instruments), one can simply inherit from this class to define more complex cases.

Methods:

convert(pitch_to_convert)

convert(pitch_to_convert)[source]
Parameters

pitch_to_convert (mutwo.parameters.abc.Pitch) –

Return type

abjad.pitch.pitches.Pitch

class MutwoPitchToHEJIAbjadPitchConverter(reference_pitch='a', prime_to_heji_accidental_name=None, otonality_indicator=None, utonality_indicator=None, exponent_to_exponent_indicator=None, tempered_pitch_indicator=None)[source]

Bases: mutwo.converters.frontends.abjad.MutwoPitchToAbjadPitchConverter

Convert Mutwo JustIntonationPitch objects to Abjad Pitch objects.

Parameters
  • reference_pitch (str, optional) – The reference pitch (1/1). Should be a diatonic pitch name (see ASCENDING_DIATONIC_PITCH_NAMES) in English nomenclature. For any other reference pitch than ‘c’, Lilyponds midi rendering for pitches with the diatonic pitch ‘c’ will be slightly out of tune (because the first value of :arg:`global_scale` always have to be 0).

  • prime_to_heji_accidental_name (typing.Dict[int, str], optional) – Mapping of a prime number to a string which indicates the respective prime number in the resulting accidental name. See DEFAULT_PRIME_TO_HEJI_ACCIDENTAL_NAME for the default mapping.

  • otonality_indicator (str, optional) – String which indicates that the respective prime alteration is otonal. See DEFAULT_OTONALITY_INDICATOR for the default value.

  • utonality_indicator (str, optional) – String which indicates that the respective prime alteration is utonal. See DEFAULT_OTONALITY_INDICATOR for the default value.

  • exponent_to_exponent_indicator (typing.Callable[[int], str], optional) – Function to convert the exponent of a prime number to string which indicates the respective exponent. See DEFAULT_EXPONENT_TO_EXPONENT_INDICATOR() for the default function.

  • tempered_pitch_indicator (str, optional) – String which indicates that the respective accidental is tempered (12 EDO). See DEFAULT_TEMPERED_PITCH_INDICATOR for the default value.

The resulting Abjad pitches are expected to be used in combination with tuning files that are generated by HEJIEkmelilyTuningFileConverter and with the Lilypond extension Ekmelily. You can find pre-generated tuning files here.

>>> from mutwo.parameters import pitches
>>> from mutwo.converters.frontends import abjad
>>> my_ji_pitch = pitches.JustIntonationPitch('5/4')
>>> converter_on_a = abjad.MutwoPitchToHEJIAbjadPitchConverter(reference_pitch='a')
>>> converter_on_c = abjad.MutwoPitchToHEJIAbjadPitchConverter(reference_pitch='c')
>>> converter_on_a.convert(my_ji_pitch)
NamedPitch("csoaa''")
>>> converter_on_c.convert(my_ji_pitch)
NamedPitch("eoaa'")

Methods:

convert(pitch_to_convert)

convert(pitch_to_convert)[source]
Parameters

pitch_to_convert (mutwo.parameters.abc.Pitch) –

Return type

abjad.pitch.pitches.Pitch

class MutwoVolumeToAbjadAttachmentDynamicConverter[source]

Bases: mutwo.converters.abc.Converter

Convert Mutwo Volume objects to Dynamic.

This default class simply checks if the passed Mutwo object belongs to mutwo.parameters.volumes.WesternVolume. If it does, Mutwo will initialise the Tempo object from the name attribute. Otherwise Mutwo will first initialise a WesternVolume object via its py:method:mutwo.parameters.volumes.WesternVolume.from_amplitude method.

Hairpins aren’t notated with the aid of mutwo.parameters.abc.Volume objects, but with mutwo.parameters.playing_indicators.Hairpin.

Methods:

convert(volume_to_convert)

convert(volume_to_convert)[source]
Parameters

volume_to_convert (mutwo.parameters.abc.Volume) –

Return type

Optional[mutwo.converters.frontends.abjad_attachments.Dynamic]

class SequentialEventToAbjadVoiceConverter(sequential_event_to_quantized_abjad_container_converter=<mutwo.converters.frontends.abjad.SequentialEventToQuantizedAbjadContainerConverter object>, simple_event_to_pitches=<function SequentialEventToAbjadVoiceConverter.<lambda>>, simple_event_to_volume=<function SequentialEventToAbjadVoiceConverter.<lambda>>, simple_event_to_playing_indicators=<function SequentialEventToAbjadVoiceConverter.<lambda>>, simple_event_to_notation_indicators=<function SequentialEventToAbjadVoiceConverter.<lambda>>, is_simple_event_rest=None, mutwo_pitch_to_abjad_pitch_converter=<mutwo.converters.frontends.abjad.MutwoPitchToAbjadPitchConverter object>, mutwo_volume_to_abjad_attachment_dynamic_converter=<mutwo.converters.frontends.abjad.MutwoVolumeToAbjadAttachmentDynamicConverter object>, tempo_envelope_to_abjad_attachment_tempo_converter=<mutwo.converters.frontends.abjad.ComplexTempoEnvelopeToAbjadAttachmentTempoConverter object>, abjad_attachment_classes=None)[source]

Bases: mutwo.converters.abc.Converter

Convert SequentialEvent to abjad.Voice.

Parameters

Methods:

convert(sequential_event_to_convert)

Convert passed SequentialEvent.

convert(sequential_event_to_convert)[source]

Convert passed SequentialEvent.

Parameters

sequential_event_to_convert (mutwo.events.basic.SequentialEvent) – The SequentialEvent which shall be converted to the abjad.Voice object.

Return type

abjad.score.Voice

Example:

>>> import abjad
>>> from mutwo.events import basic, music
>>> from mutwo.converters.frontends import abjad as mutwo_abjad
>>> mutwo_melody = basic.SequentialEvent(
>>>     [
>>>         music.NoteLike(pitch, duration)
>>>         for pitch, duration in zip("c a g e".split(" "), (1, 1 / 6, 1 / 6, 1 / 6))
>>>     ]
>>> )
>>> converter = mutwo_abjad.SequentialEventToAbjadVoiceConverter()
>>> abjad_melody = converter.convert(mutwo_melody)
>>> abjad.lilypond(abjad_melody)
\new Voice
{
    {
        \tempo 4=120
        %%% \time 4/4 %%%
        c'1
        \mf
    }
    {
        \times 2/3 {
            a'4
            g'4
            e'4
        }
        r2
    }
}
class SequentialEventToDurationLineBasedQuantizedAbjadContainerConverter(time_signatures=(TimeSignature((4, 4)), ), duration_unit='beats', tempo_envelope=None, attack_point_optimizer=<abjadext.nauert.attackpointoptimizers.MeasurewiseAttackPointOptimizer object>, search_tree=None, duration_line_minimum_length=6, duration_line_thickness=3)[source]

Bases: mutwo.converters.frontends.abjad.SequentialEventToQuantizedAbjadContainerConverter

Quantize SequentialEvent objects via abjadext.nauert.

Parameters
  • time_signatures (Sequence[abjad.indicators.TimeSignature.TimeSignature]) – Set time signatures to divide the quantized abjad data in desired bar sizes. If the converted SequentialEvent is longer than the sum of all passed time signatures, the last time signature will be repeated for the remaining bars.

  • duration_unit (str) – This defines the duration_unit of the passed SequentialEvent (how the duration attribute will be interpreted). Can either be ‘beats’ (default) or ‘miliseconds’.

  • tempo_envelope (expenvelope.envelope.Envelope) – Defines the tempo of the converted music. This is an expenvelope.Envelope object which durations are beats and which levels are either numbers (that will be interpreted as beats per minute (‘BPM’)) or TempoPoint objects. If no tempo envelope has been defined, Mutwo will assume a constant tempo of 1/4 = 120 BPM.

  • attack_point_optimizer (Optional[abjadext.nauert.attackpointoptimizers.AttackPointOptimizer]) – Optionally the user can pass a nauert.AttackPointOptimizer object. Attack point optimizer help to split events and tie them for better looking notation. The default attack point optimizer is nauert.MeasurewiseAttackPointOptimizer which splits events to better represent metrical structures within bars. If no optimizer is desired this argument can be set to None.

  • duration_line_minimum_length (int) – The minimum length of a duration line.

  • duration_line_thickness (int) – The thickness of a duration line.

  • search_tree (Optional[abjadext.nauert.searchtrees.SearchTree]) –

This converter differs from SequentialEventToQuantizedAbjadContainerConverter through the usage of duration lines for indicating rhythm instead of using flags, beams, dots and note head colors.

Note:

Don’t forget to add the ‘Duration_line_engraver’ to the resulting abjad Voice, otherwise Lilypond won’t be able to render the desired output.

Example:

>>> import abjad
>>> from mutwo.converters.frontends import abjad as mutwo_abjad
>>> from mutwo.events import basic, music
>>> converter = frontends.abjad.SequentialEventToAbjadVoiceConverter(
>>>     frontends.abjad.SequentialEventToDurationLineBasedQuantizedAbjadContainerConverter(
>>>        )
>>>    )
>>> sequential_event_to_convert = basic.SequentialEvent(
>>>     [music.NoteLike("c", 0.125), music.NoteLike("d", 1), music.NoteLike([], 0.125), music.NoteLike("e", 0.16666), music.NoteLike("e", 0.08333333333333333)]
>>>    )
>>> converted_sequential_event = converter.convert(sequential_event_to_convert)
>>> converted_sequential_event.consists_commands.append("Duration_line_engraver")

Methods:

convert(sequential_event_to_convert)

convert(sequential_event_to_convert)[source]
Parameters

sequential_event_to_convert (mutwo.events.basic.SequentialEvent) –

Return type

Tuple[abjad.score.Container, Tuple[Tuple[Tuple[int, …], …], …]]

class SequentialEventToQuantizedAbjadContainerConverter(time_signatures=(TimeSignature((4, 4)), ), duration_unit='beats', tempo_envelope=None, attack_point_optimizer=<abjadext.nauert.attackpointoptimizers.MeasurewiseAttackPointOptimizer object>, search_tree=None)[source]

Bases: mutwo.converters.abc.Converter

Quantize SequentialEvent objects via abjadext.nauert.

Parameters
  • time_signatures (Sequence[abjad.indicators.TimeSignature.TimeSignature]) – Set time signatures to divide the quantized abjad data in desired bar sizes. If the converted SequentialEvent is longer than the sum of all passed time signatures, the last time signature will be repeated for the remaining bars.

  • duration_unit (str) – This defines the duration_unit of the passed SequentialEvent (how the duration attribute will be interpreted). Can either be ‘beats’ (default) or ‘miliseconds’.

  • tempo_envelope (expenvelope.envelope.Envelope) – Defines the tempo of the converted music. This is an expenvelope.Envelope object which durations are beats and which levels are either numbers (that will be interpreted as beats per minute (‘BPM’)) or TempoPoint objects. If no tempo envelope has been defined, Mutwo will assume a constant tempo of 1/4 = 120 BPM.

  • attack_point_optimizer (Optional[abjadext.nauert.attackpointoptimizers.AttackPointOptimizer]) – Optionally the user can pass a nauert.AttackPointOptimizer object. Attack point optimizer help to split events and tie them for better looking notation. The default attack point optimizer is nauert.MeasurewiseAttackPointOptimizer which splits events to better represent metrical structures within bars. If no optimizer is desired this argument can be set to None.

  • search_tree (Optional[abjadext.nauert.searchtrees.SearchTree]) –

Methods:

convert(sequential_event_to_convert)

convert(sequential_event_to_convert)[source]
Parameters

sequential_event_to_convert (mutwo.events.basic.SequentialEvent) –

Return type

Tuple[abjad.score.Container, Tuple[Tuple[Tuple[int, …], …], …]]

class TempoEnvelopeToAbjadAttachmentTempoConverter[source]

Bases: mutwo.converters.abc.Converter

Convert tempo envelope to Tempo.

Abstract base class for tempo envelope conversion. See ComplexTempoEnvelopeToAbjadAttachmentTempoConverter for a concrete class.

Methods:

convert(tempo_envelope_to_convert)

abstract convert(tempo_envelope_to_convert)[source]
Parameters

tempo_envelope_to_convert (expenvelope.envelope.Envelope) –

Return type

Tuple[Tuple[Union[float, fractions.Fraction], mutwo.converters.frontends.abjad_attachments.Tempo], …]