lilypond-user
[Top][All Lists]
Advanced

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

Re: Iterators in Scheme?


From: Niols
Subject: Re: Iterators in Scheme?
Date: Thu, 6 Aug 2020 20:15:15 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

Hello again,

On 30/07/2020 18:22, Niols wrote:
On 29/07/2020 17:28, Jean-Julien Fleck wrote:
Le mer. 29 juil. 2020 à 15:44, Niols <niols@niols.fr <mailto:niols@niols.fr>> a écrit :


     > What do you want to achieve?

    This is actually follow-up research from my side after a previous
    e-mail
    to this list. I would like to print bar numbers that are "repeat
    aware",
    that is such that if bars 9 to 12 repeat twice, then the bar numbers go

          1, 2, …, 9, …, 12, 17, 18, etc.

    with a jump after 12 that corresponds to the bars 13 to 16 that are
    actually 9 to 12. Even better, I would like to print the two bar
    numbers
    for these bars (9/13, 10/14, etc.)


Perhaps this snippet could be of some use for you: http://lsr.di.unimi.it/LSR/Item?id=1080

I have been playing with this solution and I find it very satisfactory for my use. I do not understand yet all the intrinsics (in particular with respect to the context-spec-music and the make-apply-context functions), but I understand roughly how it works.

There is just one thing that I would want to "improve" (that is, for my use): the solution needs to map on all the music in order to find all the VoltaRepeatedMusic and override their callbacks to a newly defined one. This is achieved by providing a function "unfoldBarNumbers" that can be applied to any music and that does it.

I would however be interested to have that for all the music in my file, without having to call that function. The different ideas that pop into my mind in such a situation are the following:

1. Maybe I could override the "\repeat" function so that it does the same thing as by default but, when it is a "volta" repeat, it also attaches the new callback to the created music. I believe I see how to achieve that, except I seem unsuccessful in overriding the default definition of "\repeat". Even if I do something like:

     #(define (repeat type num body alts)
       (display "\nrepeat\n"))

     { b4 \repeat volta 2 { b b } b }

it behaves as if I had not put the #(define ...) statement. I have played around this idea for a while without success. I have tried to see if "\repeat" had a special treatment (which it does, at least in the lexing/parsing), but I haven't been able to figure this out.

I have not managed to override the "\repeat" music function. I suspect there is something I do not understand in the order in which things are executed in LilyPond.

I have however found a solution based on overriding "make-music". I replace "make-music" by a wrapper around it that adds the callback from the snippet to all 'VoltaRepeatedMusic and leaves the rest alone. This is actually just a few lines:

    #(define the-make-music make-music)

    #(define (make-music-wrapped name . music-properties)
      (let ((music (apply the-make-music (cons name music-properties))))
       (if (equal? name 'VoltaRepeatedMusic)
        (ly:music-set-property! music 'elements-callback new-volta-set))
       music))

    #(set! make-music make-music-wrapped)

It might not be the cleanest, but that is all I have, and that seems to work.

2. Maybe there is a way to define a function that will be ran before processing on any music? But this I have no idea if this is possible, or how to do it, and my research has proven ineffective so far.

3. Maybe there is a way to override the "make-volta-set" callback instead of creating a new one? Such that then, in LilyPond's normal execution, it uses the new definition and not and old one that then needs to be replaced?

For 2. and 3., I still have no idea as this is far beyond my understanding of the internals of LilyPond. I am not really looking into it though.

Thank you for your help; have a great Summer!
— Niols



reply via email to

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