Hello,
Classical guitarist here trying to make exercises to help students
understand voices in Single-Staff polyphony.
I'm not a fan of the \voiceOneStyle (hard to read and notehead change is
redundant with color change, dots and rests don't change color). I'm
trying to get single-staff polyphony exploded onto multiple staves.
I've been working with some Scheme functions that create anki cards;
front is as-written, back in original cardify.ly is with easyheads on.
Been banging my head against the wall with this most of the day; it's
easy enough to just hard-code the voices and structure into the Scheme
Function, but then I'm stuck with using /X/ number of voices. And I
can't, for the life of me, figure out how to get the code into that
block and have it engrave properly.
Here's what I've managed to come up with (full disclosure: vibe
coding... sorry), but I can not, for the life of me, get it to work
anywhere near functional. Original is here
<https://github.com/dunstad/lilypond/blob/master/cardify.ly>, which I
already modified quite a bit for some improvements.
Thanks for any help
Input file:
\version "2.24.4"
#(define cardify #t)
\include "cardify-polyphonic-rhythms.ly"
#(define musicList
(makeMusicList
(list
#{
\parallelMusic voiceA,voiceB \relative c' {
% Bar 1
e'8\rest e8 e4|
e,,2 |
}
\new Staff
<<
\voiceA
\\
\voiceB
>>
#}
)))
$@musicList
cardify-polyphonic-rhythms.ly
\version "2.24.4"
#(define musicList '())
#(define (zero-pad-3 n)
(let* ((s (number->string n)) (l (string-length s)))
(if (>= l 3) s (string-append (make-string (- 3 l) #\0) s))))
#(define (lookup-music sym)
(let ((v (module-variable (current-module) sym)))
(if v (variable-ref v) #f)))
#(define (voices->back-sim)
(let* ((names '(voiceA voiceB voiceC voiceD))
(musics
(let loop ((ns names) (acc '()))
(if (null? ns)
(reverse acc)
(let* ((sym (car ns))
(m (lookup-music sym)))
(loop (cdr ns) (if m (cons m acc) acc))))))
(staves
(map (lambda (m)
(make-music 'ContextSpeccedMusic
'context-type 'Staff
'element m))
musics)))
(if (null? staves)
#f
(make-music 'SimultaneousMusic 'elements staves))))
#(define (two-books-for music idx)
(let* ((sfx (zero-pad-3 idx))
(sfx-e (string-append sfx "-e"))
(back (voices->back-sim)))
(if (not back)
(ly:error "No voices voiceA..voiceD defined for back side.")
(list
#{ \book {
\bookOutputSuffix #sfx
\score { $music \layout { } \midi { } }
} #}
#{ \book {
\bookOutputSuffix #sfx-e
\score { \new StaffGroup << $back >> \layout { } }
} #}))))
#(define (cardifyMusicList lst)
(let loop ((xs lst) (i 1) (acc '()))
(if (null? xs)
(begin (set! musicList (reverse acc)) musicList)
(let ((pair (two-books-for (car xs) i)))
(loop (cdr xs) (+ i 1) (append (reverse pair) acc))))))
#(define (scorifyMusicList lst)
(let ((scores
(map (lambda (m) #{ \score { $m \layout { } \midi { } } #}) lst)))
(set! musicList scores)
musicList))
#(define (get-cardify)
(let ((v (module-variable (current-module) 'cardify)))
(if v (variable-ref v) #f)))
#(define makeMusicList
(if (get-cardify) cardifyMusicList scorifyMusicList))