2018-04-24 9:51 GMT+02:00 Davide Liessi <davide.lie...@gmail.com>: > Dear all, > I need to engrave a hairpin in brackets after a \fz. > I tried LSR 771 (http://lsr.di.unimi.it/LSR/Item?id=771) with the > following results: > > \version "2.19.65" > > %http://lsr.di.unimi.it/LSR/Item?id=771 > hairpinBetweenText = > #(define-music-function (leftText rightText) (markup? markup?) > #{ > \once \override Hairpin.stencil = > #(lambda (grob) > (ly:stencil-combine-at-edge > (ly:stencil-combine-at-edge > (ly:stencil-aligned-to (grob-interpret-markup grob leftText) Y > CENTER) > X RIGHT > (ly:stencil-aligned-to (ly:hairpin::print grob) Y CENTER) > 0.6) > X RIGHT > (ly:stencil-aligned-to (grob-interpret-markup grob rightText) Y > CENTER) > 0.6)) > #}) > > music = { c'1\fz\> c' c' c' d'1\! } > > \score { > << > \new Staff { > \music > } > \new Staff { > \hairpinBetweenText "[" "]" > \music > } > \new Staff { > \once \hide DynamicText > \hairpinBetweenText \markup { \dynamic { fz } "[" } "]" > \music > } > \new Staff { > \once \override Hairpin.shorten-pair = #'(0 . 2) > \once \hide DynamicText > \hairpinBetweenText \markup { \dynamic { fz } "[" } "]" > \music > } > >> > } > > Is there a way to make the second Staff look like the last one? > I.e., is it possible to avoid the clash between the dynamic mark and > the hairpin and to automatically shorten the hairpin? > > (By the way, in the third and fourth Staff hiding the DynamicText is > not necessary, since the normal \fz and the one in \hairpinBetweenText > are perfectly aligned; however if the DynamicText is omitted instead > of hidden the hairpin is shifted to the right, which I didn't expect.) > > Best wishes. > Davide
How about below? It is ensured the bracketed hairpin is always of equal length as the original. Ofcourse this means the visible hairpin is shortened a little. Applying 'shorten-pair is still possible, though. The "kerning" is adjustable. \version "2.19.81" #(define (hairpin-between-text kern left-text right-text) (lambda (grob) (let* ((v-centered-left-text (ly:stencil-aligned-to (grob-interpret-markup grob left-text) Y CENTER)) (left-text-x-ext (ly:stencil-extent v-centered-left-text X)) (v-centered-right-text (ly:stencil-aligned-to (grob-interpret-markup grob right-text) Y CENTER)) (right-text-x-ext (ly:stencil-extent v-centered-right-text X)) (prev-shorten-pair (ly:grob-property grob 'shorten-pair '(0 . 0))) (thick (ly:grob-property grob 'thickness 1)) (line-thick (ly:staff-symbol-line-thickness grob)) (actual-thick (* thick line-thick)) (shorten (+ (* 2 kern) (cdr right-text-x-ext) (cdr left-text-x-ext) (- (* 2 actual-thick))))) (ly:grob-set-property! grob 'shorten-pair (coord-translate prev-shorten-pair (cons 0 shorten))) (let* ((v-centered-hairpin (ly:stencil-aligned-to (ly:hairpin::print grob) Y CENTER)) (hairpin-x-ext (ly:stencil-extent v-centered-hairpin X))) (ly:stencil-translate-axis (ly:stencil-add (ly:stencil-translate-axis v-centered-left-text (- (car hairpin-x-ext) (cdr left-text-x-ext) actual-thick) X) (ly:stencil-translate-axis v-centered-hairpin (- kern actual-thick) X) (ly:stencil-translate-axis v-centered-right-text (+ (cdr hairpin-x-ext) (* 2 kern)) X)) (cdr left-text-x-ext) X))))) hairpinBetweenText = #(define-music-function (space text-left text-right) ((number? 0.6) markup? markup?) #{ \once \override Hairpin.stencil = #(hairpin-between-text space text-left text-right) #}) music = { c'1\fff\> c' c' c' d'1\! } \score { << \new Staff { \music } \new Staff { \hairpinBetweenText "[" "]" \music } \new Staff { \hairpinBetweenText 0.2 "[" "]" \music } \new Staff { \override Hairpin.shorten-pair = #'(1 . 2) \hairpinBetweenText "[" "]" \music } >> } HTH, Harm _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user