Browse Source

Partial support for ties and keysigns in lilypond. Lilypond syntax changed again

master
Nils 5 years ago
parent
commit
6366af1563
  1. 30
      engine/items.py
  2. 3
      engine/resources/lilypondTemplates/default.ly
  3. 2
      template

30
engine/items.py

@ -571,7 +571,7 @@ class Duration(object):
else: else:
append = "" append = ""
n = self.genericNumber n = self.genericNumber
if n == 0: if n == 0:
return "\\breve" + append return "\\breve" + append
elif n == -1: elif n == -1:
@ -1701,13 +1701,15 @@ class Chord(Item):
substrings = [] substrings = []
minimumTicksInChord = self.durationGroup.completeDuration() 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 #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 #dur = lilydur + " * {}/{}".format(factor.denominator, factor.numerator) #lilypond requires the 1/x syntax
assert int(ticks) == ticks, ticks assert int(ticks) == ticks, ticks
assert int(minimumTicksInChord) == minimumTicksInChord, minimumTicksInChord assert int(minimumTicksInChord) == minimumTicksInChord, minimumTicksInChord
assert minimumTicksInChord <= ticks assert minimumTicksInChord <= ticks
dur = lilydur + " * {}/{}".format(int(minimumTicksInChord), int(ticks)) #lilypond requires the x/y syntax, even if it is 1/x 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 + " }" ) substrings.append("\\\\ { <" + " ".join(lst) + ">" + dur + " }" )
result = "<<" + " ".join(substrings) + ">>" result = "<<" + " ".join(substrings) + ">>"
return result return result
@ -2148,13 +2150,23 @@ class KeySignature(Item):
return "" return ""
#G Major ((3, 10), (0, 0), (4, 0), (1, 0), (5, 0), (2, 0), (6, 0)) #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)) #`((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(x[0], x[1]) for x in self.keysigList)
schemepairs = " ".join(schemepairs.split()) # split and join again to reduce all whitespaces to single ones. 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 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) lyKeysignature = subtextRoot + "\\set Staff.keyAlterations = #`( {} )".format(schemepairs)
return lyKeysignature 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): class Clef(Item):
"""A clef has no direct musical logical meaning. But it gives some hints: """A clef has no direct musical logical meaning. But it gives some hints:

3
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 %Exchange note_heads_engraver with the completition variant which auto-ties notes on bar-breaks
\remove "Note_heads_engraver" \remove "Note_heads_engraver"
\consists "Completion_heads_engraver" \consists "Completion_heads_engraver"
\remove "Rest_engraver"
\consists "Completion_rest_engraver"
tieWaitForNote = ##t tieWaitForNote = ##t
} }
\context { \Staff \context { \Staff
\RemoveEmptyStaves \RemoveEmptyStaves

2
template

@ -1 +1 @@
Subproject commit ff789798793af4981fe81b9d6f769a975735faea Subproject commit bb6ae017b284957b6e1e3756599ba17aefc3322a
Loading…
Cancel
Save