lilypond-user
[Top][All Lists]
Advanced

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

Re: Question about scheme engravers


From: Carl Sorensen
Subject: Re: Question about scheme engravers
Date: Mon, 18 Jan 2010 15:49:21 -0700

On 1/18/10 2:41 PM, "Eric Knapp" <address@hidden> wrote:

> Hello, everyone.
> 
> I'm working on creating engravers in scheme. I have the example from
> here:
> 
>   http://codereview.appspot.com/181109/show
> 
> In the example file named, "scheme-engraver.ly" there is this piece of
> code:
> 
> (cons 'rest-event (lambda (engraver event)
>            (let*
>             ((x (ly:engraver-make-grob engraver 'TextScript event)))
>             (display (list "caught event" event "\ncreate:\n" x "\n"))
>             (ly:grob-set-property! x 'text "hi"))
>            ))
> 
> If there's a rest in the notation code like this, "<c-2\6>1 r2", then
> the above display function will output this:
> 
>     (caught event #<Prob: Stream_event C++: Stream_event((music-cause
>     . #<Prob: Music C++: Music((length . #<Mom 1/2>) (elements)
>     (duration . #<Duration 2 >) (origin . #<location
>     scheme-engraver.ly:23:11>))((display-methods #<procedure #f (rest
>     parser)>) (name . RestEvent) (types general-music event
>     rhythmic-event rest-event)) > ) (length . #<Mom 1/2>) (elements)
>     (duration . #<Duration 2 >) (origin . #<location
>     scheme-engraver.ly:23:11>))((class . rest-event)) >
> 
> Here's my question. How do I access elements in the event? For
> example, the duration of the rest is shown above as, "(duration .
> #<Duration 2>)". I would like to have an "if" statement look at the
> duration variable and do something based on the value. What would an
> if for that look like?

First, you want to extract the music from the stream event, I think

(ly:event-property event 'Music)  (but I'm not sure about this step)

Once you have the music, then you get the elements of the music:

(ly:music-property music 'elements)

Now, elements is a list of music elements, so you'll want to get the
duration from the first element of elements:

(ly:music-property (car elements) 'duration)

> 
> As you can probably tell, I'm also learning scheme. I've been looking
> for a reason to learn scheme and the new capability of writing scheme
> engravers has hooked me!

Looks like you're doing a good job of it!

> 

> Thanks for the help in advance, this is getting exciting.


I think so!

HTH,

Carl

P.S.  Questions at this level of detail probably belong on -devel, rather
than -user






reply via email to

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