1

I have recently started writing music notation with LilyPond. I find it convenient to split songs into different parts such as prelude, intro, interlude etc. So I have:

%prelude.ly
\new StaffGroup <<
  \override StaffGroup.SystemStartBracket.stencil = ##f

  \new Staff \with {
    instrumentName = "Piano"
    shortInstrumentName = "Pno"
  } \new Voice \relative c'' {
    c d e f
  }
>>

and

%intro.ly
\new StaffGroup <<
  \override StaffGroup.SystemStartBracket.stencil = ##f

  \new Staff \with {
    instrumentName = "Piano"
    shortInstrumentName = "Pno"
  } \new Voice \relative c'' {
    g a b c
  }
>>

Then I combine everything like so:

<<
  \chords {
    c,2 g,2 c,2 f,2 g,2 f,2 g,2 c,2
  }

  {
    \include "prelude.ly"
    \include "intro.ly"
  }
>>

This method works quite well for large scores. Except I get line breaks at StaffGroup boundaries as shown below:

Score on a staff that splits horizontally at the boundary between the prelude and the intro

Questions:

  1. Does an average musician find these breaks annoying or are they quite common?
  2. How can I avoid these breaks? Would be nice to get rid of the staff symbols at the boundaries as well.
  3. Are there better ways of organising large scores?

Update: Answers below have suggested avoiding multiple staffgroups. But if possible I would prefer to have a new staffgroup for each part of score. This allows me the felxibility to add more instruments in parallel to a particular part without affecting anything else.

3 Answers 3

4

Your code essentially evaluates to something like

{
  %prelude.ly
  \new StaffGroup <<
    \override StaffGroup.SystemStartBracket.stencil = ##f

    \new Staff \with {
      instrumentName = "Piano"
      shortInstrumentName = "Pno"
    } \new Voice \relative c'' {
      c d e f
    }
  >>
  
  %intro.ly
  \new StaffGroup <<
    \override StaffGroup.SystemStartBracket.stencil = ##f

    \new Staff \with {
      instrumentName = "Piano"
      shortInstrumentName = "Pno"
    } \new Voice \relative c'' {
      g a b c
    }
  >>
}

You see that you are calling \new StaffGroup and \new Staff multiple times. This means that at the point in question Lilypond will simply create a new context, which is by default placed below the currently existing context. To achieve what you want you should not use \new ContextType, but \context ContextType = contextID. This will attempt to find a context of given type and ID (if nothing found a new context is created) and will switch to that context. So if you do

{
  %prelude.ly
  \context StaffGroup = "SG1" <<
    \override StaffGroup.SystemStartBracket.stencil = ##f

    \context Staff = "Staff1" \with {
      instrumentName = "Piano"
      shortInstrumentName = "Pno"
    } \new Voice \relative c'' {
      c d e f
    }
  >>
  
  %intro.ly
  \context StaffGroup = "SG1" <<
    \override StaffGroup.SystemStartBracket.stencil = ##f

    \context Staff = "Staff1" \with {
      instrumentName = "Piano"
      shortInstrumentName = "Pno"
    } \new Voice \relative c'' {
      g a b c
    }
  >>
}

it works as you intend. In fact you can even outsource the chordnames into the separate files:

{
  %prelude.ly
  <<
    \context ChordNames = "CN" \chordmode {
      c,2 g,2 c,2 f,2
    }
    \context StaffGroup = "SG1" <<
      \override StaffGroup.SystemStartBracket.stencil = ##f
  
      \context Staff = "Staff1" \with {
        instrumentName = "Piano"
        shortInstrumentName = "Pno"
      } \new Voice \relative c'' {
        c d e f
      }
    >>
  >>
  
  %intro.ly
  <<
    \context ChordNames = "CN" \chordmode {
      g,2 f,2 g,2 c,2
    }
    \context StaffGroup = "SG1" <<
      \override StaffGroup.SystemStartBracket.stencil = ##f
  
      \context Staff = "Staff1" \with {
        instrumentName = "Piano"
        shortInstrumentName = "Pno"
      } \new Voice \relative c'' {
        g a b c
      }
    >>
  >>
}
1
  • you are awesome!!
    – kargirwar
    Jun 11 at 16:25
1

I've never seen anything like that before, it just looks like a mistake.


I suggest moving the common parts of your subfiles (prelude.ly & intro.ly) into the combining file (combine.ly), and making variables (\prelude & \intro) for the music in each of these.

Something like this:

%% prelude.ly

\version "2.24.1"

prelude = {
    \relative c'' {
        c2 d e f
    }
}

%\score {
%   \prelude
%}
%% intro.ly

\version "2.24.1"

intro = {
    \relative c'' {
        g2 a b c
    }
}

%\score {
%   \intro
%}
%% combine.ly

\version "2.24.1"

\include "prelude.ly"
\include "intro.ly"

<<
    \chords {
        c,2 g, c, f, g, f, g, c,
    }

    \new StaffGroup <<
        \override StaffGroup.SystemStartBracket.stencil = ##f

        \new Staff \with {
            instrumentName = "Piano"
            shortInstrumentName = "Pno"
        }
            \new Voice {
                \prelude
                \intro
            }
    >>
>>

This will give a "normal looking" score: Single staff with prelude and intro joined seamlessly


NB: When you are working on the subfiles, you'll want to uncomment the \score blocks, so that you will be able to see what you are doing (by compiling the subfiles) without having to compile the combine.ly file. Re-comment them when you have finished working on the subfiles, so that you don't get duplication in the combine.ly file.

3
  • Avoiding multiple staffgroups is the most straightforward solution. But if possible I would prefer to have a new staffgroup for each part of score. This allows me the felxibility to add more instruments in parallel to a particular part without affecting anything else.
    – kargirwar
    Jun 11 at 7:49
  • @kargirwar This comment should be part of your original post so that you get answers relevant to your goals.
    – Aaron
    Jun 11 at 13:34
  • Regarding your NB: Instead you can also do something like wrapping your \score blocks in $(if (or (not (defined? 'INCLUDED)) (not INCLUDED)) #{ \score { ... } #}). This will create a score unless you’ve done INCLUDED = ##t. Thus you won’t have to do any comment/uncomment game but simply have a score created if compiled as single file and not if included (as long as the including file does INCLUDED = ##t).
    – Lazy
    Jun 11 at 16:04
0

Consider your code in toto:

<<                                                                                  
  \chords {                                                                         
    c,2 g,2 c,2 f,2 g,2 f,2 g,2 c,2                                                 
  }                                                                                 
                                                                                    
  {                                                                                 
    %prelude.ly
    \new StaffGroup <<                                                                  
    \override StaffGroup.SystemStartBracket.stencil = ##f                             
                                                                                    
    \new Staff \with {                                                                
      instrumentName = "Piano"                                                        
      shortInstrumentName = "Pno"                                                     
    } \new Voice \relative c'' {                                                      
    c d e f                                                                         
    }                                                                                 
  >>
  %intro.ly
  \new StaffGroup <<                                                                  
    \override StaffGroup.SystemStartBracket.stencil = ##f                             
                                                                                      
    \new Staff \with {                                                                
      instrumentName = "Piano"                                                        
      shortInstrumentName = "Pno"                                                     
    } \new Voice \relative c'' {                                                      
      g a b c                                                                         
    }                                                                                 
  >> 
  }                                                                                 
>>

The image posted in the question is as expected, because a new staff group was started. But this is not what is actually desired. To get the desired result, the complete code should be more like this:

<<                                                                                  
  \chords {                                                                         
    c,2 g,2 c,2 f,2 g,2 f,2 g,2 c,2                                                 
  }                                                                                 
                                                                                    
  {                                                                                 
    \new StaffGroup <<                                                                  
    \override StaffGroup.SystemStartBracket.stencil = ##f                             
                                                                                    
    \new Staff \with {                                                                
      instrumentName = "Piano"                                                        
      shortInstrumentName = "Pno"                                                     
    } \new Voice \relative c'' {                                                      
      %prelude.ly
      c d e f                                                                         
      %intro.ly
      g a b c                                                                         
    }                                                                                 
  >>
  }
>>

Which is to say:

<<                                                                                  
  \chords {                                                                         
    c,2 g,2 c,2 f,2 g,2 f,2 g,2 c,2                                                 
  }                                                                                 
                                                                                    
  {                                                                                 
    \new StaffGroup <<                                                                  
    \override StaffGroup.SystemStartBracket.stencil = ##f                             
                                                                                    
    \new Staff \with {                                                                
      instrumentName = "Piano"                                                        
      shortInstrumentName = "Pno"                                                     
    } \new Voice \relative c'' {                                                      
        \include "prelude.ly"                                                           
        \include "intro.ly"                                                             
    }                                                                                 
  >>
  }
>>

In which the include files just contain the notes for that part of the piece.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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