lilypond-user
[Top][All Lists]
Advanced

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

Re: to make a function with argument list or vector


From: Thomas Morley
Subject: Re: to make a function with argument list or vector
Date: Sun, 4 Sep 2016 20:47:17 +0200

Hi Оксана,

you try to output music from a recursively defined scheme-function.
As Urs already said use a music-function for music.
Also some mistakes:


2016-09-04 18:52 GMT+02:00 Оксана Крымина <address@hidden>:

> \version "2.18.2"
> musSpisok = #(define-scheme-function (parser location llen)(list?)
>             (if (not (null? llen))
> #{
>                       \repeat unfold $(car llen) {c2} \bar ""  (

^^^^^^^^^^^^^^^^^^^^
The last typed character, "(", is interpreted by LilyPond, usually as
Slur-start.
> \musSpisok #'(cdr llen))  )
               ^^^^^^^^^
Don't quote (cdr llen), if you want it evaluated.
>                     #})

But even corrected this would produce not what you want.

2016-09-04 20:26 GMT+02:00 Urs Liska <address@hidden>:
>
>
> Am 4. September 2016 19:30:02 MESZ, schrieb "Оксана Крымина"
> <address@hidden>:
>>Great! It works! It works!
>>Thank You!
>>
>
> The first thing is you had to use define-music-function because that returns
> *music*.
>
> Then you can return a *list* of music expressions with something like
>
> @(map
> (lambda (len)
> #{ \repeat unfold #len ... #})
> llen)
>
> (completely untested, on the phone)
> This iterates over your input list and produces the music using regular
> syntax.
>
> HTH
> Urs

Urs suggestion would lead to the following, which I'd recommend as well:

foo =
#(define-music-function (parser location lst)(number-list?)
  #{
    $@(map (lambda (i) #{ \repeat unfold $i { c2 } \bar "||" #}) lst) \bar "|."
  #})

\foo #'(5 7 10 8)

>>2016-09-04 20:15 GMT+03:00, Simon Albrecht <address@hidden>:
>>> Hi Oxana,
>>>
>>> I _guess_ the reason it doesn’t work is because the parser doesn’t
>>> accept a Scheme expression instead of the number after \repeat
>>unfold.

Nope. See above

>>> The solution is creating music via Scheme. As a first step, you can
>>> always use something like
>>>
>>> %%%%%%%
>>> \version "2.19.47"
>>> \displayMusic { \repeat unfold 2 { c'1 } }
>>> %%%%%%%
>>>
>>> to see what the music looks like on the Scheme level:
>>>
>>> ;;;;;;;;;;;;;;;;;;;;;
>>> (make-music
>>> 'SequentialMusic
>>> 'elements
>>> (list (make-music
>>> 'UnfoldedRepeatedMusic
>>> 'elements
>>> '()
>>> 'repeat-count
>>> 2
>>> 'element
>>> (make-music
>>> 'SequentialMusic
>>> 'elements
>>> (list (make-music
>>> 'NoteEvent
>>> 'duration
>>> (ly:make-duration 0)
>>> 'pitch
>>> (ly:make-pitch 0 0)))))))
>>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>>
>>> Now I built a music function using that information:
>>>
>>> %%%%%%%%%%%%%%%
>>> \version "2.18.2"
>>>
>>> createRepeats =
>>> #(define-music-function (parser location nums mus end) (list?
>>ly:music?
>>> ly:music?)
>>> (let ((repeater (lambda (n) (make-music
>>> 'SequentialMusic
>>> 'elements
>>> (list (make-music
>>> 'UnfoldedRepeatedMusic
>>> 'elements
>>> '()
>>> 'repeat-count
>>> n
>>> 'element
>>> mus)
>>> end)))))
>>> (make-sequential-music (map repeater nums))))
>>> \createRepeats #'(2 3 7) { c'1 } { \bar "||" }
>>> %%%%%%%%%%%%%%%%
>>>
>>> If you have further questions, feel free to ask back.
>>>
>>> Best, Simon
>>>
>>> PS. In recent development versions, one may use nicer syntax:
>>>
>>> %%%%%%%%%%%%%%%%
>>> \version "2.19.47"
>>>
>>> createRepeats =
>>> #(define-music-function (nums mus end) (list? ly:music? ly:music?)
>>> (let ((repeater (lambda (n) (make-music
>>> 'SequentialMusic
>>> 'elements
>>> (list (make-music
>>> 'UnfoldedRepeatedMusic
>>> 'elements
>>> '()
>>> 'repeat-count
>>> n
>>> 'element
>>> mus)
>>> end)))))
>>> (make-sequential-music (map repeater nums))))
>>> \createRepeats 2,3,7 { c'1 } { \bar "||" }
>>> %%%%%%%%%%%%%%%%

Although working nicely, I like the sollution above best,

If you really, really want a recursion, try:

musSpisok =
#(define-music-function (parser location llen rl)(number-list? list?)
  (if (null? llen)
      #{ $@(reverse rl) \bar "|." #}
      #{
        \musSpisok
          #(cdr llen)
          #(cons #{ \repeat unfold #(car llen) { c2 } \bar "||" #} rl)
      #}))

\musSpisok #'(5 7 10 8) #'()


Cheers,
  Harm



reply via email to

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