From a414108fe1578680c5288d8777f00de382875f67 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sun, 13 Dec 2020 18:42:56 +0100 Subject: [PATCH] tuplet support for mico-voices --- engine/items.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/engine/items.py b/engine/items.py index 62cb85e..0ad2853 100644 --- a/engine/items.py +++ b/engine/items.py @@ -641,6 +641,15 @@ class DurationGroup(object): def genericNumber(self): return duration.baseDurationToTraditionalNumber[self.baseDuration] + @property + def tuplet(self): + """Return the tuplet of the shortest duration. + Does *not* use self.hasTuplet() because that returns if any + note has tuplet. We just want the logical shortest duration, + not even the actual absolute shortes duration. + In other words: the smallest notehead, does that have a tuplet?""" + return self.minimumNote.duration.tuplet + ############################################## ## Items ## @@ -1738,13 +1747,13 @@ class Chord(Item): onlyOneDuration = durations.count(durations[0]) == len(durations) if onlyOneDuration: - pre = _createLilypondTuplet(self.notelist[0].duration, carryLilypondRanges) + tupletSubstring = _createLilypondTuplet(self.notelist[0].duration, carryLilypondRanges) if len(pitches) == 1: # The most common case: Just a single note - return pre + pitches[0] + durations[0] #this is a string. + return tupletSubstring + pitches[0] + durations[0] #this is a string. else: # A simple chord with mulitple pitches but just one duration - return pre + "<" + " ".join(pitches) + ">" + durations[0] + return tupletSubstring + "<" + " ".join(pitches) + ">" + durations[0] else: #TODO: Cache this @@ -1772,7 +1781,9 @@ class Chord(Item): lilydur = lilydur[:-1] #without ~ #TODO: not supported yet. dur = lilydur + " * {}/{}".format(int(minimumTicksInChord), int(ticks)) #lilypond requires the x/y syntax, even if it is 1/y #TODO: this is very ugly substrings.append("\\\\ { <" + " ".join(lst) + ">" + dur + " }" ) - result = "<<" + " ".join(substrings) + ">>" + + tupletSubstring = _createLilypondTuplet(self.durationGroup, carryLilypondRanges) + result = tupletSubstring + "<<" + " ".join(substrings) + ">>" return result class Rest(Item):