lilypond-user
[Top][All Lists]
Advanced

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

Several questions concerning scheme-music-function


From: Robert Schmaus
Subject: Several questions concerning scheme-music-function
Date: Sat, 26 May 2018 15:15:14 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

Dear Ponderers,

so far, I was completely satisfied with out-of-the box lilypond and rarely used anything involving scheme. Mainly because, I find this language very counter-intuitive, but that's maybe because I code in C-like languages all the time.

Anyway, my project was to make me a function with which I could switch repeats from "volta" to "unfold" variants - in scores I need to have the unfold variant, but for some instruments it would be convenient to have long but repeating parts not unfolded but in volta brackets with an indication of the number of repetitions.

As a very simple solution, I came up with this (in real life, the scheme is in a separate file, but this seems to make no difference here ...):


--------------------

\version "2.19"

useRepeatVolta = #(define urv #t)
useRepeatUnfold = #(define urv #f)

unfoldOrRepeat =
#(define-music-function (parser location n m) (integer? ly:music?)

   (define nString (number->string n))

   (if urv
       #{
         <>^\markup{ \box{ \concat{ $nString "x" } } }
         \repeat volta $n { $m }
       #}

       #{
         \repeat unfold $n { $m }
       #}
       )
   )


\score {

  \new Staff {

    c'''4 4 4 4

    \barNumberCheck #2
    % \useRepeatVolta     % <-- doesn't work
    #(define urv #t)    % <-- works
    \unfoldOrRepeat 8 { c''4 4 4 4  }

    \barNumberCheck #10
    #(define urv #f)
    \unfoldOrRepeat 8 { c'4 4 4 4  }
  }
}


--------------------

which sort of works. But not really, because

(1) I have included two procedures for switching between "volta" and "unfold". They don't really work. If I use the #(define urv #t) directly, it works as expected. I don't know why ...

(2) For this function to work properly, I'll need to calculate the bar number in the "volta" case or no bar number checks will make sense anymore.
So, basically, after the \repeat volta line, there should be something like

         \set Score.currentBarNumber =
           #(+
               (* (- n 1) [LENGTH OF m in BARS] )
               (ly:context-property 'Score 'currentBarNumber)
            )

This doesn't work since, I don't know how to get the length of music variable m, and I also don't understand how to return the current bar number of the score context.

There was a recent thread

http://lilypond.1069038.n5.nabble.com/get-current-bar-number-td211064.html

that dealt with bar numbers in scheme as well, so I knew that simply using (ly:context-property 'Score 'currentBarNumber) wouldn't work. I tried to fiddle around with the code of that other thread, but the hard truth is, I have no clue what Scheme is all about.

Can anyone point me to an example where I can see how this is done?

Thanks a lot!
Robert





reply via email to

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