Browse Source

Add simpe dynamic signature to lilypond output

master
Nils 2 years ago
parent
commit
5572900bf2
  1. 26
      engine/items.py
  2. 7
      engine/track.py

26
engine/items.py

@ -1757,6 +1757,17 @@ class Chord(Item):
pass
return pre
#Do we have a dynamic signature waiting? (convert laborejo prefix to lilypond postfix)
#They belong after the duration.
if "DynamicSignature" in carryLilypondRanges:
dynsig = carryLilypondRanges["DynamicSignature"]
del carryLilypondRanges["DynamicSignature"]
else:
dynsig = ""
#Do we have a slur signature waiting? (convert laborejo prefix to lilypond postfix)
#Create lilypond durations
pitches, durations = zip(*(note.lilypond(carryLilypondRanges) for note in self.notelist))
onlyOneDuration = durations.count(durations[0]) == len(durations)
@ -1765,10 +1776,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] #this is a string.
return tupletSubstring + pitches[0] + durations[0] + dynsig #this is a string.
else:
# A simple chord with mulitple pitches but just one duration
return tupletSubstring + "<" + " ".join(pitches) + ">" + durations[0]
return tupletSubstring + "<" + " ".join(pitches) + ">" + durations[0] + dynsig
else:
#TODO: Cache this
@ -1798,7 +1809,7 @@ class Chord(Item):
substrings.append("\\\\ { <" + " ".join(lst) + ">" + dur + " }" )
tupletSubstring = _createLilypondTuplet(self.durationGroup, carryLilypondRanges)
result = tupletSubstring + "<<" + " ".join(substrings) + ">>"
result = tupletSubstring + "<<" + " ".join(substrings) + dynsig + ">>"
return result
class Rest(Item):
@ -2562,6 +2573,15 @@ class DynamicSignature(Item):
"UIstring" : self.keyword,
}
def _lilypond(self, carryLilypondRanges):
"""
Lilypond Dynamics are postfix.
Don't export anything directly, but add the dynamic keyword to the lilypond ranges dict
so the next chord can use it as postfix. """
carryLilypondRanges["DynamicSignature"] = f"\\{self.keyword}"
return ""
class DynamicRamp(Item):
"""The class for "cresc", "decresc" and so on.
It takes the current trackState as starting point and

7
engine/track.py

@ -823,8 +823,11 @@ class Track(object):
"""Called by score.lilypond(), returns a string.
We carry a dict around to hold lilypond on/off markers like tuplets
that need to set as ranges. This dict begins here. Each track
gets its own.
that need to set as ranges. Also for slurs and dynamics, that are lilypond postfixes
but appear *before* the time in the output. Which is different than in Laborejo where
the items are where they should be.
This dict begins here. Each track gets its own.
"""
for item in self.blocks[0].data[:4]:
if type(item) is MetricalInstruction:

Loading…
Cancel
Save