Learning LilyPond - Parser permissiveness

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Learning LilyPond - Parser permissiveness

Colin Tennyson
I noticed that in some places there is remarkable freedom to exchange order and grouping of commands.

Take the following nesting structure:

addKey = { \key c \major  \time 4/4 }
instrOne = { \set Staff.instrumentName = #"Superius " }
instrTwo = { \set Staff.instrumentName = #"Contratenor " }

\score {
  \new StaffGroup
  <<
    \new Staff
    <<
      \new Voice = "staffOne" { \instrOne \addKey \staffOneNotes }
      \new Lyrics \lyricsto "staffOne" \staffOneWords
      \barSetup
    >>
    \new Staff
    <<
      \instrTwo \addKey \new Voice = "staffTwo" \staffTwoNotes
      \lyricsto "staffTwo" \new Lyrics \staffTwoWords
      \barSetup
    >>
  >>
}


\new Voice = "staffOne" { \instrOne \addKey \staffOneNotes }
\new Lyrics \lyricsto "staffOne" \staffOneWords

versus:

\instrTwo \addKey \new Voice = "staffTwo" \staffTwoNotes
\lyricsto "staffTwo" \new Lyrics \staffTwoWords


Both are accepted by the parser, and they are rendered identically.

I'm amazed that the parser is able to disambiguate the source code. There are no delimiters between the expressions. How does the parser figure out where one expression has ended, and the next one has begun?

If I hazard a guess it seems likely that it's best to put the keyword \new at the start of the expression. It looks really odd to first specify \lyricsto, and after that instantiate a new Lyrics context. Still, it renders correctly.

The graphical output is rendered identially, but maybe it makes a different for the MIDI output, such as creating a spurious empty track that shows up when you later open the MIDI file with a MIDI editor.



++++++++++++++++++++++++++++++++++++++++++++++++++

\version "2.18.0"
\language "english"

% 't' as in 'test' or 'transcribing an existing score'
tBreak = { \break }
ficta = { \once \set suggestAccidentals = ##t }

barSetup = {
  % for the Mensurstriche: inside the staff hide the barline
  \override Staff.BarLine.transparent = ##t
  % for the Mensurstriche: inside the staff hide the barline
  %\override Staff.BarLine.stencil = ##f  
  s1 |         s1 |         s1 | \tBreak s1 |         s1 |         %05
  s1 |         s1 |         s1 | \tBreak s1 |         s1 |         %10
  \override Staff.BarLine.transparent = ##f \bar "||" % final barline visible
  %\override Staff.BarLine.stencil = ##t  
}
staffOneNotes =  \relative c'' {
  g1 | g2 a2 | b2 g2 | r2 a2 | d2. c4 | %005
  b2 a2 | r4 d4 d4 b4 | c4. b8 a8[ g8] a4. g8[ f8 e8] d4 a'2  g2 \ficta fs4 |  %010
}
staffOneWords = \lyricmode {
  San -- | cta Ma -- | ri -- a,  San -- | cta Ma -- | %005
  ri -- a,   suc -- cur -- re |  mi- _ _ _ _    _ _ _ _ _   _ %010
}
staffTwoNotes =  \relative c' {
  %\clef "G_8"
  g2 c2.  d4 a2 | g4. a8 b8[ c8] d2 cs4 d2 | r4  d2 d4 |  %005
  e2 f2 | d2 r2 | c2 f2. d4 f2 | e2 d4. c8 | %010
}
staffTwoWords = \lyricmode {
  San -- cta Ma -- ri -- _ _ _ _ _   _ a, San -- cta %05
  Ma -- ri -- a, suc -- cur -- re mi -- se- _ _  %10
}

\header {
  title = "Sancta Maria, succurre miseris"
  composer = "Philippe Verdelot"
  tagline = ""
}

addKey = { \key c \major  \time 4/4 }
instrOne = { \set Staff.instrumentName = #"Superius " }
instrTwo = { \set Staff.instrumentName = #"Contratenor " }

\score {
  \new StaffGroup
  <<
    \new Staff
    <<
      \new Voice = "staffOne" { \instrOne \addKey \staffOneNotes }
      \new Lyrics \lyricsto "staffOne" \staffOneWords
      \barSetup
    >>
    \new Staff
    <<
      \instrTwo \addKey \new Voice = "staffTwo" \staffTwoNotes
      \lyricsto "staffTwo" \new Lyrics \staffTwoWords
      \barSetup
    >>
  >>

  \layout
  {
    indent = 50
    \override Score.SystemStartBracket.transparent = ##t
    \override Score.BarNumber.font-size = #1
    \override Score.BarNumber.break-visibility = #end-of-line-invisible
    \override Score.BarNumber.self-alignment-X = #LEFT
    \set Score.barNumberVisibility = #(every-nth-bar-number-visible 5)
    \override Staff.InstrumentName.self-alignment-X = #RIGHT    
    \context { \Voice \remove "Forbid_line_break_engraver" }
    ragged-last = ##t
    #(layout-set-staff-size 18)
  }
  %\midi { }
}

\paper {
  left-margin = 30
  right-margin = 30
}
Reply | Threaded
Open this post in threaded view
|

Re: Learning LilyPond - Parser permissiveness

David Kastrup
Colin Tennyson <[hidden email]> writes:

> I noticed that in some places there is remarkable freedom to exchange order
> and grouping of commands.
>
> Take the following nesting structure:
>
> addKey = { \key c \major  \time 4/4 }
> instrOne = { \set Staff.instrumentName = #"Superius " }
> instrTwo = { \set Staff.instrumentName = #"Contratenor " }
>
> \score {
>   \new StaffGroup
>   <<
>     \new Staff
>     <<
>       \new Voice = "staffOne" { \instrOne \addKey \staffOneNotes }
>       \new Lyrics \lyricsto "staffOne" \staffOneWords
>       \barSetup
>     >>
>     \new Staff
>     <<
>       \instrTwo \addKey \new Voice = "staffTwo" \staffTwoNotes
>       \lyricsto "staffTwo" \new Lyrics \staffTwoWords
>       \barSetup
>     >>
>   >>
> }
>
>
> \new Voice = "staffOne" { \instrOne \addKey \staffOneNotes }
> \new Lyrics \lyricsto "staffOne" \staffOneWords
>
> versus:
>
> \instrTwo \addKey \new Voice = "staffTwo" \staffTwoNotes
> \lyricsto "staffTwo" \new Lyrics \staffTwoWords
>
>
> Both are accepted by the parser, and they are rendered identically.
>
> I'm amazed that the parser is able to disambiguate the source code. There
> are no delimiters between the expressions. How does the parser figure out
> where one expression has ended, and the next one has begun?

<URL:http://lilypond.org/doc/v2.18/Documentation/contributor/lilypond-grammar>

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Learning LilyPond - Parser permissiveness

Vaughan McAlley
In reply to this post by Colin Tennyson
On 4 January 2014 20:12, Colin Tennyson <[hidden email]> wrote:
> ficta = { \once \set suggestAccidentals = ##t }

(Slightly OT): You may be interested in my slightly modified \ficta...

+++++++++++++++++++++++++++++++++++++
\version "2.18.0"
\language "english"
ficta = {
  \once \set suggestAccidentals = ##t
  \once \accidentalStyle "dodecaphonic" % second & subsequent
accidentals in a bar will be printed
}

\relative c'' {
  b8 a a4. \ficta gs16 \ficta fs \ficta gs4
  a1
}

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Learning LilyPond - Parser permissiveness

Colin Tennyson
Vaughan McAlley wrote
 my slightly modified \ficta...

ficta = {
  \once \set suggestAccidentals = ##t
  \once \accidentalStyle "dodecaphonic" %{ second & subsequent
accidentals in a bar will be printed %}
}

The full 100 measure score does have measure with a repeated ficta. You pointing out the \accidentalStyle "dodecaphonic" is a godsend!