Translation methods for going from music21 to Victor Adan and Trevor Baca’s Abjad framework – a high-quality, Lilypond-based python framework for algorithmic music composition and post-tonal music.
See http://packages.python.org/Abjad/ for more details. Requires abjad 2.0 (not 1.1.1) to work.
Translates a simple music21 Note (no ties or tuplets) to an abjad note.
>>> import abjad
>>> import music21
>>> m21Note1 = music21.note.Note("C#5")
>>> m21Note1.quarterLength = 2
>>> abjadNote1 = music21.abj.noteToAbjad(m21Note1)
>>> abjadNote1
Note("cs''2")
>>> abjad.iotools.show(abjadNote1)
>>> m21Note2 = music21.note.Note("D--2")
>>> m21Note2.quarterLength = 0.125
>>> abjadNote2 = music21.abj.noteToAbjad(m21Note2)
>>> abjadNote2
Note('dff,32')
>>> m21Note3 = music21.note.Note("E-6")
>>> m21Note3.quarterLength = 2.333333333333333
>>> abjadNote3 = music21.abj.noteToAbjad(m21Note3)
Traceback (most recent call last):
AbjadTranslateException: cannot translate complex notes directly, split into individual components first
translates a Stream into an Abjad container
>>> import abjad
>>> import music21
>>> stream1 = music21.parse("c4 d8. e-16 FF2", "4/4")
>>> abjadContainer = music21.abj.streamToAbjad(stream1)
>>> abjadContainer
Staff{4}
>>> abjadContainer.leaves[:]
(Note("c'4"), Note("d'8."), Note("ef'16"), Note('f,2'))
>>> abjad.iotools.show(abjadContainer)
translates an arbitrary object into abjad objects.
might return a tuple because some single m21 objects will require multiple abjad objects (and vice versa).
translates a music21 music21.pitch.Pitch object to abjad.Pitch object
>>> import music21
>>> m21p = music21.pitch.Pitch("D--2")
>>> music21.abj.pitchToAbjad(m21p)
NamedChromaticPitch('dff,')
Translates cis to cs
And ces to cf
>>> translateLilyStringPitch("cis''2")
"cs''2"