On 2024-03-20 8:53 am, enejati--- via LilyPond user discussion wrote:
Hello,
I'm a new lilypond user. I want to create multiple scores in a single
file. These scores have some values on common. So I want to use
`define-music-function` in order to avoid repetition.
[ . . . ]
A few things. Firstly, you must prefix make-score with a slash, just
like any other music function. Secondly, define-music-function is not
structured the same as Scheme's define. The procedure name will go
outside:
%%%%
myFunction = #(define-music-function (arg1 arg2) (type? type?) ...)
%%%%
Lastly, a music function must return what LilyPond considers music.
Top-level things like a \score or \book will not count. Instead, what
you will need is define-void-function, which does not return anything.
Within this function, you can call the internal functions for processing
scores and books directly:
%%%%
make-score =
#(define-void-function
(instrumentName bookSuffix musicContent)
(string? string? ly:music?)
(toplevel-score-handler #{
\score {
\new Staff \with {
instrumentName = #instrumentName
} { #musicContent }
\layout { }
}
#})
(toplevel-book-handler #{
\book {
\bookOutputSuffix #bookSuffix
\score {
\new Staff \with {
midiInstrument = "piccolo"
} { #musicContent }
\midi {
\tempo 4 = 80
}
}
}
#}))
% Usage
\make-score "۱" "1" { b'4 4 2 }
\make-score "۲" "2" { b'4 4 2 }
\make-score "3" "3" { b'4 4 2 }
%%%%
-- Aaron Hill