On 1/18/10 2:41 PM, "Eric Knapp" <[email protected]> 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 _______________________________________________ lilypond-user mailing list [email protected] http://lists.gnu.org/mailman/listinfo/lilypond-user
