Take the 2-minute tour ×
Musical Practice & Performance Stack Exchange is a question and answer site for musicians, students, and enthusiasts. It's 100% free, no registration required.

Here is a short snippet of Lilypond that I think expresses the intent of what I want to do.

verseNotes = \relative c' {
    d^\markup { \verseText } d d d16 d d8 a r4 |
    cis8 cis cis cis16 cis cis8 a r4 |
}

verseSection = \relative c' {
    \repeat volta 2 {
        \verseNotes
    }
    gis,1 |
    gis4. b8~b2 |
    \repeat volta 3 {
        verseText = "Verse (repeat 2x)"
        \verseNotes
    }
}

\relative c' {
    verseText = "Verse"
    \verseSection
}

It, of course, errors out.

I think the cause is something like verseNotes being bound at the time it is parsed, and \verseText having no value at the time.

I’m thinking I want the “dynamic” equivalent of a function of some sort, to which I pass a text param. I see various sections in the Lilypond documentation expressing stuff in Scheme, but this is likely last thing I want to be doing while entering music.

Thanks for any thoughts, or pointers.

share|improve this question
    
Could you explain in more detail what you are trying to do? –  SuperMusicman Oct 30 '13 at 5:06
    
SuperMusicman, I would like to re-use the verseNotes variable, but with different values of verseText. I will edit my snippet to illustrate. –  jbm Oct 30 '13 at 17:11
add comment

2 Answers 2

up vote 5 down vote accepted

Yes, you're right - you must declare the variable before using it. Hope this helps:

verseText = "Verse"

    verseNotes = \relative c' {
        d8^\markup { \verseText } d d d16 d d8 a r4 |
        cis8 cis cis cis16 cis cis8 a r4 |
    }

    verseSection = \relative c' {
        \repeat volta 2 {
            \verseNotes
        }
        gis'1 |
        gis4. b8~b2 |
    }       

    \score { 
     \new Staff \verseSection
    }

Peter's further solution, Nov 7, 2013:

verseNotes = \relative c' {
    d8 d d d16 d d8 a r4 |
    cis8 cis cis cis16 cis cis8 a r4 |
}

verseSection = \relative c' {
    \override Score.RehearsalMark #'self-alignment-X = #LEFT
    \mark \markup { \normalsize "Verse" }
    \repeat volta 2 {
        \verseNotes
    }

    gis'1 |
    gis4. b8~b2 |
    \mark \markup { \normalsize "Verse (repeat 2x)" }
    \repeat volta 3 {
        \verseNotes
    }
}

\score {
    \new Staff \verseSection
}
share|improve this answer
    
Ah, thanks! Can you tell me, if I wanted to re-use verseNotes again within verseSection, but with a different verseText, how could I set it? I don't seem to be able to simply put an assignment interspersed with the note list, which results in a syntax error. –  jbm Oct 30 '13 at 17:09
    
I've modified my original snippet to illustrate what I should've included originally, that I'd like to re-use the variable, but expand verseNotes using different values of verseText if that helps. I think I am confused over the scope of things and when I can perform variable assignments. –  jbm Oct 30 '13 at 17:14
1  
Now it easily gets more complicated. But to still keep things simple I propose to use the \mark command. Unfortunately I didn't succeed in editing my answer. –  PeterBjuhr Nov 2 '13 at 8:48
    
I think you can add another answer. And I would appreciate it :-) –  jbm Nov 6 '13 at 15:23
    
Peter emailed me the solution, I've added it to the code above. Thanks! [Grr, the code section is being shown briefly as it is highlighted for a split second, then replaced by blank lines.] –  jbm Nov 7 '13 at 23:35
show 2 more comments
I see various sections in the Lilypond documentation expressing stuff in Scheme, but this is likely last thing I want to be doing while entering music.

Better get used to it, though. At pure LilyPond level, you can only assign static music expressions. While one can introduce a bit of variation into those using \tag, it's not really a parameterization.

You usually don't need to be "expressing stuff" while entering music and vice versa: it's quite feasible to write Scheme for schemish things (namely the parameterization) and music for musicish things by employing #{...#} judiciously.

In this case, this would look (after some tiny octave, duration, and context fixes) like:

verseNotes =
#(define-music-function (parser location verseText) (markup?)
  #{
    \relative c' {
      d8^\markup { #verseText } d d d16 d d8 a r4 |
      cis8 cis cis cis16 cis cis8 a r4 |
    }
  #})

verseSection =
#(define-music-function (parser location verseText) (markup?)
  #{
     \relative c' {
       \repeat volta 2 {
          \verseNotes #verseText
       }
       gis1 |
       gis4. b8~b2 |
       \repeat volta 3 {
          \verseNotes "Verse (repeat 2x)"
       }
     }
  #})

\relative c' {
    \new Staff \verseSection "Verse"
}

As you can see, the Scheme code compresses itself into single lines that one can learn by heart easily enough and that are only moderately infuriating.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.