From 6366af156396495f67b26fb28e6ad63dc5330764 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Thu, 25 Apr 2019 20:03:07 +0200 Subject: [PATCH] Partial support for ties and keysigns in lilypond. Lilypond syntax changed again --- engine/items.py | 30 +++++++++++++------ engine/resources/lilypondTemplates/default.ly | 3 ++ template | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/engine/items.py b/engine/items.py index 8b1f436..0fa0350 100644 --- a/engine/items.py +++ b/engine/items.py @@ -571,7 +571,7 @@ class Duration(object): else: append = "" - n = self.genericNumber + n = self.genericNumber if n == 0: return "\\breve" + append elif n == -1: @@ -1701,13 +1701,15 @@ class Chord(Item): substrings = [] minimumTicksInChord = self.durationGroup.completeDuration() - for (ticks, lilydur), lst in table.items(): + for (ticks, lilydur), lst in table.items(): #factor = Fraction(ticks, minimumDurInChord).limit_denominator(100000) #protects 6 or 7 decimal positions #dur = lilydur + " * {}/{}".format(factor.denominator, factor.numerator) #lilypond requires the 1/x syntax assert int(ticks) == ticks, ticks assert int(minimumTicksInChord) == minimumTicksInChord, minimumTicksInChord - assert minimumTicksInChord <= ticks - dur = lilydur + " * {}/{}".format(int(minimumTicksInChord), int(ticks)) #lilypond requires the x/y syntax, even if it is 1/x + assert minimumTicksInChord <= ticks + if lilydur.endswith("~"): + 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) + ">>" return result @@ -2148,13 +2150,23 @@ class KeySignature(Item): return "" #G Major ((3, 10), (0, 0), (4, 0), (1, 0), (5, 0), (2, 0), (6, 0)) - #`((0 . ,NATURAL) (1 . ,NATURAL) (2 . ,NATURAL) (3 . ,SHARP) (4 . ,NATURAL) (5 . ,NATURAL) (6 . ,NATURAL)) - - schemepairs = " ".join(build(x[0], x[1]) for x in self.keysigList) + #`((0 . ,NATURAL) (1 . ,NATURAL) (2 . ,NATURAL) (3 . ,SHARP) (4 . ,NATURAL) (5 . ,NATURAL) (6 . ,NATURAL)) + schemepairs = " ".join(build(x[0], x[1]) for x in self.keysigList) schemepairs = " ".join(schemepairs.split()) # split and join again to reduce all whitespaces to single ones. subtextRoot = "\\once \\override Staff.KeySignature #'stencil = #(lambda (grob) (ly:stencil-combine-at-edge (ly:key-signature-interface::print grob) Y DOWN (grob-interpret-markup grob (markup #:small \"" + pitchmath.pitch2ly[self.root].strip(",").title() + "\")) 3)) " #3 is the space between keysig and text - lyKeysignature = subtextRoot + "\\set Staff.keySignature = #`( {} )".format(schemepairs) - return lyKeysignature + lyKeysignature = subtextRoot + "\\set Staff.keyAlterations = #`( {} )".format(schemepairs) + return lyKeysignature + + #Alternative + schemepairs = " ".join(build(num, alt) for num, alt in enumerate(self.deviationFromMajorScale)) + schemepairs = " ".join(schemepairs.split()) # split and join again to reduce all whitespaces to single ones. + subtextRoot = "\\once \\override Staff.KeySignature #'stencil = #(lambda (grob) (ly:stencil-combine-at-edge (ly:key-signature-interface::print grob) Y DOWN (grob-interpret-markup grob (markup #:small \"" + pitchmath.pitch2ly[self.root].strip(",").title() + "\")) 3)) " #3 is the space between keysig and text + if schemepairs: + lyKeysignature = subtextRoot + f"\\key {pitchmath.pitch2ly[self.root].strip(',')} #`( {schemepairs} )" + else: #no explicit accidental + lyKeysignature = subtextRoot + "\\set Staff.keyAlterations = #`(( 0 . ,NATURAL))" #TODO: subtextRoot position is broken + return lyKeysignature + class Clef(Item): """A clef has no direct musical logical meaning. But it gives some hints: diff --git a/engine/resources/lilypondTemplates/default.ly b/engine/resources/lilypondTemplates/default.ly index 49f9b89..17a9a27 100644 --- a/engine/resources/lilypondTemplates/default.ly +++ b/engine/resources/lilypondTemplates/default.ly @@ -69,7 +69,10 @@ correctFraction = #(lambda (grob) %Exchange note_heads_engraver with the completition variant which auto-ties notes on bar-breaks \remove "Note_heads_engraver" \consists "Completion_heads_engraver" + \remove "Rest_engraver" + \consists "Completion_rest_engraver" tieWaitForNote = ##t + } \context { \Staff \RemoveEmptyStaves diff --git a/template b/template index ff78979..bb6ae01 160000 --- a/template +++ b/template @@ -1 +1 @@ -Subproject commit ff789798793af4981fe81b9d6f769a975735faea +Subproject commit bb6ae017b284957b6e1e3756599ba17aefc3322a