Skip to main content
added tag
Link
Source Link
Dubl
  • 97
  • 4

creating a bookpart generating scheme function in lilypond

I am creating a piano book in LilyPond, which I am using for the first time. I am separating each piece into its own \bookpart, and if any of them have multiple movements, then each movement is in a different \score block. I also include table of contents entries for each \bookpart, and if there are multiple movements, one entry for each movement. I would like to create a scheme function that would generate the majority of this layout for me, to avoid copying/pasting this layout every time I add a piece to the book. I found the answer here that shows how to do something similar to what I would like, but with the following differences:

  • It needs to allow for multiple scores in the \bookpart
  • It needs to add a \tocItem for the \bookpart, and each \score.

After playing around with the answer in the link above, I reached a point where I had these functions:

defaultBookPart = #(define-scheme-function
    (scores toclabel tocentry title composer)
    (ly:score? (symbol-list-or-symbol? '()) markup? string? string? )
    (toplevel-bookpart-handler #{
        \bookpart {
            \header {
                title = $title
                composer = $composer
            }
            \tocItem $toclabel $tocentry
            #scores
        }
    #})
)

defaultScore = #(define-scheme-function
    (righthand lefthand piece opus)
    (ly:music? ly:music? string? string?)
    (toplevel-score-handler #{
        \score {
            \header {
                piece = #piece
                opus = #opus
            }
            \new PianoStaff <<
                \set PianoStaff.connectArpeggios = ##t
                \accidentalStyle "piano"
                \new Staff \relative {
                    #righthand
                }
                \new Staff \relative {
                    \clef "bass"
                    #lefthand
                }
            >>
        }
    #})
)

defaultMovementScore = #(define-scheme-function
    (righthand lefthand toclabel piece opus)
    (ly:music? ly:music? (symbol-list-or-symbol? '()) string? string?)
    (toplevel-score-handler #{
        \score {
            \header {
                piece = $piece
                opus = $opus
            }
            \new PianoStaff <<
                \set PianoStaff.connectArpeggios = ##t
                \accidentalStyle "piano"
                \new Staff \relative {
                    \tocItem $toclabel \markup $piece
                    #righthand
                }
                \new Staff \relative {
                    \clef "bass"
                    #lefthand
                }
            >>
        }
    #})
)

I am getting bad expression type errors when I try to use these, and in addition I see the following problems with this approach:

  • The first argument to the defaultBookPart function has the wrong type. I was unable to find in the documentation a score-list type, but it looks like there is a built-in function that takes a similar argument: ly:make-book-part. I was unable to find what the correct type to pass in there would be however.
  • I'm not sure that the toclabel arguments have the right type either. I was able to find the type specified above in the toc-init.ly file, but when I try to call my function, it doesn't seem to like the same input as can be used in the tocItem function.

Is there a way to resolve these issues? I am also having a hard time figuring out how to call these, passing the output of the score functions into the bookpart function.