Sorry, my bad. I set \lower #2 (and the result was the same) because I
assumed that \lower made an offset from the bottom of the hairpin, but this
is not the case. Using a bigger value did the trick. Thanks for the
additional tip too!

On Sun, Dec 12, 2021 at 3:52 PM Jean Abou Samra <j...@abou-samra.fr> wrote:

>
>
> Le 12/12/2021 à 15:05, Paolo Prete a écrit :
> >
> >
> > On Sun, Dec 12, 2021 at 2:56 PM Jean Abou Samra <j...@abou-samra.fr>
> > wrote:
> >
> >
> >
> >     Le 12/12/2021 à 14:28, Paolo Prete a écrit :
> >     > Hello,
> >     >
> >     > it would be good to have more control on the text centered on a
> >     hairpin.
> >     >
> >     > For example: I can't shift the text vertically, and I think this is
> >     > useful because sometime the text is too near the hairpin.
> >     >
> >     > I tried \lower #offset inside the markup but it doesn't work,
> >     how can
> >     > I fix this?
> >     >
> >     > Thank you very much!
> >     >
> >     > %%%%%
> >     > hairpinWithCenteredText =
> >     > #(define-music-function (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))
> >     >                (new-stencil (ly:stencil-aligned-to
> >     >                  (ly:stencil-combine-at-edge
> >
> >
> >     Try replacing this one with ly:stencil-stack.
> >
> >
> > Do you mean ly:stencil-combine-at-edge replaced with ly:stencil-stack
> > ? I tried it, but the result is the same (with \lower #offset inside
> > the markup)
> >
> > thanks,
> >
> > Paolo
>
>
>
> What version do you have? This works over here;
>
> \version "2.22.1"
>
> %%%%%
> hairpinWithCenteredText =
> #(define-music-function (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))
>                 (new-stencil (ly:stencil-aligned-to
>                   (ly:stencil-stack
>                     (ly:stencil-aligned-to stencil X CENTER)
>                     Y dir
>                     (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))
>                 (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))))
>    #})
>
> hairpinMolto =
> \hairpinWithCenteredText \markup { \italic molto }
>
> hairpinMore =
> \hairpinWithCenteredText \markup { \larger \lower #10 moltissimo }
>
> \layout { ragged-right = ##f }
>
> \relative c' {
>    \hairpinMolto
>    c2\< c\f
>    \hairpinMore
>    c2\ppppp\< c\f
>    \break
>    \hairpinMolto
>    c2^\< c\f
>    \hairpinMore
>    c2\ppppp\< c\f
> }
> %%%%%
>
>
> Note that ly:stencil-stack will still prevent the stencils
> from getting too close, while allowing them to get farther
> from each other. I inferred this was not an issue from
> you problem statement that "sometimes the text is too
> near to the hairpin". If it is, you can use ly:stencil-add,
> removing the line with "Y dir", and put \lower in each markup
> as appropriate. You can also keep the original code and use
> \with-dimensions, or \with-dimension from
> https://lists.gnu.org/archive/html/lilypond-user/2020-12/msg00196.html,
> to give the "moltissimo" text a different extent
> altogether.
>
> \version "2.22.1"
>
> #(define-markup-command
>    (with-dimension layout props axis interval markup)
>    (number? number-pair? markup?)
>    (let* ((sten (interpret-markup layout props markup))
>           (xex (ly:stencil-extent sten X))
>           (yex (ly:stencil-extent sten Y)))
>     (ly:make-stencil
>      (ly:stencil-expr sten)
>      (if (eq? X axis) interval xex)
>      (if (eq? Y axis) interval yex))))
>
> hairpinWithCenteredText =
> #(define-music-function (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))
>                 (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))
>                 (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))
>                 (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))))
>    #})
>
> hairpinMolto =
> \hairpinWithCenteredText \markup { \italic molto }
>
> hairpinMore =
> \hairpinWithCenteredText \markup { \larger \with-dimension #Y #'(0 . 4)
> moltissimo }
>
> \layout { ragged-right = ##f }
>
> \relative c' {
>    \hairpinMolto
>    c2\< c\f
>    \hairpinMore
>    c2\ppppp\< c\f
>    \break
>    \hairpinMolto
>    c2^\< c\f
>    \hairpinMore
>    c2\ppppp\< c\f
> }
> %%%%%
>
> Best,
> Jean
>

Reply via email to