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: Urs Liska
Subject: Re: Get input location within a stencil override function
Date: Wed, 1 Feb 2017 12:19:07 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0

Hi David,

thank you for the explanations!


Am 01.02.2017 um 11:39 schrieb David Kastrup:
> 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.

OK.

>
>> 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!")

Obviously this is what I was looking for.
Would I have had a reasonable chance to find it myself in the docs?

>
> 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).

That means if (event-cause grob) doesn't evaluate something useful it
will crash and I should take precautions? But can a grob in a stencil
that overrides a slur *not* have an event anyway?

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

OK, I've changed that.
But is that just unnecessarily complicated/expensive or could it cause
*real* problems too?

Best and thanks again
Urs

>

-- 
address@hidden
https://openlilylib.org
http://lilypondblog.org




reply via email to

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