lilypond-user
[Top][All Lists]
Advanced

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

Re: help with music functions: change (not add) property to NoteEvent


From: Nicolas Sceaux
Subject: Re: help with music functions: change (not add) property to NoteEvent
Date: Sat, 10 Jun 2006 18:35:17 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)

Michael Meixner <address@hidden> writes:

> dottedHalf =
> #(define-music-function (parser location note) 
>                                               (ly:music?)
>
>       (set! (ly:music-property 
>              (first (ly:music-property note 'elements)) 'duration)
>         (ly:make-duration 1 1 1 1))
>         note)

> 1) Could this be simplified with " ly:music-set-property!" ?

Using (set! (accessor object) value) is the idiomatic way to set some
place. Behind the scene, (set! (ly:music-property ...) ...) uses
ly:music-set-property!.

> 2) In the case of a chord, e.g. "{ \dottedHalf <c' e'>4 }" in the
> above example, this doesn't work, because the function "catches" the
> first NoteEvent only, so I would need to "drill" (recursively?) into
> the EventChord.  Are there any examples showing this? (So far I only
> found examples of ADDING things to an EventChord, but not replacing).

Map a function setting the duration on events having a duration
property.

(for-each (lambda (event)
            (if (not (null? (ly:music-property event 'duration)))
                (set! (music-property event 'duration)
                      (ly:make-duration 1 1 1 1))))
          (ly:music-property chord 'elements)
[not tested]

> [Additional question: "first" is a GUILE feature?]

first is defined in srfi-1 AFAIR: see the guile manual.  When you want
to access the first, second, third, etc element of a list, use the
function that have this semantic: first, second, third, etc. The
functions car, cadr, caddr, etc, do the same thing, but have a different
semantic: access elements of a cons cell tree.

nicolas




reply via email to

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