From a832824cc2ee8e90f4fadb580427eb3e362addb4 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Sat, 29 Mar 2008 01:37:49 +0100 Subject: [PATCH] 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-> --- .../parenthesize-singlenotes-chords-rests.ly | 25 ++++++++++++++++++++ ly/music-functions-init.ly | 14 ++++++++++- 2 files changed, 38 insertions(+), 1 deletions(-) create mode 100644 input/regression/parenthesize-singlenotes-chords-rests.ly diff --git a/input/regression/parenthesize-singlenotes-chords-rests.ly b/input/regression/parenthesize-singlenotes-chords-rests.ly new file mode 100644 index 0000000..7fc5f1e --- /dev/null +++ b/input/regression/parenthesize-singlenotes-chords-rests.ly @@ -0,0 +1,25 @@ + +\header { + texidoc = "The parenthesize function should also work on single notes (not inside chords), rests and on whole chords (each note of the chord is parenthesized). Also, parenthesizing articulations, dynamics and text markup is possible. On all other music expressions, parenthesize does not have an effect. + + Measure 1: Three parenthesized notes (staccato not parenthesized), one note with staccato in parentheses; Measure 2: Chord and two rests in parentheses (accent and markup not); Measure 3: note (no parentheses) with \p in parentheses, with text in parentheses, and note in parentheses with p not in parentheses, rest (no parentheses); Measure 4: shows that \parenthesize does not apply to other expressions like SequentialMusic" +} + + +\paper { + ragged-right = ##t +} + +\version "2.11.43" + + +\relative c'' { + % parentheses on single notes (with articulations), inside chord and articulation + \parenthesize c \parenthesize c-. <\parenthesize c> c-\parenthesize-. | + % parenthesized rests and whole chords + \parenthesize 4-> \parenthesize r \parenthesize r2^"rest" | + % parenthesizing dynamics and text markup + c4-\parenthesize\p c-\parenthesize-"Text" \parenthesize c\p r4 | + % parenthesizing other music expressions does nothing + \parenthesize {c4 c-. r} \parenthesize| +} diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 95b5cc5..4fb69b6 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -476,7 +476,19 @@ 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* -- 1.5.4.4