Test direction within event-function

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

Test direction within event-function

Urs Liska-3

Hi,

I'm trying to write an event-function that creates both a slur and a markup on opposite sides. I can do that by manually specifying the directions:

\version "2.19.82"

testDirection =
#(define-event-function ()()
   #{
     _(
     ^"Text"
   #})

{
  c' \testDirection d' )
}

but I have to make it possible to do it both ways (top/bottom and bottom/top).
I know how to set the directions with an extra (optional) function argument, but I would prefer if I could extract the direction directly from within the event-function.

Using \displayMusic I see that an explicit direction is "known" to the event function:
\void \displayMusic ^\testDirection
=>
(make-music
  'PostEvents
  'direction
  1
  'elements
  (list (make-music
          'SlurEvent
          'direction
          -1
          'span-direction
          -1)
        (make-music
          'TextScriptEvent
          'direction
          1
          'text
          "Text")))

(the 'direction PostEvent takes either 1 or -1, or is missing if no explicit direction is given). But I have no idea if/how I can access that information from within the function to decide how to create the slur and the text event.

Thanks Urs


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

Re: Test direction within event-function

David Kastrup
Urs Liska <[hidden email]> writes:

> Hi,
>
> I'm trying to write an event-function that creates both a slur and a
> markup on opposite sides. I can do that by manually specifying the
> directions:
>
> \version "2.19.82"
>
> testDirection =
> #(define-event-function ()()
>    #{
>      _(
>      ^"Text"
>    #})
>
> {
>   c' \testDirection d' )
> }
>
> but I have to make it possible to do it both ways (top/bottom and
> bottom/top).
> I know how to set the directions with an extra (optional) function
> argument, but I would prefer if I could extract the direction directly
> from within the event-function.

You can't.  It is set after calling the event-function.  You can use
tweaks/callbacks for the respective grob functions (most likely
"direction") where you use event-cause to get the originating event, get
the event direction from there and either use or invert it.

Am badly available for a few days.  Sister's wedding.

--
David Kastrup

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