lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme question: symbol to music


From: Johan Vromans
Subject: Re: Scheme question: symbol to music
Date: 12 Nov 2008 23:39:23 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Nicolas Sceaux <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]