Browse Source

fix lilypond tempo output

master
Nils 7 months ago
parent
commit
81445a9c83
  1. 33
      template/engine/duration.py

33
template/engine/duration.py

@ -150,8 +150,33 @@ ticksToLyDurationLogDict = {
D256: 8, #1/256
}
def ticksToLilypond(ticks:int)->int:
if ticks in ticksToLyDurationLogDict:
return ticksToLyDurationLogDict[ticks]
ticksToLilypondDict = {}
for ourticks, lyAsInt in baseDurationToTraditionalNumber.items():
ly = str(lyAsInt)
ticksToLilypondDict[ourticks] = ly
ticksToLilypondDict[ourticks * 1.5] = ly + "." #dot
ticksToLilypondDict[ourticks * 1.75] = ly + ".." #double dot
ticksToLilypondDict[DM] = "\\maxima"
ticksToLilypondDict[DL] = "\\longa"
ticksToLilypondDict[DB] = "\\breve"
ticksToLilypondDict[DM*1.5] = "\\maxima."
ticksToLilypondDict[DL*1.5] = "\\longa."
ticksToLilypondDict[DB*1.5] = "\\breve."
ticksToLilypondDict[DM*1.75] = "\\maxima.."
ticksToLilypondDict[DL*1.75] = "\\longa.."
ticksToLilypondDict[DB*1.75] = "\\breve.."
def ticksToLilypond(ticks:int)->str:
"""Returns a lilypond string with the number 1, 2, 4, 8 etc.
It must be a string and not a number because we have dots and words like maxima and brevis.
This is mostly used for tempo items.
"""
if ticks in ticksToLilypondDict:
return ticksToLilypondDict[ticks]
else:
raise ValueError(f"{ticks} not in duration.py ticksToLyDurationLogDict")
raise ValueError(f"{ticks} not in duration.py ticksToLilypondDict")

Loading…
Cancel
Save