Nicolas Sceaux <[EMAIL PROTECTED]> writes:
> A more idiomatic way to do it:
Nice. This gives me the following snippet:
% \ifDefined #'symbol
% Returns the music expression defined by symbol,
% or a void expression if symbol has not been defined.
ifDefined =
#(define-music-function (parser location sym) (symbol?)
(let ((music (ly:parser-lookup parser sym)))
(if (ly:music? music)
music
(make-music 'Music 'void #t))))
% \ifDefinedThen #'symbol expression
% Returns the music expression if the symbol is defined,
% or a void expression if symbol has not been defined.
ifDefinedThen =
#(define-music-function
(parser location sym music)
(symbol? ly:music?)
(if (defined? sym)
music
(make-music 'Music 'void #t)))
% Sample application
% Some notes.
leadMusic = \relative c' { c e g }
% This can be defined. Or not.
%leadWords = \lyricmode { g e c }
\score {
<<
%% Generic snippet starts here.
\new Staff = Lead <<
\new Voice = LeadVoice {
\set Staff.instrumentName = \leadName
\set Staff.midiInstrument = "acoustic grand"
\global
\leadMusic
}
\ifDefinedThen #'leadWords
\new Lyrics \lyricsto LeadVoice \ifDefined #'leadWords
>>
%% Generic snippet ends here.
>>
\layout { }
\midi { }
}
Still not as flexible as I would like to, but it suits my current
purposes.
Thank you all for the suggestions.
-- Johan
_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user