Re: Issue when setting the font-name for a hairpin with centered text

2021-12-12 Thread Paolo Prete
Thank you, all clear!

On Sun, Dec 12, 2021 at 1:07 PM Jean Abou Samra  wrote:

> Le 12/12/2021 à 12:53, Paolo Prete a écrit :
> > Hello,
> >
> > I'm trying to set the font-name for a hairpin with centered text later
> > in the score, and not in the definition of the function.
> > However, my attempt, in the snippet below, doesn't work. How can I fix
> > this?
> >
> > Thanks,
> > P
> >
> > %
> > hairpinWithCenteredText =
> > #(define-music-function (text) (markup?)
> >   #{
> > \once \override Score.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
> >   #})
> >
> > #(define textFontName "Liberation Sans, Italic")
> >
> > hairpinPoco = {
> >   \once \override Score.DynamicLineSpanner.staff-padding = 2
> >   \hairpinWithCenteredText \markup { \override #(cons 'font-name
> > textFontName) \abs-fontsize #6 poco }
> > }
> >
> > {
> >
> > % The following command doesn't change the font name...
> > #(set! textFontName "Liberation Sans")
> > \hairpinPoco c'4\< c' c' c'\!
> >
> > }
>
>
>
> This is exactly the same as, in almost every language,
>
> a = "Liberation Sans, Italic"
> b = some_operation(a)
> a = "Liberation Sans"
>
> b is fixed at the time you define it. You're
> not using textFontName in a function, you
> just put its value in hairpinPoco. Once
> evaluated, hairpinPoco no longer depends
> on textFontName. Also, LilyPond does not
> process the score linearly in one pass. At
> the time at which the font name is retrieved,
> the music of the whole score has long been
> parsed, so it comes after your #(set! ...),
> but also after any other #(set! ...)s coming
> after the hairpin you want to customize.
> How about:
>
> \version "2.22.1"
>
> hairpinWithCenteredText =
> #(define-music-function (text) (markup?)
>#{
>  \once \override Score.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
>#})
>
>
> hairpinPoco = {
>\once \override Score.DynamicLineSpanner.staff-padding = 2
>\hairpinWithCen

Re: Issue when setting the font-name for a hairpin with centered text

2021-12-12 Thread Jean Abou Samra

Le 12/12/2021 à 12:53, Paolo Prete a écrit :

Hello,

I'm trying to set the font-name for a hairpin with centered text later 
in the score, and not in the definition of the function.
However, my attempt, in the snippet below, doesn't work. How can I fix 
this?


Thanks,
P

%
hairpinWithCenteredText =
#(define-music-function (text) (markup?)
  #{
    \once \override Score.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
  #})

#(define textFontName "Liberation Sans, Italic")

hairpinPoco = {
  \once \override Score.DynamicLineSpanner.staff-padding = 2
  \hairpinWithCenteredText \markup { \override #(cons 'font-name 
textFontName) \abs-fontsize #6 poco }

}

{

% The following command doesn't change the font name...
#(set! textFontName "Liberation Sans")
\hairpinPoco c'4\< c' c' c'\!

}




This is exactly the same as, in almost every language,

a = "Liberation Sans, Italic"
b = some_operation(a)
a = "Liberation Sans"

b is fixed at the time you define it. You're
not using textFontName in a function, you
just put its value in hairpinPoco. Once
evaluated, hairpinPoco no longer depends
on textFontName. Also, LilyPond does not
process the score linearly in one pass. At
the time at which the font name is retrieved,
the music of the whole score has long been
parsed, so it comes after your #(set! ...),
but also after any other #(set! ...)s coming
after the hairpin you want to customize.
How about:

\version "2.22.1"

hairpinWithCenteredText =
#(define-music-function (text) (markup?)
  #{
    \once \override Score.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
  #})


hairpinPoco = {
  \once \override Score.DynamicLineSpanner.staff-padding = 2
  \hairpinWithCenteredText \markup \abs-fontsize #6 poco
}

\layout {
  \context {
    \Score
    \override Hairpin.font-name = "Liberation Sans, Italic"
  }
}

{
  \hairpinPoco c'4\< c' c' c'\!
  \once \override Hairpin.font-name = "Liberation Sans"
  \hairpinPoco c'4\< c' c' c'\!
}



Regards,
Jean



Issue when setting the font-name for a hairpin with centered text

2021-12-12 Thread Paolo Prete
Hello,

I'm trying to set the font-name for a hairpin with centered text later in
the score, and not in the definition of the function.
However, my attempt, in the snippet below, doesn't work. How can I fix this?

Thanks,
P

%
hairpinWithCenteredText =
#(define-music-function (text) (markup?)
  #{
\once \override Score.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
  #})

#(define textFontName "Liberation Sans, Italic")

hairpinPoco = {
  \once \override Score.DynamicLineSpanner.staff-padding = 2
  \hairpinWithCenteredText \markup { \override #(cons 'font-name
textFontName) \abs-fontsize #6 poco }
}

{

% The following command doesn't change the font name...
#(set! textFontName "Liberation Sans")
\hairpinPoco c'4\< c' c' c'\!

}
%