lilypond-user
[Top][All Lists]
Advanced

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

Scheme music function to expand lyrics


From: Yannick CHARLES
Subject: Scheme music function to expand lyrics
Date: Fri, 5 Apr 2013 23:12:44 +0200

Hello everybody !

I am working on a project involving a collection of songs and hymns,
and I wanted to make the files more "generic", based on the song
templates (i.e. verse-verse, verse-chorus...)

Ideally I would like at some point in my source file to have a music
function build the staves, and insert the correct number of verses
(assuming verse-verse template).
That is, for a song with 4 verses (variable nCouplets), this music
expression would expand to :

 <<
  \accidentalStyle #'Score "modern"
  \new ChordNames \with {
    midiInstrument = "acoustic guitar (nylon)"
  } { \transpose d d, \accords }
  \new Staff \with {
    midiInstrument = "clarinet"
  } <<
    \new Voice = "melodie" { \melodie }
  >>
   \new Lyrics \with {
     \override VerticalAxisGroup #'staff-affinity = #CENTER
 } \lyricsto "melodie" \coupletUn
   \new Lyrics \with {
     \override VerticalAxisGroup #'staff-affinity = #CENTER
 } \lyricsto "melodie" \coupletDeux
   \new Lyrics \with {
     \override VerticalAxisGroup #'staff-affinity = #CENTER
 } \lyricsto "melodie" \coupletTrois
   \new Lyrics \with {
     \override VerticalAxisGroup #'staff-affinity = #CENTER
 } \lyricsto "melodie" \coupletQuatre
>>

where "\coupletXX" is the music variable storing the lyrics of verse XX.
I'm quite a beginner with scheme (and advanced lilypond as well), but
I have the idea of using a kind of iterative structure (I've seen that
there is a "do" construct in scheme), that will get the proper verse
name from an associative list. However I'm stuck quite near the start,
as I don't manage to use the result of a scheme function as a variable
containing the lyrics.

The example I provide below is working, as I define a test variable :
#(define test #{ \coupletUn #})
and reuse it directly after :
\new Lyrics \with {
     \override VerticalAxisGroup #'staff-affinity = #CENTER
 } \lyricsto "melodie" $test

But if I try something like : #(define test (cdr (assoc 1 verseList)))
it fails, giving an error at $test saying "syntax error, unexpected
SCM_IDENTIFIER" and "warning: ignored non musical expression".

Could someone give me a hint ? Or tell me if I'm going to a wrong
direction ? I'm not used to functional programming, so I'm not sure my
way of taking the problem is good or not.

Thanks !
Yann

---------

% Working piece of code:
\version "2.16.0"

% Number of verses
nCouplets = 4

% Music variables
melodie = \relative c' {
  \slurDotted c4( c) \slurSolid d g |
  c,1 |
}

accords = \chordmode {
  \set chordChanges = ##t
  c2. g4 |
  c1 |
}

coupletUn = \lyricmode {
  \set stanza = "1."
  \set ignoreMelismata = ##t
  Lou -- ez
  \unset ignoreMelismata
  L'É -- ter -- "nel !"
}

coupletDeux = \lyricmode {
  \set stanza = "2."
  Car __ il est "bon !"
}

coupletTrois = \lyricmode {
  \set stanza = "3."
  \set ignoreMelismata = ##t
  Sa mi -- sé -- ri -- corde
  \unset ignoreMelismata
}

coupletQuatre = \lyricmode {
  \set stanza = "4."
  Dure __ à tou -- jours.
}

% Some scheme definitions
#(define verseList '((1 . #{ \coupletUn #}) (2 . #{ \coupletDeux #})
(3 . #{ \coupletTrois #}) (4 . #{ \coupletQuatre #}) (5 . #{
\coupletCinq #}) (6 . #{ \coupletSix #}) (7 . #{ \coupletSept #}) (8 .
#{ \coupletHuit #}) (9 . #{ \coupletNeuf #}) (10 . #{ \coupletDix #})
(11 . #{ \coupletOnze #}) (12 . #{ \coupletDouze #}) (13 . #{
\coupletTreize #}) (14 . #{ \coupletQuatorze #}) (15 . #{
\coupletQuinze #}) (16 . #{ \coupletSeize #})))

#(define test #{ \coupletUn #})

% Staves and so on
makeBasePart =
#(define-music-function
  (parser location numCouplets verseList)
  (number? cheap-list?)
  #{
  <<
  \accidentalStyle #'Score "modern"
  \new ChordNames \with {
    midiInstrument = "acoustic guitar (nylon)"
  } { \transpose d d, \accords }
  \new Staff \with {
    midiInstrument = "clarinet"
  } <<
    \new Voice = "melodie" { \melodie }
  >>

  % Node of the problem...
   \new Lyrics \with {
     \override VerticalAxisGroup #'staff-affinity = #CENTER
 } \lyricsto "melodie" $test

>>
#} )

basePart = \makeBasePart \nCouplets \verseList



% Book block
\book {
  \score {
    \basePart
    \layout { }
  }

  \score {
    \unfoldRepeats \basePart
    \midi { }
  }
}



reply via email to

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