[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: repeat unfold evaluated each time
From: |
David Kastrup |
Subject: |
Re: repeat unfold evaluated each time |
Date: |
Fri, 12 Oct 2012 17:27:17 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) |
Jean-Alexis Montignies <address@hidden> writes:
[...]
> I'm adapting a snippet about creating random notes. I'd like to be able to
> make the code more customizable for a non coding user.
>
> So I tried something like this:
>
>
> random-state = # (seed->random-state (current-time))
> randomNote = #(define-music-function
> (parser location) ()
> (let ((idx (random 12 random-state)))
> (make-event-chord
> (list
> (make-music 'NoteEvent
> 'duration (ly:make-duration 2 0
> 1 1)
> 'pitch (ly:make-pitch
> (quotient idx 7)
> (remainder idx 7)
> 0))))))
>
> \score {
> \repeat unfold 24 { $randomNote }
> }
>
> I excepted that I wouldn't get what I want :) : $randomNote would be
> called only once a the result copied 24 times (24 identical notes).
> Is there a way to force lilypond to evaluate the repeated music each
> time?
No.
> Should I write my own repeat function?
Won't help as arguments are evaluated before a function is being called.
The best you can do is writing a function that does not receive a music
expression but rather a music function as its argument and then
repeatedly call it. Or just let randomNote take a count as argument.
> Or is the only way is really to have a scheme function returning a
> list of notes?
That's easier.
--
David Kastrup