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:
Convert tempo envelope to |
|
Convert Mutwo Pitch objects to Abjad Pitch objects. |
|
Convert Mutwo |
|
Convert Mutwo Volume objects to |
|
Convert |
|
|
Quantize |
Quantize |
|
Convert tempo envelope to |
- class ComplexTempoEnvelopeToAbjadAttachmentTempoConverter[source]¶
Bases:
mutwo.converters.frontends.abjad.TempoEnvelopeToAbjadAttachmentTempoConverterConvert tempo envelope to
Tempo.This object tries to intelligently set correct tempo attachments to an
abjad.Voiceobject, 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.ConverterConvert 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 thenameattribute. Otherwise Mutwo will simply initialise the Abjad Pitch from the objectsfrequencyattribute.If users desire to make more complex conversions (for instance due to
scordaturaor 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.MutwoPitchToAbjadPitchConverterConvert Mutwo
JustIntonationPitchobjects 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_NAMEfor the default mapping.otonality_indicator (str, optional) – String which indicates that the respective prime alteration is otonal. See
DEFAULT_OTONALITY_INDICATORfor the default value.utonality_indicator (str, optional) – String which indicates that the respective prime alteration is utonal. See
DEFAULT_OTONALITY_INDICATORfor 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_INDICATORfor the default value.
The resulting Abjad pitches are expected to be used in combination with tuning files that are generated by
HEJIEkmelilyTuningFileConverterand 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.ConverterConvert 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 theTempoobject from thenameattribute. Otherwise Mutwo will first initialise aWesternVolumeobject via its py:method:mutwo.parameters.volumes.WesternVolume.from_amplitude method.Hairpins aren’t notated with the aid of
mutwo.parameters.abc.Volumeobjects, but withmutwo.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.ConverterConvert
SequentialEventtoabjad.Voice.- Parameters
sequential_event_to_quantized_abjad_container_converter (SequentialEventToQuantizedAbjadContainerConverter, optional) – Class which defines how the Mutwo data will be quantized. See
SequentialEventToQuantizedAbjadContainerConverterfor more information.simple_event_to_pitches (typing.Callable[[events.basic.SimpleEvent], parameters.abc.Pitch], optional) – Function to extract from a
mutwo.events.basic.SimpleEventa tuple that contains pitch objects (objects that inherit frommutwo.parameters.abc.Pitch). By default it asks the Event for itspitch_or_pitchesattribute (because by defaultmutwo.events.music.NoteLikeobjects are expected). When using different Event classes thanNoteLikewith a different name for their pitch property, this argument should be overridden. If the function call raises anAttributeError(e.g. if no pitch can be extracted), mutwo will assume an event without any pitches.simple_event_to_volume (typing.Callable[[events.basic.SimpleEvent], parameters.abc.Volume], optional) – Function to extract the volume from a
mutwo.events.basic.SimpleEventin the purpose of generating dynamic indicators. The function should return an object that inherits frommutwo.parameters.abc.Volume. By default it asks the Event for itsvolumeattribute (because by defaultmutwo.events.music.NoteLikeobjects are expected). When using different Event classes thanNoteLikewith a different name for their volume property, this argument should be overridden. If the function call raises anAttributeError(e.g. if no volume can be extracted), mutwo will setpitch_or_pitchesto an empty list and set volume to 0.simple_event_to_playing_indicators (typing.Callable[[events.basic.SimpleEvent], parameters.playing_indicators.PlayingIndicatorCollection,], optional) – Function to extract from a
mutwo.events.basic.SimpleEventamutwo.parameters.playing_indicators.PlayingIndicatorCollectionobject. By default it asks the Event for itsplaying_indicatorsattribute (because by defaultmutwo.events.music.NoteLikeobjects are expected). When using different Event classes thanNoteLikewith a different name for their playing_indicators property, this argument should be overridden. If the function call raises anAttributeError(e.g. if no playing indicator collection can be extracted), mutwo will build a playing indicator collection fromDEFAULT_PLAYING_INDICATORS_COLLECTION_CLASS.simple_event_to_notation_indicators (typing.Callable[[events.basic.SimpleEvent], parameters.notation_indicators.NotationIndicatorCollection,], optional) – Function to extract from a
mutwo.events.basic.SimpleEventamutwo.parameters.notation_indicators.NotationIndicatorCollectionobject. By default it asks the Event for itsnotation_indicators(because by defaultmutwo.events.music.NoteLikeobjects are expected). When using different Event classes thanNoteLikewith a different name for their playing_indicators property, this argument should be overridden. If the function call raises anAttributeError(e.g. if no notation indicator collection can be extracted), mutwo will build a notation indicator collection fromDEFAULT_NOTATION_INDICATORS_COLLECTION_CLASSis_simple_event_rest (typing.Callable[[events.basic.SimpleEvent], bool], optional) – Function to detect if the the inspected
mutwo.events.basic.SimpleEventis a Rest. By default Mutwo simply checks if ‘pitch_or_pitches’ contain any objects. If not, the Event will be interpreted as a rest.mutwo_pitch_to_abjad_pitch_converter (MutwoPitchToAbjadPitchConverter, optional) – Class which defines how to convert
mutwo.parameters.abc.Pitchobjects toabjad.Pitchobjects. SeeMutwoPitchToAbjadPitchConverterfor more information.mutwo_volume_to_abjad_attachment_dynamic_converter (MutwoVolumeToAbjadAttachmentDynamicConverter, optional) – Class which defines how to convert
mutwo.parameters.abc.Volumeobjects tomutwo.converters.frontends.abjad_attachments.Dynamicobjects. SeeMutwoVolumeToAbjadAttachmentDynamicConverterfor more information.tempo_envelope_to_abjad_attachment_tempo_converter (TempoEnvelopeToAbjadAttachmentTempoConverter, optional) – Class which defines how to convert tempo envelopes to
mutwo.converters.frontends.abjad_attachments.Tempoobjects. SeeTempoEnvelopeToAbjadAttachmentTempoConverterfor more information.abjad_attachment_classes (typing.Sequence[abjad_attachments.AbjadAttachment], optional) – A tuple which contains all available abjad attachment classes which shall be used by the converter.
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
SequentialEventwhich shall be converted to theabjad.Voiceobject.- 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.SequentialEventToQuantizedAbjadContainerConverterQuantize
SequentialEventobjects viaabjadext.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
SequentialEventis 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 thedurationattribute 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.Envelopeobject which durations are beats and which levels are either numbers (that will be interpreted as beats per minute (‘BPM’)) orTempoPointobjects. 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.AttackPointOptimizerobject. Attack point optimizer help to split events and tie them for better looking notation. The default attack point optimizer isnauert.MeasurewiseAttackPointOptimizerwhich splits events to better represent metrical structures within bars. If no optimizer is desired this argument can be set toNone.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
SequentialEventToQuantizedAbjadContainerConverterthrough 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.ConverterQuantize
SequentialEventobjects viaabjadext.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
SequentialEventis 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 thedurationattribute 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.Envelopeobject which durations are beats and which levels are either numbers (that will be interpreted as beats per minute (‘BPM’)) orTempoPointobjects. 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.AttackPointOptimizerobject. Attack point optimizer help to split events and tie them for better looking notation. The default attack point optimizer isnauert.MeasurewiseAttackPointOptimizerwhich splits events to better represent metrical structures within bars. If no optimizer is desired this argument can be set toNone.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.ConverterConvert tempo envelope to
Tempo.Abstract base class for tempo envelope conversion. See
ComplexTempoEnvelopeToAbjadAttachmentTempoConverterfor 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], …]