lilypond-user
[Top][All Lists]
Advanced

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

Re: Help with music-function generating music


From: Urs Liska
Subject: Re: Help with music-function generating music
Date: Thu, 27 Mar 2014 08:39:49 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

Am 26.03.2014 22:53, schrieb Paul Morris:
Hi Urs,

I had a chance to work on the iteration part.  This one accepts a note as an
argument which is a better approach, following the examples here:

http://lilypond.org/doc/v2.18/Documentation/extending/doubling-a-note-with-slurs-_0028example_0029
http://lilypond.org/doc/v2.18/Documentation/extending/adding-articulation-to-notes-_0028example_0029

The iteration is done with a "named let" (which is just one option) see
these docs for Guile and Scheme:

https://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Iteration.html
https://www.gnu.org/software/guile/manual/guile.html#while-do

Cheers,
-Paul



Thank you very much. Such concrete examples are incredibly helpful.
I had already started to fiddle around with yesterday's example and was trying to achieve something similar to your new example. But I didn't come to an end (Scheme gives you soo many opportunities to do something wrong ...), so I can now investigate your example with some pre-knowledge.

I hope (but honestly doubt) to find the time to pour these experiences in a tutorial (series), as I think that this step is a hard one for many people, and the respective documentation is really hard to grasp.

Urs

\version "2.18.0"

myNotes =
#(define-music-function (parser location note num)
    (ly:music? number?)
    "Returns a series of notes. @var{note} is repeated @var{num} times.
    @var{note} is supposed to be a single note."
    ;; iteration by named let
    (let loop
      ;; two variables/arguments,
      ;; i is the iteration count
      ;; nts is the list of notes we're building
      ((i 0)
       (nts '()))

      ;; conditional
      (cond
       ((< i num)
        ;; call the loop again with modified values for i and nts
        (loop
         (+ i 1)
         (append nts (list (ly:music-deep-copy note)))))

       (else
        ;; when done, return the music
        (make-music 'SequentialMusic 'elements nts)))))

{
   \myNotes g'16 #8
}



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160867.html
Sent from the User mailing list archive at Nabble.com.

_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user





reply via email to

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