]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix parenthesize to work with single notes, rests and whole chords
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 30 Mar 2008 11:45:00 +0000 (13:45 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 30 Mar 2008 11:45:00 +0000 (13:45 +0200)
By default, Lilypond's \parenthesize function (to put parentheses around notes,
articulations, etc.) only works on notes if they are written inside a chord.
In particular, \parenthesize c4 will not work, only <\parenthesize c>4 will.
Similarly, trying to parenthesize a rest will fail. The reason is that
internally, Lilypond understands c4 as <c>4, so the first example is
internally the same as \parenthesize <c>4. The apparent solution is to make
\parenthesize apply to all elements inside a chord instead of the chord
itself (which the current implementation does).

In fact, one can simply redefine the \parenthesize function, which sets
the parenthesize property of a music expression to ##t, so that if applied
to a chord, it will set this property for all note and rest children of a
chord. This immediately solves the problem of parenthesizing rests, as well
as allowing the parenthesizing of all notes inside a chord at once. All
other uses of \parenthesize continue working as usual. So, using the
redefinition of \parenthesize from the snippet, finally the following
commands work as expected:

    \parenthesize c4-. \parenthesize r4 \parenthesize <c e g>4->

ly/music-functions-init.ly

index 95b5cc5cc87eb25ae32d07079b7a9c76a6a2cd92..3f9ad80c5ddbf04a20c2f879ff9e5da8ae0e452d 100644 (file)
@@ -476,7 +476,16 @@ parenthesize =
 #(define-music-function (parser loc arg) (ly:music?)
    (_i "Tag @var{arg} to be parenthesized.")
 
-   (set! (ly:music-property arg 'parenthesize) #t)
+   (if (memq 'event-chord (ly:music-property arg 'types))
+     ; arg is an EventChord -> set the parenthesize property on all child notes and rests
+     (map
+       (lambda (ev)
+         (if (or (memq 'note-event (ly:music-property ev 'types))
+                 (memq 'rest-event (ly:music-property ev 'types)))
+           (set! (ly:music-property ev 'parenthesize) #t)))
+       (ly:music-property arg 'elements))
+     ; No chord, simply set property for this expression:
+     (set! (ly:music-property arg 'parenthesize) #t))
    arg)
 
 %% for lambda*