lilypond-user
[Top][All Lists]
Advanced

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

Re: Get input location within a stencil override function


From: David Kastrup
Subject: Re: Get input location within a stencil override function
Date: Wed, 01 Feb 2017 11:39:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Urs Liska <address@hidden> writes:

> I'm writing a custom stencil and want to issue a warning under certain
> circumstances.
>
> The warning should point to the input location whose grob caused that
> circumstance. But I don't "find" the proper location within the stencil
> function.
>
> \version "2.19.54" testLocation = #(define-scheme-function
> (grob)(ly:grob?)    (ly:input-message (*location*) "Where is the
> origin?")    (ly:message "Location???: ~a" (ly:grob-property grob
> 'cause))    (ly:make-stencil       `(path 1 `(moveto 0 0 lineto 1 1))))
> {   c'   \override NoteHead.stencil = #testLocation   c' }

Uh, define-scheme-function defines a function to be used in LilyPond
source, not in a callback.  It's only a convenience for programming
other input absorbing functions that this is callable in Scheme.

> FIrst I try (*location*), which points to somewhere in LilyPond itself:
>
> /home/uliska/lilypond/usr/share/lilypond/current/ly/init.ly:56:2 <0>:
> Where is the origin?
>
> #
> (let ((book-handler (if (defined? 'default-toplevel-book-handler)

Sure.  You call (*location*) when LilyPond is _done_ processing the
input file and in its typesetting phase.

> The next (and last) thing I came up with is retrieving the 'cause of the
> grob:
>
> Location???: #<Prob: Stream_event C++: Stream_event((music-cause .
> #<Prob: Music C++: Music((length . #<Mom 1/4>) (pitch . #<Pitch c' >)
> (duration . #<Duration 4 >) (origin . #<location
> /tmp/frescobaldi-v2tso25z/tmp_qbil8qe/document.ly:14
> <1>:3>))((display-methods #<procedure #f (note)>) (name . NoteEvent)
> (iterator-ctor . #<primitive-procedure
> ly:rhythmic-music-iterator::constructor>) (types event note-event
> rhythmic-event melodic-event)) >
>
> ) (length . #<Mom 1/4>))((class note-event melodic-event rhythmic-event
> music-event StreamEvent) (length . #<Mom 1/4>) (pitch . #<Pitch c' >)
> (duration . #<Duration 4 >) (origin . #<location
> /tmp/frescobaldi-v2tso25z/tmp_qbil8qe/document.ly:14 <2>:3>)) >
>
>
> This is better because obviously it contains the correct location. (14:3
> of the input file).
> However, I don't know how to get "inside" that <Prob: or if there's
> another, more straightforward way to get to the location of the grob.

The cause obviously is a stream event.  Try something like

(ly:event-warning (event-cause grob) "This is bad!")

Note that the string is a format string and can take ~S-like format
elements to be followed by corresponding values in the function call.
Also notice that ly:event-warning is not robust against a missing event
(currently).

But really, really, really don't use define-scheme-function for
something not supposed to work on LilyPond input.

-- 
David Kastrup



reply via email to

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