Many thanks for this! For my case the hairpin-attached text will have a different size to other text anyway, so a slight difference is perfectly fine.
Best, David On Wed, 27 Jan 2021 at 22:59, Thomas Morley <thomasmorle...@gmail.com> wrote: > > Am Mi., 27. Jan. 2021 um 21:32 Uhr schrieb David Stephen Grant > <da...@davidgrant.no>: > > > > Hi all, > > > > For "Center text below hairpin dynamics" in the LSR > > (http://lsr.di.unimi.it/LSR/Snippet?id=233) I'd like the text to scale > > with the staff size for ossia staves. Does anyone have any pointers? > > > > hairpinWithCenteredText = > > #(define-music-function (parser location text) (markup?) > > #{ > > \once \override Voice.Hairpin.after-line-breaking = > > #(lambda (grob) > > (let* ((stencil (ly:hairpin::print grob)) > > (par-y (ly:grob-parent grob Y)) > > (dir (ly:grob-property par-y 'direction)) > > (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)) > > (new-stencil (ly:stencil-aligned-to > > (ly:stencil-combine-at-edge > > (ly:stencil-aligned-to stencil X CENTER) > > Y dir > > (ly:stencil-aligned-to > > (grob-interpret-markup grob text) X CENTER)) > > X LEFT)) > > (par-x (ly:grob-parent grob X)) > > (dyn-text (grob::has-interface par-x > > 'dynamic-text-interface)) > > (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)))) > > #}) > > > > hairpinPoco = > > \hairpinWithCenteredText \markup { \fontsize #-1 "poco" } > > > > music = { > > \hairpinPoco > > c'4 \< e' f' g' \! > > } > > > > \score { > > << > > \new Staff \with { > > fontSize = #-5 > > \override StaffSymbol.staff-space = #(magstep -5) > > } \music > > \new Staff \music > > >> > > } > > > > Hi David, > > below does a fairly good job. > Alas, it's not perfect: The added TextScript does not have exactly the > same size as the text added text to the hairpin and I have no clue why > not ... > > hairpinWithCenteredText = > #(define-music-function (parser location text) (markup?) > #{ > \once \override Voice.Hairpin.after-line-breaking = > #(lambda (grob) > (let* ((stencil (ly:hairpin::print grob)) > (par-y (ly:grob-parent grob Y)) > (dir (ly:grob-property par-y 'direction)) > (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)) > (new-stencil (ly:stencil-aligned-to > (ly:stencil-combine-at-edge > (ly:stencil-aligned-to stencil X CENTER) > Y dir > (ly:stencil-aligned-to > (grob-interpret-markup > grob > (make-fontsize-markup > (magnification->font-size > (+ (ly:staff-symbol-staff-space grob) > (/ staff-line-thickness 2))) > text)) X CENTER)) > X LEFT)) > (par-x (ly:grob-parent grob X)) > (dyn-text (grob::has-interface par-x 'dynamic-text-interface)) > (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)))) > #}) > > hairpinPoco = > \hairpinWithCenteredText \markup { \fontsize #-1 "poco" } > > music = { > \hairpinPoco > c'4 \<_"poco" e' f' g' \! > } > > val = #-5 > > \score { > << > \new Staff \with { > fontSize = \val > \override StaffSymbol.staff-space = #(magstep val) > } \music > \new Staff \music > >> > } > > Cheers, > Harm -- David Stephen Grant da...@davidgrant.no www.davidgrant.no Phone: (+47) 918 14 276