Am 03.12.2011 20:25, schrieb Jay Anderson:
On Fri, Dec 2, 2011 at 3:26 AM, Marc Hohl<m...@hohlart.de>  wrote:
Now the data files contain different numbers of stanzas, and ideally, the
generator file
should be intelligent enough to include all stanzas which are present. Has
someone an idea
how to create a loop which scans for textA, textB, textC etc. and puts a
command that acts like
\addlyrics for each hit?
I'll add my solution to this problem. I keep each verse in a separate
file with just "\lyricmode {...}". These are named verse_1.ily,
verse_2.ily, etc. Then where I want the lyrics I add '\createLyrics
"001" "soprano"' (see below for the definition). It isn't doing
\addLyrics, but \new Lyrics ... \lyricsto ... so it isn't exactly the
same. It isn't perfect but it works for what I need.
Hello Jay,

I think this would clutter up my file structure, but I think I'll find
a use of your solution for another project - thanks for sharing!

Marc
-----Jay

==========
#(use-modules (ice-9 regex))

#(define (verse-files dir)
   (define (is-verse-file? file)
     (string-match "^verse_[0-9]+\\.ily$" file))
   (let ((dir-stream (opendir dir))
         (count 0))
     (do
       ((entry (readdir dir-stream) (readdir dir-stream)))
       ((eof-object? entry))
       (if
         (is-verse-file? entry)
         (set! count (+ 1 count))))
     (closedir dir-stream)
     count))

#(define (range a b)
   (define (range-inner a b out)
     (if (>  a b)
       out
       (range-inner a (- b 1) (cons b out))))
   (range-inner a b '()))

createLyrics =
#(define-music-function (parser location dir voice) (string? string?)
   (make-simultaneous-music
     (map
       (lambda (num)
         (let* ((num-str (number->string num))
                (file (string-append dir "/verse_" num-str ".ily"))
                (verse (string-append num-str ".")))
           #{ \new Lyrics \with {alignAboveContext = "bot"} \lyricsto
$voice { \set stanza = $verse { \include $file }} #}))
       (range 1 (verse-files dir)))))
===============



_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to