Skip to content

Commit 2554e64

Browse files
authored
Merge pull request #1800 from jeremy9959/jeremy9959-1791
Update of property assignment syntax for Lilypond conversion (issue #1791)
2 parents eb5a88f + ed9f50f commit 2554e64

File tree

2 files changed

+70
-72
lines changed

2 files changed

+70
-72
lines changed

music21/lily/lilyObjects.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
# Purpose: python objects representing lilypond
55
#
66
# Authors: Michael Scott Asato Cuthbert
7+
# Jeremy Teitelbaum (Lilypond 2.24 adaptations)
78
#
8-
# Copyright: Copyright © 2007-2012 Michael Scott Asato Cuthbert
9+
# Copyright: Copyright © 2007-2025 Michael Scott Asato Cuthbert
910
# License: BSD, see license.txt
1011
# ------------------------------------------------------------------------------
1112
'''
1213
music21 translates to Lilypond format and if Lilypond is installed on the
1314
local computer, can automatically generate .pdf, .png, and .svg versions
14-
of musical files using Lilypond
15-
16-
this replaces (April 2012) the old LilyString() conversion methods.
15+
of musical files using Lilypond.
1716
1817
The Grammar for Lilypond comes from
1918
http://lilypond.org/doc/v2.14/Documentation/notation/lilypond-grammar
@@ -778,13 +777,12 @@ def stringOutput(self):
778777
else:
779778
return self.outputDef.stringOutput()
780779

781-
782780
class LyLayout(LyObject):
783781
def stringOutput(self):
784782
theseStrings = [self.backslash + 'layout {',
785783
' ' + self.backslash + 'context {',
786-
' ' + self.backslash + 'RemoveEmptyStaffContext',
787-
' ' + self.backslash + "override VerticalAxisGroup #'remove-first = ##t",
784+
' ' + self.backslash + 'RemoveEmptyStaves',
785+
' ' + self.backslash + 'override VerticalAxisGroup.remove-first = ##t',
788786
' ' + '}', '}']
789787

790788
return self.newlineSeparateStringOutputIfNotNone(theseStrings)
@@ -1482,11 +1480,11 @@ class LyPropertyOperation(LyObject):
14821480
14831481
>>> lpo = lily.lilyObjects.LyPropertyOperation('override', 'simple', 'x', 'y')
14841482
>>> str(lpo)
1485-
'\\override simple x = y '
1483+
'\\override simple.x = y '
14861484
14871485
>>> lpo = lily.lilyObjects.LyPropertyOperation('revert', 'x', 'y')
14881486
>>> str(lpo)
1489-
'\\revert x y '
1487+
'\\revert x.y '
14901488
14911489
TODO: should \set be given?
14921490
'''
@@ -1507,10 +1505,10 @@ def stringOutput(self):
15071505
elif self.mode == 'unset':
15081506
return self.backslash + 'unset ' + self.value1 + ' '
15091507
elif self.mode == 'override':
1510-
return ''.join([self.backslash, 'override ', self.value1, ' ', self.value2,
1508+
return ''.join([self.backslash, 'override ', self.value1, '.', self.value2,
15111509
' = ', self.value3, ' '])
15121510
elif self.mode == 'revert':
1513-
return self.backslash + 'revert ' + self.value1 + ' ' + self.value2 + ' '
1511+
return self.backslash + 'revert ' + self.value1 + '.' + self.value2 + ' '
15141512

15151513

15161514
class LyContextDefMod(LyObject):

music21/lily/translate.py

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ class LilypondConverter:
9898
colorDef = (
9999
r'''
100100
color = #(define-music-function (parser location color) (string?) #{
101-
\once \override NoteHead #'color = #(x11-color color)
102-
\once \override Stem #'color = #(x11-color color)
103-
\once \override Rest #'color = #(x11-color color)
104-
\once \override Beam #'color = #(x11-color color)
101+
\once \override NoteHead.color = #(x11-color color)
102+
\once \override Stem.color = #(x11-color color)
103+
\once \override Rest.color = #(x11-color color)
104+
\once \override Beam.color = #(x11-color color)
105105
#})
106106
'''.lstrip())
107107
simplePaperDefinitionScm = r'''
@@ -114,8 +114,8 @@ class LilypondConverter:
114114
}
115115
'''.lstrip()
116116
transparencyStartScheme = r'''
117-
\override Rest #'transparent = ##t
118-
\override Dots #'transparent = ##t
117+
\override Rest.transparent = ##t
118+
\override Dots.transparent = ##t
119119
'''.lstrip()
120120
transparencyStopScheme = r'''
121121
\revert Rest #'transparent
@@ -261,10 +261,10 @@ def textFromMusic21Object(self, m21ObjectIn):
261261
\version "2..."
262262
\include "lilypond-book-preamble.ly"
263263
color = #(define-music-function (parser location color) (string?) #{
264-
\once \override NoteHead #'color = #(x11-color color)
265-
\once \override Stem #'color = #(x11-color color)
266-
\once \override Rest #'color = #(x11-color color)
267-
\once \override Beam #'color = #(x11-color color)
264+
\once \override NoteHead.color = #(x11-color color)
265+
\once \override Stem.color = #(x11-color color)
266+
\once \override Rest.color = #(x11-color color)
267+
\once \override Beam.color = #(x11-color color)
268268
#})
269269
\header { }
270270
\score {
@@ -463,12 +463,12 @@ def lyPartsAndOssiaInitFromScore(self, scoreIn):
463463
\remove "Time_signature_engraver"
464464
alignAboveContext = #"pa"
465465
fontSize = #-3
466-
\override StaffSymbol #'staff-space = #(magstep -3)
467-
\override StaffSymbol #'thickness = #(magstep -3)
468-
\override TupletBracket #'bracket-visibility = ##f
469-
\override TupletNumber #'stencil = ##f
470-
\override Clef #'transparent = ##t
471-
\override OctavateEight #'transparent = ##t
466+
\override StaffSymbol.staff-space = #(magstep -3)
467+
\override StaffSymbol.thickness = #(magstep -3)
468+
\override TupletBracket.bracket-visibility = ##f
469+
\override TupletNumber.stencil = ##f
470+
\override Clef.transparent = ##t
471+
\override OctavateEight.transparent = ##t
472472
\consists "Default_bar_line_engraver"
473473
}
474474
{ \stopStaff s1 s1 s1 s1 }
@@ -477,12 +477,12 @@ def lyPartsAndOssiaInitFromScore(self, scoreIn):
477477
\remove "Time_signature_engraver"
478478
alignAboveContext = #"pa"
479479
fontSize = #-3
480-
\override StaffSymbol #'staff-space = #(magstep -3)
481-
\override StaffSymbol #'thickness = #(magstep -3)
482-
\override TupletBracket #'bracket-visibility = ##f
483-
\override TupletNumber #'stencil = ##f
484-
\override Clef #'transparent = ##t
485-
\override OctavateEight #'transparent = ##t
480+
\override StaffSymbol.staff-space = #(magstep -3)
481+
\override StaffSymbol.thickness = #(magstep -3)
482+
\override TupletBracket.bracket-visibility = ##f
483+
\override TupletNumber.stencil = ##f
484+
\override Clef.transparent = ##t
485+
\override OctavateEight.transparent = ##t
486486
\consists "Default_bar_line_engraver"
487487
}
488488
{ \stopStaff s1 s1 s1 s1 }
@@ -492,12 +492,12 @@ def lyPartsAndOssiaInitFromScore(self, scoreIn):
492492
\remove "Time_signature_engraver"
493493
alignAboveContext = #"pb...
494494
fontSize = #-3
495-
\override StaffSymbol #'staff-space = #(magstep -3)
496-
\override StaffSymbol #'thickness = #(magstep -3)
497-
\override TupletBracket #'bracket-visibility = ##f
498-
\override TupletNumber #'stencil = ##f
499-
\override Clef #'transparent = ##t
500-
\override OctavateEight #'transparent = ##t
495+
\override StaffSymbol.staff-space = #(magstep -3)
496+
\override StaffSymbol.thickness = #(magstep -3)
497+
\override TupletBracket.bracket-visibility = ##f
498+
\override TupletNumber.stencil = ##f
499+
\override Clef.transparent = ##t
500+
\override OctavateEight.transparent = ##t
501501
\consists "Default_bar_line_engraver"
502502
}
503503
{ \stopStaff s1 s1 s1 s1 }
@@ -506,12 +506,12 @@ def lyPartsAndOssiaInitFromScore(self, scoreIn):
506506
\remove "Time_signature_engraver"
507507
alignAboveContext = #"pb...
508508
fontSize = #-3
509-
\override StaffSymbol #'staff-space = #(magstep -3)
510-
\override StaffSymbol #'thickness = #(magstep -3)
511-
\override TupletBracket #'bracket-visibility = ##f
512-
\override TupletNumber #'stencil = ##f
513-
\override Clef #'transparent = ##t
514-
\override OctavateEight #'transparent = ##t
509+
\override StaffSymbol.staff-space = #(magstep -3)
510+
\override StaffSymbol.thickness = #(magstep -3)
511+
\override TupletBracket.bracket-visibility = ##f
512+
\override TupletNumber.stencil = ##f
513+
\override Clef.transparent = ##t
514+
\override OctavateEight.transparent = ##t
515515
\consists "Default_bar_line_engraver"
516516
}
517517
{ \stopStaff s1 s1 s1 s1 }
@@ -548,12 +548,12 @@ def lyPartsAndOssiaInitFromScore(self, scoreIn):
548548
contextModList = [r'\remove "Time_signature_engraver"',
549549
fr'alignAboveContext = #"{partIdText}"',
550550
r'fontSize = #-3',
551-
r"\override StaffSymbol #'staff-space = #(magstep -3)",
552-
r"\override StaffSymbol #'thickness = #(magstep -3)",
553-
r"\override TupletBracket #'bracket-visibility = ##f",
554-
r"\override TupletNumber #'stencil = ##f",
555-
r"\override Clef #'transparent = ##t",
556-
r"\override OctavateEight #'transparent = ##t",
551+
r'\override StaffSymbol.staff-space = #(magstep -3)',
552+
r'\override StaffSymbol.thickness = #(magstep -3)',
553+
r'\override TupletBracket.bracket-visibility = ##f',
554+
r'\override TupletNumber.stencil = ##f',
555+
r'\override Clef.transparent = ##t',
556+
r'\override OctavateEight.transparent = ##t',
557557
r'\consists "Default_bar_line_engraver"',
558558
]
559559
optionalContextMod = lyo.LyContextModification(contextModList)
@@ -639,22 +639,22 @@ def lyGroupedMusicListFromScoreWithParts(self, scoreIn, scoreInit=None):
639639
\key fis \minor
640640
\time 4/4
641641
\set stemRightBeamCount = #1
642-
\once \override Stem #'direction = #DOWN
642+
\once \override Stem.direction = #DOWN
643643
cis'' 8 [
644644
\set stemLeftBeamCount = #1
645-
\once \override Stem #'direction = #DOWN
645+
\once \override Stem.direction = #DOWN
646646
b... 8 ]
647647
\bar "|" %{ end measure 0 %}
648-
\once \override Stem #'direction = #UP
648+
\once \override Stem.direction = #UP
649649
a' 4
650-
\once \override Stem #'direction = #DOWN
650+
\once \override Stem.direction = #DOWN
651651
b... 4
652-
\once \override Stem #'direction = #DOWN
652+
\once \override Stem.direction = #DOWN
653653
cis'' 4 \fermata
654-
\once \override Stem #'direction = #DOWN
654+
\once \override Stem.direction = #DOWN
655655
e'' 4
656656
\bar "|" %{ end measure 1 %}
657-
\once \override Stem #'direction = #DOWN
657+
\once \override Stem.direction = #DOWN
658658
cis'' 4
659659
...
660660
}
@@ -665,12 +665,12 @@ def lyGroupedMusicListFromScoreWithParts(self, scoreIn, scoreInit=None):
665665
}
666666
{ \startStaff \partial 32*8
667667
\clef "treble"...
668-
\once \override Stem #'direction = #UP
668+
\once \override Stem.direction = #UP
669669
e' 4
670670
\bar "|" %{ end measure 0 %}
671-
\once \override Stem #'direction = #UP
671+
\once \override Stem.direction = #UP
672672
fis' 4
673-
\once \override Stem #'direction = #UP
673+
\once \override Stem.direction = #UP
674674
e' 4
675675
...
676676
}
@@ -872,7 +872,7 @@ def lyPrefixCompositeMusicFromStream(
872872
<music21.lily.lilyObjects.LyPrefixCompositeMusic \new Staff...>
873873
>>> print(lyPrefixCompositeMusicOut)
874874
\new Staff = ... \with {
875-
\override StaffSymbol #'line-count = #4
875+
\override StaffSymbol.line-count = #4
876876
}
877877
{ \clef "bass"
878878
\time 3/4
@@ -908,7 +908,7 @@ def lyPrefixCompositeMusicFromStream(
908908
contextModList.append(r'\autoBeamOff ')
909909

910910
if hasattr(streamIn, 'staffLines') and streamIn.staffLines != 5:
911-
contextModList.append(fr"\override StaffSymbol #'line-count = #{streamIn.staffLines}")
911+
contextModList.append(fr'\override StaffSymbol.line-count = #{streamIn.staffLines}')
912912
if streamIn.staffLines % 2 == 0: # even stafflines need a change
913913
pass
914914

@@ -1409,12 +1409,12 @@ def appendStemCode(self, noteOrChord):
14091409
>>> print(lpc.context.contents)
14101410
[<music21.lily.lilyObjects.LyEmbeddedScm \once \ove...>]
14111411
>>> print(lpc.context.contents[0])
1412-
\once \override Stem #'direction = #UP
1412+
\once \override Stem.direction = #UP
14131413
'''
14141414
if hasattr(noteOrChord, 'stemDirection') and noteOrChord.stemDirection is not None:
14151415
stemDirection = noteOrChord.stemDirection.upper()
14161416
if stemDirection in ['UP', 'DOWN']:
1417-
stemFile = fr'''\once \override Stem #'direction = #{stemDirection} '''
1417+
stemFile = fr'''\once \override Stem.direction = #{stemDirection} '''
14181418
lpStemScheme = lyo.LyEmbeddedScm(stemFile)
14191419
self.context.contents.append(lpStemScheme)
14201420
lpStemScheme.setParent(self.context)
@@ -2203,13 +2203,13 @@ def lyPrefixCompositeMusicFromVariant(self,
22032203
# \remove "Time_signature_engraver"
22042204
# alignAboveContext = #"%s"
22052205
# fontSize = #-3
2206-
# \override StaffSymbol #'staff-space = #(magstep -3)
2207-
# \override StaffSymbol #'thickness = #(magstep -3)
2208-
# \override TupletBracket #'bracket-visibility = ##f
2209-
# \override TupletNumber #'stencil = ##f
2210-
# \override Clef #'transparent = ##t
2206+
# \override StaffSymbol.staff-space = #(magstep -3)
2207+
# \override StaffSymbol.thickness = #(magstep -3)
2208+
# \override TupletBracket.bracket-visibility = ##f
2209+
# \override TupletNumber.stencil = ##f
2210+
# \override Clef.transparent = ##t
22112211
# }
2212-
# ''' % containerId #\override BarLine #'transparent = ##t
2212+
# ''' % containerId #\override BarLine.transparent = ##t
22132213
# # is the best way of fixing the #barlines that I have come up with.
22142214
# lpPrefixCompositeMusicVariant.optionalContextMod = optionalContextMod
22152215

@@ -2454,8 +2454,8 @@ def runThroughLily(self, format=None,
24542454
lilyCommand += '-f ' + format + ' '
24552455
if backend is not None:
24562456
lilyCommand += self.backendString + backend + ' '
2457-
lilyCommand += '-o ' + str(fileName) + ' ' + str(fileName)
24582457

2458+
lilyCommand += '-o ' + str(fileName) + ' ' + str(fileName)
24592459
os.system(lilyCommand)
24602460

24612461
try:

0 commit comments

Comments
 (0)