Baseline align in TextSpanner

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Baseline align in TextSpanner

Davide Liessi-2
Hi all.
I want to align TextSpanner texts to baseline.
I'm trying to use the code provided by Thomas Morley / Harm in
http://lists.gnu.org/archive/html/lilypond-user/2016-10/msg00365.html
which works very well e.g. with \tempo, but applying \test to
TextSpanner.bound-details.left.text has no effect.
I also tried replacing ly:line-spanner::print in TextSpanner.stencil
with a new function but I couldn't make it work.
An example follows, including Harm's code.
Is there a way to adapt it to my case?
Best wishes.
Davide

\version "2.19.82"

#(define (lists-map function ls)
   "Apply @var{function} to @var{ls} and all of it sublists.
First it recurses over the children, then the function is applied to
@var{ls}."
   (if (list? ls)
       (set! ls (map (lambda (y) (lists-map function y)) ls))
       ls)
   (function ls))

#(define test-proc
   (lambda (e)
     (if (and (list? e) (member 'glyph-string e))
         (begin
          (for-each
           (lambda (x)
             (begin
              (set-car! (cadr x) 0)
              x))
           (cadr (last e)))
          e)
         e)))

#(define-markup-command (test layout props glyph-name)
   (markup?)
   (let* ((stil (interpret-markup layout props glyph-name))
          (new-stile-expr
           (lists-map
            test-proc
            (ly:stencil-expr stil))))

     (ly:make-stencil
      new-stile-expr
      (ly:stencil-extent stil X)
      ;(cons 0 (cdr (ly:stencil-extent stil Y)))
      (ly:stencil-extent stil Y)
      )))

{
  \override TextSpanner.bound-details.left.text = \markup { \test "a" }
  b2\startTextSpan b2\stopTextSpan
  \override TextSpanner.bound-details.left.text = \markup { \test "p" }
  b2\startTextSpan b2\stopTextSpan
}

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Baseline align in TextSpanner

Davide Liessi-2
Hi everyone.
Maybe my previous message [1] went unnoticed.
I would really appreciate any hint.
Best wishes.
Davide

[1] http://lists.gnu.org/archive/html/lilypond-user/2018-09/msg00455.html

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Baseline align in TextSpanner

Kieren MacMillan
In reply to this post by Davide Liessi-2
Hi Davide,

> I want to align TextSpanner texts to baseline.

This works for me:

{
 \override TextSpanner.bound-details.left.text = \markup { \combine \transparent "Tj" \test "a" }
 b2\startTextSpan b2\stopTextSpan
 \override TextSpanner.bound-details.left.text = \markup { \combine \transparent "Tj" \test "p" }
 b2\startTextSpan b2\stopTextSpan
}

Of course, I prefer to bury the \combine inside any custom markup functions, so that I don’t have to remember to add it every time.

Hope that helps!
Kieren.
________________________________

Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: [hidden email]


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Baseline align in TextSpanner

Davide Liessi-2
Dear Kieren,

Il giorno ven 5 ott 2018 alle ore 15:11 Kieren MacMillan
<[hidden email]> ha scritto:
> This works for me:
[...]

your solution works well to keep all TextSpanners baseline-aligned,
but it still does not solve my real problem, which indeed was not
apparent in my first message.
I'm trying to make TextSpanners and tempo markings look the same,
including being aligned at the same baseline.
The reason is to follow the recommendations of Gould for tempo
alteration markings (example at page 184).

A slightly more realistic example follows: I would like to align
\tempo markings and TextSpanners to the same baseline.
As you can see using your trick on both does achieve the desired result.
I renamed the \test function to a more specific \baseline-align.
I'm cc-ing also Harm / Thomas Morley because I'm using his code, so he
may have some insights or suggestions.

Thanks for your help so far.
Best wishes!
Davide

%%% new example
\version "2.19.81"

#(define (lists-map function ls)
   "Apply @var{function} to @var{ls} and all of it sublists.
First it recurses over the children, then the function is applied to
@var{ls}."
   (if (list? ls)
       (set! ls (map (lambda (y) (lists-map function y)) ls))
       ls)
   (function ls))

#(define baseline-align-proc
   (lambda (e)
     (if (and (list? e) (member 'glyph-string e))
         (begin
          (for-each
           (lambda (x)
             (begin
              (set-car! (cadr x) 0)
              x))
           (cadr (last e)))
          e)
         e)))

#(define-markup-command (baseline-align layout props glyph-name)
   (markup?)
   (let* ((stil (interpret-markup layout props glyph-name))
          (new-stile-expr
           (lists-map
            baseline-align-proc
            (ly:stencil-expr stil))))

     (ly:make-stencil
      new-stile-expr
      (ly:stencil-extent stil X)
      ;(cons 0 (cdr (ly:stencil-extent stil Y)))
      (ly:stencil-extent stil Y)
      )))

startTempoSpan =
#(define-event-function
  (left-text)
  (markup?)
  #{
    \tweak bound-details.left.text \markup {
      \combine \transparent "Tj"
      #left-text
    }
    \tweak font-shape #'upright
    \tweak font-size 1
    \tweak font-series #'bold
    \startTextSpan
  #})
stopTempoSpan = \stopTextSpan

{
  R1 |
  \tempo \markup { \baseline-align \large "a" }
  R1 |
  \tempo \markup { \baseline-align \large "p" }
  R1 |
  <>\startTempoSpan "a"
  R1
  <>\stopTempoSpan |
  R1 |
  <>\startTempoSpan "p"
  R1
  <>\stopTempoSpan |
  R1
  \tempo \markup { \large \combine \transparent "Tj" "a" }
  R1 |
  \tempo \markup { \large \combine \transparent "Tj" "p" }
  R1 |
}

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Baseline align in TextSpanner

Trevor Bača-2
Hi Davide,

Avoid the the LilyPond \tempo command entirely: then use markup (in text spanner bound-details) for everything. Alignment (baseline and otherwise) can then be controlled with text spanner bound-details.

If you need an empty region of of whitespace between two elements in your (possibly enchained) text spanners, play with the dash fraction / dash period of the text spanner to make the dashes disappear, leaving only your markup visible.

Trevor.



On Sun, Oct 14, 2018 at 2:17 PM Davide Liessi <[hidden email]> wrote:
Dear Kieren,

Il giorno ven 5 ott 2018 alle ore 15:11 Kieren MacMillan
<[hidden email]> ha scritto:
> This works for me:
[...]

your solution works well to keep all TextSpanners baseline-aligned,
but it still does not solve my real problem, which indeed was not
apparent in my first message.
I'm trying to make TextSpanners and tempo markings look the same,
including being aligned at the same baseline.
The reason is to follow the recommendations of Gould for tempo
alteration markings (example at page 184).

A slightly more realistic example follows: I would like to align
\tempo markings and TextSpanners to the same baseline.
As you can see using your trick on both does achieve the desired result.
I renamed the \test function to a more specific \baseline-align.
I'm cc-ing also Harm / Thomas Morley because I'm using his code, so he
may have some insights or suggestions.

Thanks for your help so far.
Best wishes!
Davide

%%% new example
\version "2.19.81"

#(define (lists-map function ls)
   "Apply @var{function} to @var{ls} and all of it sublists.
First it recurses over the children, then the function is applied to
@var{ls}."
   (if (list? ls)
       (set! ls (map (lambda (y) (lists-map function y)) ls))
       ls)
   (function ls))

#(define baseline-align-proc
   (lambda (e)
     (if (and (list? e) (member 'glyph-string e))
         (begin
          (for-each
           (lambda (x)
             (begin
              (set-car! (cadr x) 0)
              x))
           (cadr (last e)))
          e)
         e)))

#(define-markup-command (baseline-align layout props glyph-name)
   (markup?)
   (let* ((stil (interpret-markup layout props glyph-name))
          (new-stile-expr
           (lists-map
            baseline-align-proc
            (ly:stencil-expr stil))))

     (ly:make-stencil
      new-stile-expr
      (ly:stencil-extent stil X)
      ;(cons 0 (cdr (ly:stencil-extent stil Y)))
      (ly:stencil-extent stil Y)
      )))

startTempoSpan =
#(define-event-function
  (left-text)
  (markup?)
  #{
    \tweak bound-details.left.text \markup {
      \combine \transparent "Tj"
      #left-text
    }
    \tweak font-shape #'upright
    \tweak font-size 1
    \tweak font-series #'bold
    \startTextSpan
  #})
stopTempoSpan = \stopTextSpan

{
  R1 |
  \tempo \markup { \baseline-align \large "a" }
  R1 |
  \tempo \markup { \baseline-align \large "p" }
  R1 |
  <>\startTempoSpan "a"
  R1
  <>\stopTempoSpan |
  R1 |
  <>\startTempoSpan "p"
  R1
  <>\stopTempoSpan |
  R1
  \tempo \markup { \large \combine \transparent "Tj" "a" }
  R1 |
  \tempo \markup { \large \combine \transparent "Tj" "p" }
  R1 |
}

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user


--

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user