Browse Source

add Slurs to lilypond output

master
Nils 2 years ago
parent
commit
85d0b58ccc
  1. 30
      engine/items.py

30
engine/items.py

@ -1757,7 +1757,7 @@ class Chord(Item):
pass
return pre
#Do we have a dynamic signature waiting? (convert laborejo prefix to lilypond postfix)
#Do we have a dynamic \f signature waiting? (convert laborejo prefix to lilypond postfix)
#They belong after the duration.
if "DynamicSignature" in carryLilypondRanges:
dynsig = carryLilypondRanges["DynamicSignature"]
@ -1765,7 +1765,12 @@ class Chord(Item):
else:
dynsig = ""
#Do we have a slur signature waiting? (convert laborejo prefix to lilypond postfix)
#Do we have a slur ( or ) signature waiting? (convert laborejo prefix to lilypond postfix)
if "LegatoSlur" in carryLilypondRanges:
slur = carryLilypondRanges["LegatoSlur"]
del carryLilypondRanges["LegatoSlur"]
else:
slur = ""
#Create lilypond durations
@ -1776,10 +1781,10 @@ class Chord(Item):
tupletSubstring = _createLilypondTuplet(self.notelist[0].duration, carryLilypondRanges)
if len(pitches) == 1:
# The most common case: Just a single note
return tupletSubstring + pitches[0] + durations[0] + dynsig #this is a string.
return tupletSubstring + pitches[0] + durations[0] + dynsig + slur #this is a string.
else:
# A simple chord with mulitple pitches but just one duration
return tupletSubstring + "<" + " ".join(pitches) + ">" + durations[0] + dynsig
return tupletSubstring + "<" + " ".join(pitches) + ">" + durations[0] + dynsig + slur
else:
#TODO: Cache this
@ -1787,6 +1792,7 @@ class Chord(Item):
#Here is how it's done: We group the same duration together and create normal chords which are placed each in its own automatic voice through the lilypond syntax << { <chord> } \\ { <chord> } \\ etc. >>
#Lilypond default is to take the longest note as overall duration. However, Laborejo uses the shortest duration as logical duration. So we scale all other to logical shortest duration
#See http://lilypond.org/doc/v2.18/Documentation/notation/writing-rhythms#scaling-durations
table = {}
for note in self.notelist:
pitch, duration = note.lilypond(carryLilypondRanges)
@ -1810,6 +1816,10 @@ class Chord(Item):
tupletSubstring = _createLilypondTuplet(self.durationGroup, carryLilypondRanges)
result = tupletSubstring + "<<" + " ".join(substrings) + dynsig + ">>"
if slur:
logging.error("Slurs in single-track polyphonic chords are not supported. Please use multiple tracks for real polyphony. This is the problematic Chord: " + result)
return result
class Rest(Item):
@ -2750,6 +2760,9 @@ class LegatoSlur(Item):
def _exportObject(self, trackState):
#We export so many times, the chances are > 99.9% that this cache for lilypond export will be correct
self._cacheKeywordForLilypond = self.asText(trackState)
return {
"type" : "LegatoSlur",
"slur" : self.openOrClose(trackState),
@ -2759,6 +2772,15 @@ class LegatoSlur(Item):
"UIstring" : self.asText(trackState),
}
def _lilypond(self, carryLilypondRanges):
"""
Lilypond Slurs are postfix.
Don't export anything directly, but add the keyword to the lilypond ranges dict
so the next chord can use it as postfix. """
carryLilypondRanges["LegatoSlur"] = self._cacheKeywordForLilypond
return ""
class InstrumentChange(Item):
"""Includes program change, both bank changes and the lilypond short name change.
Lilypond does not support a full name change, so we don't offer that here."""

Loading…
Cancel
Save