Hi everyone, I'm working on a score where I need hairpins to end on a specific text. I do this because I don't really like the hairpins with a circle tip. I prefer to use "n." for niente and "pd." for perdendosi (the first one for strings, the second one for winds).
Now, on some occasions the hairpin must end with the text placed just before the bar line, like this: <http://lilypond.1069038.n5.nabble.com/file/n165055/Screen_Shot_2014-07-28_at_11.png> As I find the typical solution of creating a second voice with spacers rather clumsy, I managed to come up with a better one by tweaking the snippet for placing text under a hairpin. However, I'm know nothing of scheme so my solution is far from perfect. The code is here: hairpinWithRightText = #(define-music-function (parser location text) (markup?) #{ \once \override Voice.Hairpin.after-line-breaking = #(lambda (grob) (let* ((stencil (ly:hairpin::print grob)) (new-stencil (ly:stencil-aligned-to (ly:stencil-combine-at-edge (ly:stencil-aligned-to stencil X RIGHT) Y CENTER (ly:stencil-aligned-to (grob-interpret-markup grob text) X CENTER)) X LEFT)) (staff-space (ly:output-def-lookup (ly:grob-layout grob) 'staff-space)) (staff-line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness)) (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name))) (par-x (ly:grob-parent grob X)) (dyn-text (eq? (grob-name par-x) 'DynamicText )) (dyn-text-stencil-x-length (if dyn-text (interval-length (ly:stencil-extent (ly:grob-property par-x 'stencil) X)) 0)) (x-shift (if dyn-text (- (+ staff-space dyn-text-stencil-x-length) (* 0.5 staff-line-thickness)) 0))) (ly:grob-set-property! grob 'Y-offset 0) (ly:grob-set-property! grob 'stencil (ly:stencil-translate-axis new-stencil x-shift X)))) #}) hairpinN = { \override Hairpin #'bound-padding = #2.3 \once \hairpinWithRightText \markup { \italic " n." } } hairpinPD = { \override Hairpin #'bound-padding = #3.2 \once \hairpinWithRightText \markup { \italic " pd." } } If you check the original code for this snippet, you will see that I just changed the word "dir" for CENTER, on the 10th line of hairpinWithRightText. I have then defined the two hairpins and placed a lot of spaces before each text. Then, I have increased the padding of the hairpins so that they leave enough space for the text. The result is here: <http://lilypond.1069038.n5.nabble.com/file/n165055/Screen_Shot_2014-07-28_at_11.png> Not a bad result, but the "pd." is not properly aligned (verticaly). See how the "pd." is placed when attached to a rest: <http://lilypond.1069038.n5.nabble.com/file/n165055/Screen_Shot_2014-07-28_at_11.png> You can see the vertical alignment is not the same. It's a tiny difference but I would like it to be perfect. Also, my solution is not really very elegant, is it? Can anyone who knows scheme find a better way to do this? Something simple, effective and accurate? I would appreciate very much any help on this. Antonio P.S.: this could also be used to end hairpins with normal dynamic text, thus avoiding the tiresome solution of writing a second voice with spacers. -- View this message in context: http://lilypond.1069038.n5.nabble.com/Haipins-ending-with-text-scheme-help-tp165055.html Sent from the User mailing list archive at Nabble.com. _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user