Hi,
I was struggling with this earlier, but suggestions from the list didn't
help me and I had to postpone the issue. Now I've got to resolve it and
while I make progress I don't seem to be able to get to the goal line :-(
I am trying to create a text command that prints items at a specific
distance from the staff (in order to have multiple items on the same
baseline). The behaviour of staff-padding is good enough for me, that is
if one of the items is forced to be farther away to prevent collisions
with the music I'm OK with adjusting the staff-padding for *all* items.
My problem is that the created markup should push other items to the
right rather have them stack vertically as is the standard behaviour of
TextScript - but only if there actually *is* such an item. Using
\textLengthOn always pushes the next note column to the right, even when
that doesn't have a text attached.
I found a solution using extra-spacing-width (but not
extra-spacing-height) together with unsetting outside-staff-priority and
wrapping all of this in an event-function:
\version "2.19.82"
#(define (create-foo text)
#{
-\tweak extra-spacing-width #(cons -0.0 .8)
-\tweak outside-staff-priority ##f
-\tweak staff-padding 3
-\markup #text
#})
this =
#(define-event-function ()()
(create-foo "thisis."))
that =
#(define-event-function ()()
(create-foo "thatis."))
\relative {
e''16 \this [ f e \that d \this ]
}
In the attached 'correct.png' you can see that the *second* item
"thatis." correctly pushes the next note in order to avoid the collision
(the little white space comes from the .8 value to extra-spacing-width)
while the first "thisis." leaves the second note alone.
However, I don't actually use a literal value for staff-padding but a
callback function that modifies the staff-padding according to the
direction. And as soon as staff-padding is set to that (any) callback
function the behaviour is again like using \textLengthOn, as can be seen
in the attached 'wrong.png' where the second note is wrongly pushed to
the right:
\version "2.19.82"
#(define (calc-staff-padding grob)
"Calculate the staff-padding value of a grob.
This has to be done in a callback since it seems to be
the only solution to both align texts to the baseline
(using staff-padding) *and* to adjust upper and lower
padding. See
http://lists.gnu.org/archive/html/lilypond-user/2018-10/msg00267.html"
(let ((dir (ly:grob-property grob 'direction))
(staff-padding 4) ; in the real project this is loaded from options
)
(if (> dir 0)
staff-padding
; NOTE: It is somewhat arbitrary to have lower texts
; pad by exactly 1 staff space more than above
; TODO: Calculate by creating a "Tq" markup and measuring its Y-extent
(+ 1 staff-padding))))
#(define (create-foo text)
#{
-\tweak extra-spacing-width #(cons -0.0 .8)
-\tweak outside-staff-priority ##f
-\tweak staff-padding #calc-staff-padding
-\markup #text
#})
this =
#(define-event-function ()()
(create-foo "thisis."))
that =
#(define-event-function ()()
(create-foo "thatis."))
\relative {
e''16 \this [ f e \that d \this ]
}
Can anyone explain why the TextScript is behaving differently when
staff-padding is tweaked to a literal or to a callback? And - more
importantly - how I can achieve my goal?
Thanks
Urs
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user