lilypond-user
[Top][All Lists]
Advanced

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

Re: Nesting levels in the source code - why do I have to use one level m


From: David Wright
Subject: Re: Nesting levels in the source code - why do I have to use one level more than I thought?
Date: Thu, 29 Aug 2019 13:26:05 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Thu 29 Aug 2019 at 17:09:09 (+0200), Petr Pařízek wrote:
> Hello,
> 
> I'm currently learning to use LilyPond. I've finally succeeded in
> writing a short piece of music but there's one thing I don't
> understand. In my source code, there was one line that said "\score
> {". In order it worked at all, I had to keep a single left brace { on
> the immediately following line, which meant that I later had to use a
> single right brace } on two consecutive lines.
> 
> To me, this seems like an additional level of nesting which I didn't
> think was necessary. So I wanted to know why it has to be there or why
> the compiling process fails if I don't keep that.
> 
> To be more specific, I'll quote a shortened version of my code to give
> you a better idea of what I'm talking about.
> 
> -----
> 
> \version "2.19.83"
> 
> \language "deutsch"
> 
> \score {
> 
> {
> 
> \key g \major
> 
> \time 4/2
> 
> <<
> 
> \relative \new Staff {
> 
> % The top voice goes here.
> 
> }
> 
> \relative \new Staff {
> 
> % The middle voice goes here.
> 
> }
> 
> \relative \new Staff {
> 
> % The bottom voice goes here.
> 
> }
> 
> > > 
> 
> }
> 
> \layout { }
> 
> \midi { }
> 
> }
> 
> -----
> 
> Thank you for your suggestions or comments.

Indented code is easier to understand.

\version "2.19.83"
\language "deutsch"
\score {
  {
    \key g \major
    \time 4/2
    <<
      \relative \new Staff {
        %% The top voice goes here.
      }
      \relative \new Staff {
        %% The middle voice goes here.
      }
      \relative \new Staff {
        %% The bottom voice goes here.
      }
    >>
  }
  \layout { }
  \midi { }
}

I think your question is "Why do I need the second { and the }
before \layout?" The technical answer is that \score { … } accepts
a *single* musical expression. Because you've started your music with
\key g \major, that's your lot:

\score { \key g \major }

and any more requires to be made part of sequential or simultaneous
music, by enclosing in {} or <<>>. You've chosen the former:

\score {
  { \key g \major \time 4/2 … }
}

More likely what you want is something like:

\score {
  \new GrandStaff <<
    \new Staff <<
      …
    >>
    \new Staff <<
      …
    >>
  >>
  \layout { }
  \midi { }
}

and the expression   \new GrandStaff << … >>   is singular.

Cheers,
David.



reply via email to

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