[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Completely separating notation from output logic
From: |
Michael Ellis |
Subject: |
Completely separating notation from output logic |
Date: |
Mon, 3 Jan 2011 15:01:51 -0500 |
I'm trying to develop an include file with Scheme functions that will
allow notation files to contain nothing more than a header block and
music for one or more voices. Below is what I've got so far. What
I'm finding is that I can easily define a music function that appends
voices to a list and a corresponding function that retrieves them in
order within the context of a \score block. What doesn't work so
far is trying to generate the score block itself. I get an error
complaining about "Unexpected \score". I'm assuming that's because a
\score isn't a music type. Is that right? Also, what I'm doing now
feels a bit hackish. Is there a more elegant approach?
Thanks,
Mike
%% To go into an include file, e.g. "myinclude.ly" ...
\version "2.12.3"
%% Append music for one voice to a list.
appendVoice = #(define-music-function (P L ml m) (list? ly:music?)
(append! ml m))
%% Insert a voice in a score block
newvoice = #(define-music-function (P L M) (ly:music?)
#{
\new Voice $M
#})
%% Insert list of voices to a score block
allvoices = #(define-music-function (P L mlist) (list?)
(if (eq? mlist '())
#{ #}
(let ((v (car mlist)))
#{
\newvoice $v
#}
(allvoices (cdr mlist)))))
%% Generate a score block containing voices from a list.
thescore = #(define-music-function (P L mlist) (list?)
#{
\score {
<<
\allvoices \myvoices
>>
}
#})
%% ---------------------------------------
%% To go into a notation file
%\include "myinclude.ly"
#(define myvoices '())
\appendVoice \myvoices \relative c' { e f g a }
\appendVoice \myvoices \relative c' { c d e f }
%% THIS WORKS
\score {
<<
\allvoices \myvoices
>>
}
%% THIS DOES NOT
\thescore \myvoices
Cheers,
Mike
- Completely separating notation from output logic,
Michael Ellis <=