Search code examples
lilypond

How can I use the segno repeat when the Coda mark would be within another repeat?


The song as two verses that use a normal volta repeat. After the two verses comes an additional part. At the end of the additional part, there should be a jump back to the beginning. Instead of going through both verses again, there should be the coda mark to jump to the finale right after the first verse.

My attempts compile but they don't produce the correct output, probably because there are two interleaving \alternative blocks.

I tried something like this:

\version "2.22.0"

\relative c {
  \autoBeamOff
  \clef "treble_8"
 
  \partial 4
  c

  \repeat segno 2 {
    \repeat volta 2 {
      c c c c %<verseNotes>
    }
    \alternative {
      \volta 1 {
        \alternative {
          \volta 1 {
            g1 %<firstEndFromVoltaRepeatRepeatingVerseNotes>
          }
          \volta 2 {
            c1 %<secondEndFromVoltaRepeatRepeatingVerseNotes>
          }
        }

        c4 c c c
      }
      \volta 2 \volta #'() {
        \section
        \sectionLabel "Finale"
      }
    }

    c2 c
    \fine
  }  
}

But the problem is, that it really misinterprets the relation between these alternatives.

It should show the Coda sign just at the bar at the beginning of the two alternatives that should end the verse.

Is there any way to set some kind of an anchor that tells lilypond to what \repeat an \alternative belongs to?

Or do I need a completely different approach?


Solution

  • Firstly, I'm not sure how you managed to get the segno repeat to work with version 2.22.0; it was new to LilyPond with v2.23.

    In versions 2.24 & 2.25, the segno repeat structure works fine in isolation, sequentially, or even when nested, but it hasn’t been designed to work in an overlapping way with the volta repeat structure. (This is basically because there aren’t anchors for the \alternative and \volta n blocks; there is no way of specifying which repeat structure they are referring to.)


    To make it easier to work with, I’ve relabelled the various sections with single letters:

    • A = anacrusis (introduction)
    • B = verse
    • C = 1st ending
    • D = 2nd ending
    • E = additional part (bridge)
    • F = finale (coda)

    If I’m understanding correctly, you are trying to achieve the form: A-BC-BD-E-BC-F, with the BC-BD as a Volta repeat, and the E-BC-F as a Dal Segno al Coda repeat — it’ll look something like:

    Score: A; start repeat, segno, B; 1st volta, C, to coda, end repeat; 2nd volta, D; E, D.S. al Coda; Coda F.

    These repeat loops can’t be separated because the BC needs to be in both, and they can’t be combined into a single loop because they are different types. This flowchart attempts to shows why there is no way for the two repeat loops to be separated:

    Flowchart: A to B, B1,3 to C, B2 to D, C to B, D to E, E to B, C to F


    Nevertheless, it is possible to get this structure to work (even if the code is inelegant and cumbersome).

    Instructions that are only to appear when folded can placed manually with the \volta #'() command. And conversely, the \unfolded command can be used to explicitly define how the repeat is to unfold.

    For some reason, the coda mark doesn’t want to appear in the right place, but we can get rid of it with \omit \codaMark 1, and place one in the correct spot with \codaMark 1.

    Unfortunately, the B and C sections appear twice in the code, but you can always make variables for these.

    Code

    The code below will look like the image at the top, but importantly it will also unfold correctly.

    \version "2.24.1"
    
    music = {
        s1_"A" |
        \section
        \repeat segno 2 {
            \volta 1 {
                \repeat volta 2 {
                    s1_"B" |
                }
                \alternative {
                    \volta 1 {
                        s1_"C" |
                        \section
                        \volta #'() {
                            \codaMark 1
                        }
                    }
                    \volta 2 {
                        s1_"D" |
                        \omit \codaMark 1
                        \section
                    }
                }
            }
            \unfolded {
                \volta 2 {
                    s1_"B" |
                    s1_"C" |
                    \section
                }
            }
        }
        \alternative {
            \volta 1 {
                s1_"E" |
                \section
            }
            \volta 2 \volta #'() {
                \sectionLabel "Coda"
            }
        }
        s1_"F" |
        \fine
    }
    
    \score { \music }
    
    \score { \unfoldRepeats \music }
    

    For the documentation about long repeats see:
    https://lilypond.org/doc/v2.24/Documentation/notation/long-repeats