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: Paul Morris
Subject: Re: Help with music-function generating music
Date: Wed, 26 Mar 2014 14:53:05 -0700 (PDT)

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


\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.



reply via email to

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