From d90226d67cdd0491b175c89968db711306b98721 Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 31 Jul 2022 20:22:54 +0200 Subject: [PATCH] Fix lilypond keysig regressions. update ly template to v2.22 --- engine/items.py | 19 ++++++++++++++----- engine/lilypond.py | 2 +- engine/resources/lilypondTemplates/default.ly | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/engine/items.py b/engine/items.py index bdea223..027cff7 100644 --- a/engine/items.py +++ b/engine/items.py @@ -2266,7 +2266,19 @@ class KeySignature(Item): } def _lilypond(self, carryLilypondRanges): + """Lilyponds custom key signatures are also the difference to the C Major scale. + The \key X in front does not affect the scale building, it is a seconds step done by lilypond + So, it is actually the same as our system, we just need to build a SCHEME string. + + This would be our hollywood-scale: + + \key c #`( (0 . ,NATURAL) (1 . ,NATURAL) (2 . ,NATURAL) (3 . ,NATURAL) (4 . ,NATURAL) (5 . ,FLAT) (6 . ,FLAT) ) + + https://lilypond.org/doc/v2.18/Documentation/notation/displaying-pitches#key-signature + """ + def build(step, alteration): #generate a Scheme pair for Lilyponds GUILE interpreter + assert 0 <= step <= 6, step if alteration == -10: return "(" + str(step) + " . ," + "FLAT)" elif alteration == 10: @@ -2275,14 +2287,11 @@ class KeySignature(Item): return "(" + str(step) + " . ," + "DOUBLE-SHARP)" elif alteration == -20: return "(" + str(step) + " . ," + "DOUBLE-FLAT)" - elif self.lilypondParameters["explicit"] and alteration == 0: - return "(" + str(step) + " . ," + "NATURAL)" #explicit is a legacy flag. It is not available to the user. We now (v2.2.0) always export everything explictely to get ly-transposition working else: + assert alteration == 0, alteration return "(" + str(step) + " . ," + "NATURAL)" - #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) + schemepairs = " ".join(build(i, dev) for i, dev in enumerate(self.deviationFromMajorScale)) schemepairs = " ".join(schemepairs.split()) # split and join again to reduce all whitespaces to single ones. assert schemepairs #For Transposition in lilypond we need to explicitly export all scheme pairs, not only the one that differ from major. diff --git a/engine/lilypond.py b/engine/lilypond.py index 4ab4f13..0cc69c7 100644 --- a/engine/lilypond.py +++ b/engine/lilypond.py @@ -180,7 +180,7 @@ def processData(data): def structure(track, lilypondTrack): """ \new Staff = "tgliHJuGCFAIICICBEHBJABHIJE_Staff" << \\new Voice = "tgliHJuGCFAIICICBEHBJABHIJE" \tgliHJuGCFAIICICBEHBJABHIJE >> %EndTrack """ name = stringToCharsOnlyString(track.name) - instruments = '\\with {{ \n instrumentName = #"{}" \n shortInstrumentName = #"{}" }}'.format(lilyfy(track.initialInstrumentName), lilyfy(track.initialShortInstrumentName)) + instruments = '\\with {{ \n instrumentName = #"{}" \n shortInstrumentName = #"{}" }}\n'.format(lilyfy(track.initialInstrumentName), lilyfy(track.initialShortInstrumentName)) mergeTempo = "\\new Voice = \"Tempo\" \\tempoStaff" return """\\new Staff = "{}_Staff" {} << {} \\new Voice = "{}" \{} >> %EndTrack""".format(name, instruments, mergeTempo, name, name) diff --git a/engine/resources/lilypondTemplates/default.ly b/engine/resources/lilypondTemplates/default.ly index 95c2d9b..fced5a6 100644 --- a/engine/resources/lilypondTemplates/default.ly +++ b/engine/resources/lilypondTemplates/default.ly @@ -2,7 +2,7 @@ %% Generation Date: %$$DATE$$ %% Filename: %$$FILENAME$$ -\version "2.18" +\version "2.22" #(set-default-paper-size "a4") #(set-global-staff-size 18 ) #(ly:set-option 'point-and-click #f)