From: Reinhold Kainhofer Date: Sun, 30 Mar 2008 11:45:00 +0000 (+0200) Subject: Fix parenthesize to work with single notes, rests and whole chords X-Git-Tag: release/2.11.44-1~64 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5e864591ae95b497cc6d85831565fca65d610e29;p=lilypond.git Fix parenthesize to work with single notes, rests and whole chords 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 4, so the first example is internally the same as \parenthesize 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 4-> --- diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 95b5cc5cc8..3f9ad80c5d 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -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*