|
From: | Jean Abou Samra |
Subject: | Re: arbitrary repeat counter |
Date: | Wed, 1 Jun 2022 18:38:11 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 |
Le 01/06/2022 à 18:19, Simon Bailey a écrit :
Hi, On Wed, 1 Jun 2022 at 17:09, Jean Abou Samra - jean at abou-samra.fr <mailforwards@cloudmails.net> wrote:What did not work? This is perfectly valid Scheme: (set! count (1+ count))(set! counter (+ counter 1)) was giving an error message. Probably had some misaligned parentheses or other weirdness. I didn't know about (1+ var) ;)You're welcome. To be honest, and simplifying a bit, I had a year of unsuccessful attempts to grasp Scheme before Urs' Scheme tutorial made me learn as much of Scheme in 4 hours as I had learnt in a year, then another year without that kind of help to learn LilyPond internals, so if I've managed to write something that is similarly turning a year into 4 hours for you, I'm quite happy.Your readthedocs thing really helped; I still need to have a look at Urs' tutorial. I did some functional programming sometime at the beginning of the millenium, but 20yrs of OOP is a hard habit to break ;-)
For what it's worth, while LilyPond's seldom uses it, Guile actually has an object-oriented layer. https://www.gnu.org/software/guile/manual/html_node/GOOPS.html You may find yourself liking that. This shows that OOP is or can be largely orthogonal to functional vs. imperative.
A further definition: repeatCountingWithTags = #(define-music-function (n music) (index? ly:music?) #{ << \tag #'score \repeat unfold #n { #music } \tag #'part \repeatCounting #n { #music \bar "!|" } >> #}) ebass = \relative c { \clef bass \time 7/4 \repeatCountingWithTags 4 { c4. 8 r4 8 r c2. | d4. 4. 4 e2. | 1 r2 r4 | } } \new StaffGroup << \new Staff \with { instrumentName = "Score" } \keepWithTag #'score \ebass \new Staff \with { instrumentName = "Part" } \keepWithTag #'part \ebass and I get the attached output, which is exactly what I want. And it makes my input files so much easier to read and manage. Thanks ever so much for your help!
Again, you're welcome. Best, Jean
[Prev in Thread] | Current Thread | [Next in Thread] |