lilypond-devel
[Top][All Lists]
Advanced

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

Re: trying to make a music function, Part 2 of X


From: Nicolas Sceaux
Subject: Re: trying to make a music function, Part 2 of X
Date: Thu, 01 Jun 2006 21:37:48 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)

Kieren MacMillan <address@hidden> writes:

> Hello, all --
>
> Okay, I've got at least this much going:
>
> %% CODE SNIPPET BEGINS
> \version "2.9.6"
>
> addDynText = #(define-music-function (parser location dyn text event- 
> chord) (string? string? ly:music?)
>                       (let ((result-event-chord (ly:music-deep-copy 
> event-chord)))
>                               (set! (ly:music-property result-event-chord 
> 'elements)
>                                       (cons
>                                               (make-music
>                                               AbsoluteDynamicEvent
>                                               text (markup #:line
>                                               (#:dynamic dyn
>                                               #:normal-text
>                                               (#:italic text))))
>                                               (ly:music-property 
> result-event-chord 'elements )))
>                               result-event-chord ))

You have forgotten some quotes here, before AbsoluteDynamicEvent and
text. You don't have to explicitely write #:line just after markup:

(make-music 'AbsoluteDynamicEvent
            'text (markup #:dynamic dyn 
                          #:normal-text #:italic text))

You should indent your code properly, so that it should be less painful
to read.

It's not strictly required to copy the music passed as an argument (with
ly:music-deep-copy). It depends on how you'll be using the function. If
you want to do:
  musicA = { some music }
  musicB = \functionFoo \musicA
  musicC = \functionBar \musicA
then \functionFoo and \functionBar should indeed copy their music
argument (so that \musicA should not be altered when it is used several
times as a music function argument). However, if all you do is calling
your function on music "literals" (that is, on the notes directly,
rather than on a variable), then copying the arguments is useless.

> \relative c'
> {
>       \addDynText #'"pp" #'"sempre" <c d e>4 c
>               \addDynText #'"f" #'"(no, really)" <c d e>8 c c4
> }
> %% CODE SNIPPET ENDS

You don't have to quote a string in scheme. Moreover, you don't have to
"sharp" the strings. So this snippet becomes:

  \relative c' {
    \addDynText "pp" "sempre" <c d e>4 c
    \addDynText "f" "(no, really)" <c d e>8 c c4
  }

> However...
>
> 1. I'd like the syntax to be easier -- maybe something like
>
>      <c d e>8\addDynText #'( f . "(no, really)" )
>
> or something even slicker, if anyone has a recommendation. Anyway, I
> don't know how to do that -- it would involve (car args) and so on,
> and I'm not there yet.

If you want to have only two arguments, use a list for the first
argument (predicate: list?). You access the first element with first,
and the second element with second (simple).

#(define-music-function (parser location dyn-text event-chord)
                        (list? ly:music?)
   (let ((dyn (first dyn-text))
         (text (second dyn-text)))
    ... as before

==>
\addDynText #'("pp" "sempre") <c d e>4

which is not better imho.
The music function arguments have to be after it.

> 2. I don't know how to (or even where to look to find out how to)
>    change the self-alignment-X or X-offset property of an
>    AbsoluteDynamicEvent within the Scheme code. I tried to work it out
>    by looking at the existing Lilypond (Scheme) code, to no avail
>    (yet).

Use \displayMusic !

> 3. I'd love someone to tell me that I'm on the right track -- e.g.,
>    that I'm not bypassing the parser inadvertently, or creating some
>    endless loop, or double-garbage-collecting, or "this would be
>    better  in C++", or whatever.


addDynText = 
#(define-music-function (parser location dyn text event-chord)
                        (string? string? ly:music?)
   (set! (ly:music-property event-chord 'elements)
         (cons (make-music 'AbsoluteDynamicEvent
                 'text (markup #:dynamic dyn
                               #:normal-text #:italic text))
               (ly:music-property event-chord 'elements)))
   event-chord)


\relative c' {
  \addDynText "pp" "sempre" <c d e>4 c
  \addDynText "f" "(no, really)" <c d e>8 c c4
}

nicolas




reply via email to

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