From a90e90170ed572dec7f4daa20cdf0f0de0f34da0 Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 18 Jun 2022 20:30:34 +0200 Subject: [PATCH] ticksToLilypond --- template/engine/duration.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/template/engine/duration.py b/template/engine/duration.py index 6e21d84..37428e1 100644 --- a/template/engine/duration.py +++ b/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")