Re: Trouble hiding NullVoice

2022-03-27 Thread Lukas-Fabian Moser

Hi Samanth,

(Please keep the list in your replies, so future readers can follow the 
discussion.)


When I put in the \new Staff, it does indeed prevent the nullVoice 
from producing a staff ... however the chords now appear in the wrong 
line ... almost as if they are being put above where the NullVoice 
score would have been.


It's easier to define the "correct" order of contexts once and for all, 
so I took the liberty of re-organizing your score a bit.


While doing , I noticed something else that I missed before: If you 
enter the durations of your Lyrics words explicitly, you do not need a 
(Null)Voice to align the lyrics to. There are two fundamentally 
different ways of writing Lyrics in LilyPond:


- with explicit lengths (as you did: "When8. I16" etc.)
- without explicit lengths, but aligned to a Voice or NullVoice

So one can reduce to:

% When I'm Sixty Four - Bass Song Sheet
\version "2.22.2"
\language english

\header {
  title = "When I'm Sixty Four"
  subtitle = Bass
  composer = "McCartney/Lennon"
}

% Setup variables for Chords, Notes, Rhythm and Lyrics
introChords = \chordmode {
  c1 c1 f2 g2 |
  c1 c1 c1 |
}

verseChords = \chordmode {
  c1 c1 c1 g1:7 |
}

introNotes = \relative c, {
  c4 r4 g4 r4 |
  c4 r4 g4 r4 |
  f4 r4 g4 r4 |
  \break
  c4 g4 c4 r4 |
  c4 r4 g4 r8 a16 b16 |
  c4 r4 g4 r4 |
  \bar "||"
  \break
}

verseNotes = \relative c, {
  c4 r4 g4 r4 |
  c4 r4 g4 r4 |
  c4 r4 g4 r4 |
  g4 r4 d'4\3 r4 |
  \break
}

verseOneLyrics = \lyricmode
{
  \set stanza = "1. "
  When8. I16 get4 old4 -- er4
  losing4 my4 hair2
  Many4 years4 from4 now4 "___"1
}

<<
  \new ChordNames {
    \introChords
    \verseChords
  }
  \new Staff \with {
    \easyHeadsOn
    \clef "bass_8"
  } {
    \introNotes
    \verseNotes
  }
  \new Lyrics {
    #(skip-of-length introNotes)
    \verseOneLyrics
  }
>>

But it's often easier to actually use a (Null)Voice for this, since that 
way we don't have to clutter the lyrics with durations. The way I'd 
personally do it would be (as I often need the actual melody as well, I 
went ahead and entered it with pitches - but these might also be omitted):


% When I'm Sixty Four - Bass Song Sheet
\version "2.22.2"
\language english

\header {
  title = "When I'm Sixty Four"
  subtitle = Bass
  composer = "McCartney/Lennon"
}

% Setup variables for Chords, Notes, Rhythm and Lyrics
introChords = \chordmode {
  c1 c1 f2 g2 |
  c1 c1 c1 |
}

verseChords = \chordmode {
  c1 c1 c1 g1:7 |
}

introNotes = \relative c, {
  c4 r4 g4 r4 |
  c4 r4 g4 r4 |
  f4 r4 g4 r4 |
  \break
  c4 g4 c4 r4 |
  c4 r4 g4 r8 a16 b16 |
  c4 r4 g4 r4 |
  \bar "||"
  \break
}

verseNotes = \relative c, {
  c4 r4 g4 r4 |
  c4 r4 g4 r4 |
  c4 r4 g4 r4 |
  g4 r4 d'4\3 r4 |
  \break
}

melody = \relative {
  R1*6
  e'8 ds e8 g4. e4 % If we're not interested in the pitches, we can 
simply write 8 8 8 4. 4 etc.

  g8 a g c4. r4
  c8 e4. c4 a8 d8~
  d2 r
}

verseOneLyrics = \lyricmode
{
  \set stanza = "1. "
  When I get old -- er
  lo -- sing my hair
  Ma -- ny years from now __
}

<<
  \new ChordNames {
    \introChords
    \verseChords
  }
  \new Staff \with {
    \easyHeadsOn
    \clef "bass_8"
  }
  <<
    {
  \introNotes
  \verseNotes
    }
    \new NullVoice = mel \melody
  >>
  \new Lyrics \lyricsto mel {
    \verseOneLyrics
  }
>>

\new StaffGroup <<
  \new ChordNames {
    \introChords
    \verseChords
  }
  \new Staff \with { \autoBeamOff }
  \new Voice = "mel" \melody
  \new Lyrics \lyricsto mel {
    \verseOneLyrics
  }
  \new Staff \with {
    \easyHeadsOn
    \clef "bass_8"
  }
  {
    \introNotes
    \verseNotes
  }
>>

As you can see, this way one can generate different versions of the 
score from the same variables, which is one of the main strengths of 
LilyPond.


For the construct

\new Voice = someName { ... }
\new Lyrics \lyricsTo someName { ... }

there is the shorthand

\new Voice { ... } \addlyrics { ... }

but in my experience this is only really helpful in the simplest of use 
cases, so I didn't use it here.


Lukas




Re: Trouble hiding NullVoice

2022-03-27 Thread Lukas-Fabian Moser

Hi Samanth(a),


I'm producing a bassline score, with chords, notes and lyrics.

As the bassline notes are ... sparse, I'm trying to use a NullVoice to 
hold the rhythm and aligning the lyrics to that (I gather this is an 
approach used by others)


Despite much googling/reading of docs/internals/snippets/etc I'm 
totally failing to prevent a staff appearing for the NullVoice.


I'm fairly new to Lilypond and am still trying to wrap my head around 
contexts/grobs/etc and would be grateful for any advice as to how to 
resolve this issue.


I've attached a cutdown .ly and the pdf it produces.


Don't worry, it'll all become clear soon enough. And you hit a 
comparatively subtle point: Since you're not creating a Staff context 
explicitly, you're relying on LilyPond to create staves automatically, 
and it seems a new Voice (or NullVoice) causes a new Staff to be created.


Replacing your

\score {
  {
...

by

\score {
  \new Staff {
...

already does the trick.

In general, I would not recommend adding multiple sections of 
simultaneous music << ... >> one after another to make up a piece. Most 
often, it's more convenient to construct a _complete_ bass music 
variable (which of course may be comprised of multiple sections defined 
independently), similarly for the other voices, and then combine them in 
a << ... >> expression.


So (pseudocode), I prefer

\score {
  <<
    \new Staff \firstInstrument
    \new Staff \secondInstrument
  >>
}

with

firstInstrument = {
  \firstInstrumentIntro
  \firstInstrumentVerse
}

etc.

Lukas