music21 translates to Lilypond format and if Lilypond is installed on the local computer, can automatically generate .pdf, .png, and .svg versions of musical files using Lilypond
this replaces (July 2012) the old LilyString() conversion methods.
Takes an id and makes it purely letters by substituting letters for all other characters.
>>> from music21 import *
>>> print lily.translate.makeLettersOnlyId('rainbow123@@dfas')
rainbowxyzmmdfas
LilypondConverter attributes
- versionScheme¶
represents Scheme embedded in Lilypond code.
Can be either a SCM_TOKEN (Scheme Token) or SCM_IDENTIFIER String stored in self.content
Note that if any LyEmbeddedScm is found in an output then the output SHOULD be marked as unsafe. But a lot of standard lilypond functions are actually embedded scheme. For instance, clef, which as http://lilypond.org/doc/v2.12/input/lsr/lilypond-snippets/Pitches#Tweaking-clef-properties shows is a macro to run a lot of set commands.
- context¶
corresponds to the highest level lilypond object in Appendix C:
`lilypond: /* empty */ | lilypond toplevel_expression | lilypond assignment | lilypond error | lilypond "\invalid"`error and invalid are not defined by music21
- topLevelObject¶
corresponds to the highest level lilypond object in Appendix C:
`lilypond: /* empty */ | lilypond toplevel_expression | lilypond assignment | lilypond error | lilypond "\invalid"`error and invalid are not defined by music21
Attributes without Documentation: accidentalConvert, barlineDict, colorDef, fictaDef, simplePaperDefinitionScm, transparencyStartScheme, transparencyStopScheme, majorVersion, LILYEXEC, minorVersion, variantMode, currentMeasure, storedContexts, doNotOutput, versionString, backendString, variantColors, coloredVariants, addedVariants, backend
LilypondConverter methods
- appendBeamCode(noteOrChord)¶
Adds an LyEmbeddedScm object to the context’s contents if the object’s has a .beams attribute.
>>> from music21 import * >>> lpc = lily.translate.LilypondConverter() >>> lpMusicList = lyo.LyMusicList() >>> lpc.context = lpMusicList >>> lpc.context.contents [] >>> n1 = note.Note(quarterLength = 0.25) >>> n2 = note.Note(quarterLength = 0.25) >>> n1.beams.fill(2, 'start') >>> n2.beams.fill(2, 'stop') >>> lpc.appendBeamCode(n1) >>> print lpc.context.contents [<music21.lily.lilyObjects.LyEmbeddedScm object at 0x...>, <music21.lily.lilyObjects.LyEmbeddedScm object at 0x...>] >>> print lpc.context \set stemLeftBeamCount = #0 \set stemRightBeamCount = #2
- appendContextFromNoteOrRest(noteOrRest)¶
appends lySimpleMusicFromNoteOrRest to the current context.
>>> from music21 import * >>> n = note.Note("C#4") >>> lpc = lily.translate.LilypondConverter() >>> lpMusicList = lily.lilyObjects.LyMusicList() >>> lpc.context = lpMusicList >>> lpc.appendContextFromNoteOrRest(n) >>> print lpMusicList cis' 4>>> n2 = note.Note("D#4") >>> n2.duration.quarterLength = 0.3333333333333 >>> n2.duration.tuplets[0].type = 'start' >>> n3 = note.Note("E4") >>> n3.duration.quarterLength = 0.3333333333333 >>> n4 = note.Note("F4") >>> n4.duration.quarterLength = 0.3333333333333 >>> n4.duration.tuplets[0].type = 'stop' >>> n5 = note.Note("F#4")>>> lpc.appendContextFromNoteOrRest(n2) >>> lpc.appendContextFromNoteOrRest(n3) >>> lpc.appendContextFromNoteOrRest(n4) >>> lpc.appendContextFromNoteOrRest(n5) >>> print lpc.context cis' 4 \times 2/3 { dis' 8 e' 8 f' 8 } fis' 4
- appendContextFromVariant(variantObjectOrList, activeSite=None, coloredVariants=False)¶
- appendM21ObjectToContext(thisObject)¶
converts any type of object into a lilyObject of LyMusic ( LySimpleMusic, LyEmbeddedScm etc.) type
- appendObjectsToContextFromStream(streamObject)¶
takes a Stream and appends all the elements in it to the current context’s .contents list, and deals with creating Voices in it. It also deals with variants in it.
(should eventually replace the main Score parts finding tools)
>>> from music21 import * >>> lpc = lily.translate.LilypondConverter() >>> lpMusicList = lyo.LyMusicList() >>> lpc.context = lpMusicList >>> lpc.context.contents [] >>> c = converter.parse('tinynotation: 3/4 c4 d- e#') >>> lpc.appendObjectsToContextFromStream(c) >>> print lpc.context.contents [<music21.lily.lilyObjects.LyEmbeddedScm...>, <music21.lily.lilyObjects.LySimpleMusic...>, <music21.lily.lilyObjects.LySimpleMusic...>, <music21.lily.lilyObjects.LySimpleMusic...] >>> print lpc.context \time 3/4 c' 4 des' 4 eis' 4>>> v1 = stream.Voice() >>> v1.append(note.Note("C5", quarterLength = 4.0)) >>> v2 = stream.Voice() >>> v2.append(note.Note("C#5", quarterLength = 4.0)) >>> m = stream.Measure() >>> m.insert(0, v1) >>> m.insert(0, v2) >>> lpMusicList = lyo.LyMusicList() >>> lpc.context = lpMusicList >>> lpc.appendObjectsToContextFromStream(m) >>> print lpc.context # internal spaces removed... << \new Voice { c'' 1 } \new Voice { cis'' 1 } >>
- appendStemCode(noteOrChord)¶
Adds an LyEmbeddedScm object to the context’s contents if the object’s stem direction is set (currrently, only “up” and “down” are supported).
>>> from music21 import * >>> lpc = lily.translate.LilypondConverter() >>> lpMusicList = lyo.LyMusicList() >>> lpc.context = lpMusicList >>> lpc.context.contents [] >>> n = note.Note() >>> n.stemDirection = 'up' >>> lpc.appendStemCode(n) >>> print lpc.context.contents [<music21.lily.lilyObjects.LyEmbeddedScm object at 0x...>] >>> print lpc.context.contents[0] \once \override Stem #'direction = #UP
- baseNameFromPitch(pitch)¶
returns a string of the base name (including accidental) for a music21 pitch
- closeMeasure(barChecksOnly=False)¶
return a LyObject or None for the end of the previous Measure
uses self.currentMeasure
>>> from music21 import * >>> lpc = lily.translate.LilypondConverter() >>> m = stream.Measure() >>> m.number = 2 >>> m.rightBarline = 'double' >>> lpc.currentMeasure = m >>> lyObj = lpc.closeMeasure() >>> lpc.currentMeasure is None True >>> print lyObj \bar "||" %{ end measure 2 %}
- createPDF(fileName=None)¶
create a PDF file from self.topLevelObject and return the filepath of the file.
most users will just call stream.write(‘lily.pdf’) on a stream.
- createPNG(fileName=None)¶
create a PNG file from self.topLevelObject and return the filepath of the file.
most users will just call stream.write(‘lily.png’) on a stream.
if PIL is installed then a small white border is created around the score
- createSVG(fileName=None)¶
create an SVG file from self.topLevelObject and return the filepath of the file.
most users will just call stream.Stream.write(‘lily.svg’) on a stream.
- getLySpacersFromStream(streamIn, measuresOnly=True)¶
Creates a series of Spacer objects for the measures in a Stream Part.
>>> from music21 import * >>> m1 = stream.Measure(converter.parse("a2.", "3/4")) >>> m2 = stream.Measure(converter.parse("b2.", "3/4")) >>> m3 = stream.Measure(converter.parse("a1", "4/4")) >>> m4 = stream.Measure(converter.parse("b1", "4/4")) >>> m5 = stream.Measure(converter.parse("c1", "4/4")) >>> m6 = stream.Measure(converter.parse("a4 b1", "5/4")) >>> streamIn = stream.Stream([m1, m2, m3, m4, m5, m6]) >>> lpc = lily.translate.LilypondConverter() >>> print lpc.getLySpacersFromStream(streamIn) s2. s2. s1 s1 s1 s1 s4TODO: Low-priority... rare, but possible: tuplet time signatures (3/10)...
- getSchemeForPadding(measureObject)¶
lilypond partial durations are very strange and are really of type LyMultipliedDuration. You notate how many notes are left in the measure, for a quarter note, write “4” for an eighth, write “8”, but for 3 eighths, write “8*3” ! so we will measure in 32nd notes always... won’t work for tuplets of course.
returns a scheme object or None if not needed
>>> from music21 import * >>> m = stream.Measure() >>> m.append(meter.TimeSignature('3/4')) >>> m.paddingLeft = 2.0 >>> lpc = lily.translate.LilypondConverter() >>> outScheme = lpc.getSchemeForPadding(m) >>> print outScheme \partial 32*8
- loadFromMusic21Object(m21ObjectIn)¶
Create a Lilypond object hierarchy in self.topLevelObject from an arbitrary music21 object.
TODO: Add tests... TODO: Add test for TinyNotationStream...
- loadObjectFromOpus(opusIn=None, makeNotation=True)¶
creates a filled topLevelObject (lily.lilyObjects.LyLilypondTop) whose string representation accurately reflects all the Score objects in this Opus object.
>>> from music21 import * >>> fifeOpus = corpus.parse('miscFolk/americanfifeopus.abc') >>> lpc = lily.translate.LilypondConverter() >>> lpc.loadObjectFromOpus(fifeOpus, makeNotation = False) >>> lpc.showPDF()
- loadObjectFromScore(scoreIn=None, makeNotation=True)¶
creates a filled topLevelObject (lily.lilyObjects.LyLilypondTop) whose string representation accurately reflects this Score object.
>>> from music21 import * >>> lpc = lily.translate.LilypondConverter() >>> b = corpus.parse('bach/bwv66.6') >>> lpc.loadObjectFromScore(b) >>> #print lpc.topLevelObject
- lyEmbeddedScmFromClef(clefObj)¶
converts a Clef object to a lilyObjects.LyEmbeddedScm object
>>> from music21 import * >>> tc = clef.TrebleClef() >>> conv = lily.translate.LilypondConverter() >>> lpEmbeddedScm = conv.lyEmbeddedScmFromClef(tc) >>> print lpEmbeddedScm \clef "treble"
- lyEmbeddedScmFromKeySignature(keyObj)¶
converts a Key or KeySignature object to a lilyObjects.LyEmbeddedScm object
>>> from music21 import * >>> d = key.KeySignature(-1) >>> d.mode = 'minor' >>> conv = lily.translate.LilypondConverter() >>> lpEmbeddedScm = conv.lyEmbeddedScmFromKeySignature(d) >>> print lpEmbeddedScm \key d \minorMajor is assumed:
>>> fsharp = key.KeySignature(6) >>> print conv.lyEmbeddedScmFromKeySignature(fsharp) \key fis \major
- lyEmbeddedScmFromTimeSignature(ts)¶
convert a TimeSignature object to a lilyObjects.LyEmbeddedScm object
>>> from music21 import * >>> ts = meter.TimeSignature('3/4') >>> conv = lily.translate.LilypondConverter() >>> print conv.lyEmbeddedScmFromTimeSignature(ts) \time 3/4
- lyGroupedMusicListFromScoreWithParts(scoreIn, scoreInit=None)¶
More complex example showing how the score can be set up with ossia parts...
>>> from music21 import * >>> lpc = lily.translate.LilypondConverter() >>> b = corpus.parse('bach/bwv66.6') >>> lpPartsAndOssiaInit = lpc.lyPartsAndOssiaInitFromScore(b) >>> lpGroupedMusicList = lpc.lyGroupedMusicListFromScoreWithParts(b, scoreInit = lpPartsAndOssiaInit) >>> print lpGroupedMusicList << \new Staff = Soprano { \stopStaff s4 s1 s1 s1 s1 s1 s1 s1 s1 s2. } \new Staff = Alto { \stopStaff s4 s1 s1 s1 s1 s1 s1 s1 s1 s2. } \new Staff = Tenor { \stopStaff s4 s1 s1 s1 s1 s1 s1 s1 s1 s2. } \new Staff = Bass { \stopStaff s4 s1 s1 s1 s1 s1 s1 s1 s1 s2. } \context Staff = Soprano { \startStaff \partial 32*8 \clef "treble" \key fis \minor \time 4/4 \once \override Stem #'direction = #DOWN cis'' 8 \once \override Stem #'direction = #DOWN b' 8 \bar "|" %{ end measure 0 %} \once \override Stem #'direction = #UP a' 4 \once \override Stem #'direction = #DOWN b' 4 \once \override Stem #'direction = #DOWN cis'' 4 \fermata \once \override Stem #'direction = #DOWN e'' 4 \bar "|" %{ end measure 1 %} \once \override Stem #'direction = #DOWN cis'' 4 ... } \context Staff = Alto { \startStaff \partial 32*8 \clef "treble"... \once \override Stem #'direction = #UP e' 4 \bar "|" %{ end measure 0 %} \once \override Stem #'direction = #UP fis' 4 \once \override Stem #'direction = #UP e' 4 ... } >>
- lyLyricElementFromM21Lyric(m21Lyric)¶
Returns a LyLyricElement object from a Lyric object.
Uses self.inWord to keep track of whether or not we’re in the middle of a word.
>>> from music21 import * >>> s = converter.parse('tinyNotation: 4/4 c4_hel- d4_-lo r2 e2 f2_world') >>> s.makeMeasures(inPlace = True) >>> lyrics = s.lyrics()[1] # get first verse (yes, 1 = first, not 0!) >>> lpc = lily.translate.LilypondConverter() >>> lpc.lyLyricElementFromM21Lyric(lyrics[0]) <music21.lily.lilyObjects.LyLyricElement object "hel --"> >>> lpc.inWord True >>> lpc.lyLyricElementFromM21Lyric(lyrics[1]) <music21.lily.lilyObjects.LyLyricElement object "lo__"> >>> lpc.lyLyricElementFromM21Lyric(lyrics[2]) <music21.lily.lilyObjects.LyLyricElement object " _ "> >>> lpc.lyLyricElementFromM21Lyric(lyrics[3]) <music21.lily.lilyObjects.LyLyricElement object "world"> >>> lpc.inWord False
- lyMultipliedDurationFromDuration(durationObj)¶
take a simple Duration (that is one with one DurationUnit object and return a LyMultipliedDuration object:
>>> from music21 import * >>> d = duration.Duration(3) >>> lpc = lily.translate.LilypondConverter() >>> lyMultipliedDuration = lpc.lyMultipliedDurationFromDuration(d) >>> str(lyMultipliedDuration) '2. ' >>> str(lpc.lyMultipliedDurationFromDuration(duration.Duration(8.0))) '\\breve 'Does not work with complex durations:
>>> d = duration.Duration(5.0) >>> str(lpc.lyMultipliedDurationFromDuration(d)) Traceback (most recent call last): LilyTranslateException: DurationException for durationObject <music21.duration.Duration 5.0>: Could not determine durationNumber from NoneInstead split by components:
>>> components = d.components >>> [str(lpc.lyMultipliedDurationFromDuration(c)) for c in components] ['1 ', '4 ']
- lyNewLyricsFromStream(streamIn, streamId=None, alignment='alignBelowContext')¶
returns a LyNewLyrics object
This is a little bit of a hack. This should be switched over to using a prefixed context thing with new Lyric = “id” with { } {}
>>> from music21 import * >>> s = converter.parse('tinyNotation: 4/4 c4_hel- d4_-lo r4 e4_world') >>> s.makeMeasures(inPlace = True) >>> s.id = 'helloWorld' >>> lpc = lily.translate.LilypondConverter() >>> lyNewLyrics = lpc.lyNewLyricsFromStream(s) >>> print lyNewLyrics \addlyrics { \set alignBelowContext = #"helloWorld" hel -- lo__ world }
- lyOssiaMusicFromVariant(variantIn)¶
returns a LyOssiaMusic object from a stream
>>> from music21 import * >>> c = converter.parse('tinynotation: 3/4 C4 D E F2.') >>> v = variant.Variant(c) >>> lpc = lily.translate.LilypondConverter() >>> lySequentialMusicOut = lpc.lySequentialMusicFromStream(v) >>> lySequentialMusicOut <music21.lily.lilyObjects.LySequentialMusic object at 0x...> >>> print lySequentialMusicOut { \time 3/4 c 4 d 4 e 4 f 2. }
- lyPartsAndOssiaInitFromScore(scoreIn)¶
Takes in a score and returns a block that starts each part context and variant context with an identifier and {stopStaff s1*n} (or s, whatever is needed for the duration) where n is the number of measures in the score.
>>> from music21 import * >>> import copySet up score:
>>> s = stream.Score() >>> p1,p2 = stream.Part(), stream.Part() >>> p1.insert(0, meter.TimeSignature('4/4')) >>> p2.insert(0, meter.TimeSignature('4/4')) >>> p1.append(variant.Variant(name = 'london')) >>> p2.append(variant.Variant(name = 'london')) >>> p1.append(variant.Variant(name = 'rome')) >>> p2.append(variant.Variant(name = 'rome')) >>> for i in range(4): ... m = stream.Measure() ... n = note.WholeNote('D4') ... m.append(n) ... p1.append(m) ... p2.append(copy.deepcopy(m)) >>> p1.id = 'pa' >>> p2.id = 'pb' >>> s.append(p1) >>> s.append(p2)Run method
>>> lpc = lily.translate.LilypondConverter() >>> print lpc.lyPartsAndOssiaInitFromScore(s) \new Staff = pa { \stopStaff s1 s1 s1 s1 } \new Staff = londonpa \with { \remove "Time_signature_engraver" alignAboveContext = #"pa" fontSize = #-3 \override StaffSymbol #'staff-space = #(magstep -3) \override StaffSymbol #'thickness = #(magstep -3) \override TupletBracket #'bracket-visibility = ##f \override TupletNumber #'stencil = ##f \override Clef #'transparent = ##t \override OctavateEight #'transparent = ##t \consists "Default_bar_line_engraver" } { \stopStaff s1 s1 s1 s1 } \new Staff = romepa \with { \remove "Time_signature_engraver" alignAboveContext = #"pa" fontSize = #-3 \override StaffSymbol #'staff-space = #(magstep -3) \override StaffSymbol #'thickness = #(magstep -3) \override TupletBracket #'bracket-visibility = ##f \override TupletNumber #'stencil = ##f \override Clef #'transparent = ##t \override OctavateEight #'transparent = ##t \consists "Default_bar_line_engraver" } { \stopStaff s1 s1 s1 s1 } \new Staff = pb { \stopStaff s1 s1 s1 s1 } \new Staff = londonpb \with { \remove "Time_signature_engraver" alignAboveContext = #"pb" fontSize = #-3 \override StaffSymbol #'staff-space = #(magstep -3) \override StaffSymbol #'thickness = #(magstep -3) \override TupletBracket #'bracket-visibility = ##f \override TupletNumber #'stencil = ##f \override Clef #'transparent = ##t \override OctavateEight #'transparent = ##t \consists "Default_bar_line_engraver" } { \stopStaff s1 s1 s1 s1 } \new Staff = romepb \with { \remove "Time_signature_engraver" alignAboveContext = #"pb" fontSize = #-3 \override StaffSymbol #'staff-space = #(magstep -3) \override StaffSymbol #'thickness = #(magstep -3) \override TupletBracket #'bracket-visibility = ##f \override TupletNumber #'stencil = ##f \override Clef #'transparent = ##t \override OctavateEight #'transparent = ##t \consists "Default_bar_line_engraver" } { \stopStaff s1 s1 s1 s1 }
- lyPitchFromPitch(pitch)¶
converts a music21.pitch.Pitch object to a lily.lilyObjects.LyPitch object.
- lyPrefixCompositeMusicFromRelatedVariants(variantList, activeSite=None, coloredVariants=False)¶
>>> from music21 import * >>> s1 = converter.parse("a4 a a a a1", "4/4") >>> s2 = converter.parse("b4 b b b", "4/4") >>> s3 = converter.parse("c4 c c c", "4/4") >>> s4 = converter.parse("d4 d d d", "4/4") >>> s5 = converter.parse("e4 e e e f f f f g g g g a a a a b b b b", "4/4") >>> for s in [ s1, s2, s3, s4, s5]: ... s.makeMeasures(inPlace = True)>>> activeSite = stream.Part(s5) >>> v1 = variant.Variant() >>> for el in s1: ... v1.append(el) >>> v1.replacementDuration = 4.0>>> v2 = variant.Variant() >>> sp2 = note.SpacerRest() >>> sp2.duration.quarterLength = 4.0 >>> v2.replacementDuration = 4.0 >>> v2.append(sp2) >>> for el in s2: ... v2.append(el) >>> v3 = variant.Variant() >>> sp3 = note.SpacerRest() >>> sp3.duration.quarterLength = 8.0 >>> v3.replacementDuration = 4.0 >>> v3.append(sp3) >>> for el in s3: ... v3.append(el)>>> v4 = variant.Variant() >>> sp4 = note.SpacerRest() >>> sp4.duration.quarterLength = 16.0 >>> v4.replacementDuration = 4.0 >>> v4.append(sp4) >>> for el in s4: ... v4.append(el) >>> variantList = [v4,v1,v3,v2] >>> for v in variantList : ... v.groups = ['london'] ... activeSite.insert(0.0, v)>>> lpc = lily.translate.LilypondConverter() >>> print lpc.lyPrefixCompositeMusicFromRelatedVariants(variantList, activeSite = activeSite)[0] \new Staff = london... { { \times 1/2 {\startStaff \clef "treble" \clef "treble" a' 4 a' 4 a' 4 a' 4 | %{ end measure 1 %} a' 1 | %{ end measure 2 %} \stopStaff} } {\startStaff \clef "treble" b' 4 b' 4 b' 4 b' 4 | %{ end measure 1 %} \stopStaff} {\startStaff \clef "treble" c' 4 c' 4 c' 4 c' 4 | %{ end measure 1 %} \stopStaff} s 1 {\startStaff \clef "treble" d' 4 d' 4 d' 4 d' 4 | %{ end measure 1 %} \stopStaff} }
- lyPrefixCompositeMusicFromStream(streamIn, contextType=None, type=None, beforeMatter=None)¶
returns an LyPrefixCompositeMusic object from a stream (generally a part, but who knows...)
>>> from music21 import * >>> c = converter.parse('tinynotation: 3/4 C4 D E F2.') >>> c.staffLines = 4 >>> lpc = lily.translate.LilypondConverter() >>> lyPrefixCompositeMusicOut = lpc.lyPrefixCompositeMusicFromStream(c, contextType='Staff') >>> lyPrefixCompositeMusicOut <music21.lily.lilyObjects.LyPrefixCompositeMusic object at 0x...> >>> print lyPrefixCompositeMusicOut \new Staff = ... \with { \override StaffSymbol #'line-count = #4 } { \time 3/4 c 4 d 4 e 4 f 2. }
- lyPrefixCompositeMusicFromVariant(variantObject, replacedElements, coloredVariants=False)¶
>>> from music21 import * >>> pstream = converter.parse("a4 b c d e4 f g a", "4/4") >>> pstream.makeMeasures(inPlace = True) >>> p = stream.Part(pstream) >>> p.id = 'p1' >>> vstream = converter.parse("a4. b8 c4 d", "4/4") >>> vstream.makeMeasures(inPlace = True) >>> v = variant.Variant(vstream) >>> v.groups = ['london'] >>> p.insert(0.0, v) >>> lpc = lily.translate.LilypondConverter() >>> replacedElements = v.replacedElements() >>> lpPrefixCompositeMusicVariant = lpc.lyPrefixCompositeMusicFromVariant(v, replacedElements) >>> print lpPrefixCompositeMusicVariant \new Staff = londonpx { {\startStaff \clef "treble" \clef "treble" a' 4. b' 8 c' 4 d' 4 | %{ end measure 1 %} \stopStaff} } >>> replacedElements.show('text') {0.0} <music21.stream.Measure 1 offset=0.0> {0.0} <music21.clef.TrebleClef> {0.0} <music21.meter.TimeSignature 4/4> {0.0} <music21.note.Note A> {1.0} <music21.note.Note B> {2.0} <music21.note.Note C> {3.0} <music21.note.Note D>>>> print lpc.addedVariants [u'london']
- lyScoreBlockFromScore(scoreIn)¶
No documentation.
- lySequentialMusicFromStream(streamIn, beforeMatter=None)¶
returns a LySequentialMusic object from a stream
>>> from music21 import * >>> c = converter.parse('tinynotation: 3/4 C4 D E F2.') >>> lpc = lily.translate.LilypondConverter() >>> lySequentialMusicOut = lpc.lySequentialMusicFromStream(c) >>> lySequentialMusicOut <music21.lily.lilyObjects.LySequentialMusic object at 0x...> >>> print lySequentialMusicOut { \time 3/4 c 4 d 4 e 4 f 2. }
- lySimpleMusicFromChord(chordObj)¶
>>> from music21 import * >>> conv = lily.translate.LilypondConverter() >>> c1 = chord.Chord(["C#2", "E4", "D#5"]) >>> c1.quarterLength = 3.5 >>> c1.pitches[2].accidental.displayType = 'always' >>> print conv.lySimpleMusicFromChord(c1) < cis, e' dis'' ! > 2..
- lySimpleMusicFromNoteOrRest(noteOrRest)¶
returns a lilyObjects.LySimpleMusic object for the generalNote containing...
LyEventChord containing LySimpleChordElements containing LySimpleElement containing LyPitch AND LyMultipliedDuration containing:
LyMultipliedDuration containing LyStenoDurationdoes not check for tuplets. That’s in appendContextFromNoteOrRest
read-only property that returns a string of the lilypond representation of a note (or via subclassing, rest or chord)
>>> from music21 import * >>> conv = lily.translate.LilypondConverter() >>> n0 = note.Note("D#5") >>> n0.pitch.accidental.displayType = 'always' >>> n0.pitch.accidental.displayStyle = 'parentheses' >>> n0.editorial.color = 'blue' >>> sm = conv.lySimpleMusicFromNoteOrRest(n0) >>> print sm \color "blue" dis'' ! ? 4
- newContext(newContext)¶
No documentation.
- octaveCharactersFromPitch(pitch)¶
returns a string of single-quotes or commas or “” representing the octave of a Pitch object
- postEventsFromObject(generalNote)¶
attaches events that apply to notes and chords (and some other things) equally
- restoreContext()¶
No documentation.
- runThroughLily(format=None, backend=None, fileName=None, skipWriting=False)¶
creates a .ly file from self.topLevelObject via .writeLyFile then runs the file through Lilypond.
Returns the full path of the file produced by lilypond including the format extension.
If skipWriting is True and a fileName is given then it will run that file through lilypond instead
- setContextForTimeFraction(numerator, denominator)¶
Explicitly starts a new context for scaled music (tuplets, etc.) for the given numerator and denominator (either an int or a string or unicode)
Returns an lpMusicList object contained in an lpSequentialMusic object in an lpPrefixCompositeMusic object which sets the times object to a particular fraction.
>>> from music21 import * >>> lpc = lily.translate.LilypondConverter() >>> lpc.context <music21.lily.lilyObjects.LyLilypondTop object at 0x...> >>> lyTop = lpc.context >>> lyoMusicList = lpc.setContextForTimeFraction(5, 4) >>> lyoMusicList <music21.lily.lilyObjects.LyMusicList object at 0x...> >>> lpc.context <music21.lily.lilyObjects.LyMusicList object at 0x...> >>> lpc.context is lyoMusicList True >>> lpc.context.getParent() <music21.lily.lilyObjects.LySequentialMusic object at 0x...> >>> lpc.context.getParent().getParent() <music21.lily.lilyObjects.LyPrefixCompositeMusic object at 0x...> >>> lpc.context.getParent().getParent().fraction u'5/4' >>> lpc.context.getParent().getParent().type u'times' >>> lpc.context.getParent().getParent().getParent() <music21.lily.lilyObjects.LyLilypondTop object at 0x...> >>> lpc.context.getParent().getParent().getParent() is lyTop True
- setContextForTupletStart(inObj)¶
if the inObj has tuplets then we set a new context for the tuplets and anything up till a tuplet stop.
Note that a broken tuplet (a la Michael Gordon) will not work.
If there are no tuplets, this routine does nothing. If there are tuplets and they have type start then it returns an lpMusicList object, which is the new context
For now, no nested tuplets. They’re an easy extension, but there’s too much else missing to do it now...
- setContextForTupletStop(inObj)¶
Reverse of setContextForTupletStart
- setHeaderFromMetadata(metadataObject=None, lpHeader=None)¶
Returns a lilypond.lilyObjects.LyLilypondHeader object set with data from the metadata object
>>> from music21 import * >>> md = metadata.Metadata() >>> md.title = 'My Title' >>> md.alternativeTitle = 'My "sub"-title' >>> lpc = lily.translate.LilypondConverter() >>> lpHeader = lpc.setHeaderFromMetadata(md) >>> print lpHeader \header { title = "My Title" subtitle = "My \"sub\"-title" }
- setupTools()¶
No documentation.
- showPDF()¶
create a SVG file from self.topLevelObject, show it with your pdf reader (often Adobe Acrobat/Adobe Reader or Apple Preview) and return the filepath of the file.
most users will just call stream.Stream.show(‘lily.pdf’) on a stream.
- showPNG()¶
Take the object, run it through LilyPond, and then show it as a PNG file. On Windows, the PNG file will not be deleted, so you will need to clean out TEMP every once in a while.
Most users will just want to call stream.Stream.show(‘lily.png’) instead.
- showSVG(fileName=None)¶
create a SVG file from self.topLevelObject, show it with your svg reader (often Internet Explorer on PC) and return the filepath of the file.
most users will just call stream.Stream.show(‘lily.png’) on a stream.
- textFromMusic21Object(m21ObjectIn)¶
get a proper lilypond text file for writing from a music21 object
>>> from music21 import * >>> n = note.Note() >>> print lily.translate.LilypondConverter().textFromMusic21Object(n) \version "2.13" color = #(define-music-function (parser location color) (string?) #{ \once \override NoteHead #'color = #(x11-color $color) \once \override Stem #'color = #(x11-color $color) \once \override Rest #'color = #(x11-color $color) \once \override Beam #'color = #(x11-color $color) #}) \header { } \score { << \new Staff = ... { c' 4 } >> } \paper { } ...
- writeLyFile(ext='', fp=None)¶
writes the contents of the self.topLevelObject to a file.
The extension should be ly. If fp is None then a named temporary file is created by environment.getTempFile.