lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Direction operators in event-function


From: Urs Liska
Subject: Re: Direction operators in event-function
Date: Tue, 23 Oct 2018 08:39:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1



Am 21.10.2018 um 18:17 schrieb David Kastrup:
David Kastrup <address@hidden> writes:

Urs Liska <address@hidden> writes:

What I would *like* to do is a function like

propagate-direction =
#(define-event-function (text)(markup?)
    #{
      -\tweak direction #UP
      -(
      -\tweak direction #UP
      -\markup #text
    #})

but instead of hard-coding #UP I'd like to calculate the values based
on something. For example let the text have the opposite direction of
the slur and have the slur accept the ^\_ operator.
Even assuming PostEvents are fixed, you'd still be stuck having to
look at one event from another, independent one.  You'd be missing a
reliable handle for that.  You'd need to use an engraver for doing
that kind of interaction.
Correction: you could put a callback into a direction tweak on the text
event and this callback could check the _text_ event's direction and
then assume the _opposite_.  So after "assuming PostEvents are fixed"
should more or less work for this particular scenario,

My impression is: no. When I tried that I got a "calculation-in-progress" error.

It seems that my initial misunderstanding led me to try getting something that isn't really available, so I finally changed the approach and seem to be reasonably successful. If the user wants slur and text on opposite sides this has to be explicitly specified, and then the directions can be taken from the given argument. If OTOH they are on the same side then the text will not be printed by creating a second event but by combining both in a modified slur stencil where the staff-padding property is emulated by manually calculating the necessary distance from the slur. (

Thank you anyway for the explanations.
Urs

PS: For future reference here's the implementation I arrived at (expecting oll-core for the option handling)

\registerOption markup-staff-padding 2.5
annotateSlur =
#(define-event-function (min-padding text)((number? 1) markup?)
   "Create a slur with an attached markup."
   #{
     -\tweak after-line-breaking
     #(lambda (grob)
        (let*
         ((dir (ly:grob-property grob 'direction))
          ;; staff-padding from the options
          (staff-padding (getOption '(markup-staff-padding)))
          ;; The original slur stencil
          (stencil (ly:slur::print grob))
          ;; A new stencil for the markup
          (markup-stencil (grob-interpret-markup grob text))
          ;; Y-extent of the original slur for later reference
          (slur-extent (ly:grob-property grob 'Y-extent))
          ;; total height of slur
          (slur-height (- (cdr slur-extent) (car slur-extent)))
          ;; absolute distance of outer slur edge from middle staffline
          (outer-slur-edge-abs
           (abs (if (> dir 0) (cdr slur-extent) (car slur-extent))))
          ;; Y-extent of the added markup stencil
          (markup-extent (ly:stencil-extent markup-stencil Y))
          ;; total height of markup
          (markup-height (- (cdr markup-extent) (car markup-extent)))
          ;; height of lower extender or X height, depending on direction
          (markup-inner-height
           (if (> dir 0)
               (* -1 (car markup-extent))
               (cdr markup-extent)))
          ;; offset because staff-padding *below* staff is increased by 1
          (direction-offset (if (> dir 0) 0 -1))
          ;; padding between slur and markup, based on both the min-padding
          ;; argument and the global markup-staff-padding option
          (effective-padding
           (max
            (- (+ staff-padding 2)
              markup-inner-height
              direction-offset
              outer-slur-edge-abs)
            min-padding))
          ;; necessary horizontal shift to center the markup against the slur
          (hshift (- (interval-center (ly:stencil-extent stencil X))
                    (interval-center (ly:stencil-extent markup-stencil X))))
          ;; combined stencil from slur and text
          (new-stencil
           (ly:stencil-combine-at-edge stencil Y dir
             (ly:stencil-translate-axis markup-stencil hshift X)
             effective-padding)))
         ;; enclose the *new* stencil by the modified Y-extent
         ;; NOTE: this only makes the whole thing *clickable*, it doesn't
         ;; help with pushing the staff towards the bottom of the page.
         (ly:grob-set-property! grob 'Y-extent
           (if (> dir 0)
               (cons
                (car slur-extent)
                (+ (car slur-extent) slur-height effective-padding 
markup-height))
               (cons
                (- (car slur-extent) effective-padding markup-height)
                (cdr slur-extent))))
         (ly:grob-set-property! grob 'stencil new-stencil)))
     % NOTE: this is a slur-event, not a misplaced parenthesis
     (
   #})

but

\tweak direction #UP \propagate-direction

would then override both tweaks.  I mean, you could still override with
a callback that reverses direction only on markup grobs but things get
increasingly murky and awkward when trying to do stuff like that.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]