Am Sa., 12. Okt. 2024 um 20:33 Uhr schrieb Cameron Hall <[email protected]>:
>
> In this example, I have function called "scorePart" that returns a
> staff that I use to make parts in the score, and this works. I have
> another function called "standalonePart" that returns a bookpart, which
> I'd like to use to print individual instrument parts. However, when I
> attempt to use it I get an error complaining about bad expression type.
> What is going on here that it will accept a staff but not a bookpart?
>
> Thanks,
> Cameron
>
> %%%
> \version "2.24.4"
> \header { title = "Example" }
>
> flute.name = "Flute"
> flute.key = c'
> flute.music = \fixed c'' { \key c \major c4 d e d c1 }
>
> trumpet.name = "B♭ Trumpet"
> trumpet.key = bes
> trumpet.music = \fixed c' { \key c \major c4 d c b, c1 }
>
> scorePart =
> #(define-scheme-function (instrument) (alist?)
> #{
> \new Staff
> \with { instrumentName = #(ly:assoc-get 'name instrument) }
> { #(ly:assoc-get 'music instrument) }
> #}
> )
>
> standalonePart =
> #(define-scheme-function (instrument) (alist?)
> #{
> \bookpart {
> \header { instrument = #(ly:assoc-get 'name instrument) }
> \score {
> \new Staff
> \transpose #(ly:assoc-get 'key instrument) c'
> #(ly:assoc-get 'music instrument)
> }
> }
> #}
> )
>
> % Score book
> \book {
> \header { instrument = "Concert Pitch Score" }
> \score {
> <<
> \scorePart \flute
> \scorePart \trumpet
> >>
> }
> }
>
> % Book containing all parts
> \book {
> \standalonePart \flute
> \standalonePart \trumpet
> }
> %%%
>
Hi Cameron,
iirc, there are some problems with bookpart...
Anyway, you could do:
%%%
\version "2.24.4"
\header { title = "Example" }
flute.name = "Flute"
flute.key = c'
flute.music = \fixed c'' { \key c \major c4 d e d c1 }
trumpet.name = "B♭ Trumpet"
trumpet.key = bes
trumpet.music = \fixed c' { \key c \major c4 d c b, c1 }
#(define (add-bookpart book-part)
"Add bookpart @var{book-part} to current-book or toplevel-bookparts"
;; See also: `collect-bookpart-for-book` in lily-library.scm
(let* ((user-book (ly:parser-lookup '$current-book)))
(if user-book
(ly:book-add-bookpart! user-book book-part)
(ly:parser-define!
'toplevel-bookparts
(cons book-part (ly:parser-lookup 'toplevel-bookparts))))))
scorePart =
#(define-scheme-function (instrument) (alist?)
#{
\new Staff
\with { instrumentName = #(ly:assoc-get 'name instrument) }
{ #(ly:assoc-get 'music instrument) }
#})
standalonePart =
#(define-void-function (instrument) (alist?)
(add-bookpart
#{
\bookpart {
\header { instrument = #(ly:assoc-get 'name instrument) }
\score {
\new Staff
\transpose #(ly:assoc-get 'key instrument) c'
#(ly:assoc-get 'music instrument)
}
}
#}))
% Score book
\book {
\header { instrument = "Concert Pitch Score" }
\score {
<<
\scorePart \flute
\scorePart \trumpet
>>
}
}
% Book containing all parts
\book {
\standalonePart \flute
\standalonePart \trumpet
}
%%%
Cheers,
Harm