2

I'm trying to write my first define-scheme-function in Lilypond, and I'm stuck. I'm wanting to output a variable number of handbell 'echo' notations within a single measure.

This is working for a static number (2-4):

echoTwoThreeFour = #(define-scheme-function
 (halign)
 (number?)
 #{ \markup { \halign #halign \center-column {⮍ 2} \center-column {⮍ 3} \center-column {⮍ 4} } #}
 )

<c e g c>1 -$(echoTwoThreeFour -3)

This outputs: enter image description here

However, I'd really like to send as an argument a list of beat numbers (list 2 3 4) so that I can use a single function for variable numbers of echoes, called like:

<c e g c>1 -$(echoVariable (list 2 3 4) -3)

How can I iterate through a list of numbers within a scheme function and output the appropriate markup?

1 Answer 1

2

For example like this. map creates a list of function results for each entry of a list. This can be used to create the individual markups. Then we simply make a line markup from this list of markups.

echoN =
#(define-scheme-function
 (halign iterations)
 ((number? -3) list?)
 (let* ((marks (map (lambda (c) #{ \markup\center-column {⮍ #(number->string c) } #}) iterations))
        (basemup (make-line-markup marks)))
   #{ \markup \halign #halign #marks #}))

{ <c e g c>1 -\echoN #'(1 2 3) }

Edit: But I think you are actually using \halign for the purpose of \hspace. You’d probably want to do

echoN =
#(define-scheme-function
 (space iterations)
 ((number? 3) list?)
 (let ((marks (map (lambda (c) #{ \markup\center-column {⮍ #(number->string c) } #}) iterations)))
   (make-line-markup (cons (make-hspace-markup space) marks))))

Note that this can then also be called with this nice scheme-free syntax

{ <c e g c>1 -\echoN 2 1,2,3 }
3
  • Thanks, @Lazy! I will try this out. Thanks for the hint on halign vs. hspace. I'm guessing I have lots of such things going on in my first few scores, due to copying/pasting without fully understanding.
    – Mark
    Commented Sep 27, 2023 at 13:51
  • Perhaps someday my eyes will be able to read scheme/lisp without so much effort. Are you missing a parameter in the first snippet -\echoN #'(1 2 3)?
    – Mark
    Commented Sep 27, 2023 at 16:07
  • 1
    @Mark See here lilypond.org/doc/v2.24/Documentation/extending/… the stuff about optional arguments.
    – Lazy
    Commented Sep 27, 2023 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.