On Tue, Nov 25, 2014 at 8:49 AM, Jay Vara <j...@diljun.com> wrote:
> Trying to force the lyric in David's program to associate with the
> Staff/Voice, I added a name "jun" to the voice and see if that worked.
>
[...]
In this case, the lyrics, that is the pitch numbers, did not show up at
> all! Wonder why?
>
I think it's because \music gets interpreted and forces the creation of a
new higher-level context, but I'm pretty fuzzy here.
I wonder if there's a way to parse \music without any side effects. I see
various Scheme functions relating to the parser, but I'm pretty unfamiliar
with this area. Would ly:parser-clone get us somewhere?
Anyway, here's an interesting experiment.
First, I created a text file "display.txt" with the Scheme expression for
\music. I did this by running the file "out.ly".
I then added a # in front of the expression in the text file. Unsure of
how to automate that.
Next, I included the contents of the text file in the main file ("another.ly")
like so:
\new Staff
<<
\new Voice = "jun" \music
\noteNameToLyric \extractPitches \include "display.txt"
>>
And, like magic, it works!
--David
#(make-music
'RelativeOctaveMusic
'element
(make-music
'SequentialMusic
'elements
(list (make-music
'NoteEvent
'duration
(ly:make-duration 2)
'pitch
(ly:make-pitch 0 0))
(make-music
'NoteEvent
'pitch
(ly:make-pitch 0 1)
'duration
(ly:make-duration 2))
(make-music
'NoteEvent
'pitch
(ly:make-pitch 0 2)
'duration
(ly:make-duration 2))
(make-music
'NoteEvent
'pitch
(ly:make-pitch 0 3)
'duration
(ly:make-duration 2))
(make-music
'NoteEvent
'pitch
(ly:make-pitch 0 4)
'duration
(ly:make-duration 2))
(make-music
'NoteEvent
'pitch
(ly:make-pitch 0 5)
'duration
(ly:make-duration 2))
(make-music
'NoteEvent
'pitch
(ly:make-pitch 0 6)
'duration
(ly:make-duration 2))
(make-music
'NoteEvent
'pitch
(ly:make-pitch 1 0)
'duration
(ly:make-duration 2)))))
\version "2.19.15"
#(define (get-pitch elt)
(ly:music-property elt 'pitch))
#(define (extract-pitches lst result)
(cond
((null? lst) result)
((ly:pitch? (get-pitch (car lst)))
(set! result (append result (list (get-pitch (car lst)))))
(extract-pitches (cdr lst) result))
((ly:music-property (car lst) 'elements)
(append
(extract-pitches (ly:music-property (car lst) 'elements) result)
(extract-pitches (cdr lst) '())))
(else (extract-pitches (cdr lst) result))))
extractPitches =
#(define-scheme-function
(parser location lst)
(ly:music?)
(extract-pitches
(extract-named-music lst '(EventChord NoteEvent))
'()) )
#(define (t lst)
(let loop ((t lst) (result ""))
(if (null? t)
result
(loop (cdr t)
(string-append
result
"\""
(number->string (ly:pitch-notename (car t)))
"\""
" ")))))
noteNameToLyric =
#(define-void-function (parser location lst) (list?)
(let* ((str (t lst))
(str (string-append "{ " str "}")))
(display str) (newline)
(ly:parser-include-string
parser
(string-append " \\new Lyrics \\lyricsto \"jun\" " str))))
music = \relative c' { c4 d e f g a b c }
\new Staff
<<
\new Voice = "jun" \music
\noteNameToLyric \extractPitches \include "display.txt"
>>
music = \relative c' { c4 d e f g a b c }
{
#(with-output-to-file "display.txt"
(lambda () #{ \displayMusic \music #}))
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user