lilypond

In Lilypond, my repeats don't come out as I expect


I am trying to score a piece in lilypond with the structure:

Section_a ending_1 Section_a ending_2 Section_b Section_a ending_1

My code is:

\repeat segno 2 {
\repeat volta 2 {  \Section_a
        \alternative {
          \volta 1  {\ending_1 }
          \volta 2  {\ending_2 }
        }
  
  \Section_b
}}

It looks OK on the PDF, but when I unfold it to create a midi file, the repeats are not what I want (so I assume that my code is wrong).

It all seems to work OK if I just code for section a with endings 1 and 2 followed by section b; it's when I try to add a Da Capo back to section a by wrapping it in the outer "\repeat segno 2" that it falls apart.

I'd appreciate any help, but I'd particularly appreciate pointers to a good teaching resource about the repeat structure (I'm finding the lilypond notation reference to be rather obscure on this topic)


Solution

  • It's always best to post working, well-formatted code in your example. Also, you don't say what exactly what goes wrong so it's hard to know how to fix it.

    But with a couple of assumptions I can up with this code that "works" (does what I would expect):

    \version "2.24.4"
    
    music = 
    \repeat segno 2 {
      s1_1
      \repeat volta 2 { 
        s1_2
        \alternative {
          \volta 1 { s1_3 }
          \volta 2 { s1_4 }
        }
      }
      s1_5
    }
    
    \score { \music }
    \score { \unfoldRepeats \music }
    

    If this is what you were expecting, then I can say that \Section_b is in the wrong place. It needs to be below the second brace, where my s1_5 is. Tell me if that helps and if not, post working code and a detailed explanation.

    Edit: You also asked for teaching resources. The LilyPond docs are the best place. Try here: https://lilypond.org/doc/v2.24/Documentation/notation/long-repeats