Re: Books with alternative lyrics minimizing code duplication?

2023-11-24 Thread David Wright
On Fri 24 Nov 2023 at 16:23:52 (+0200), YTG 123 wrote:
> 
> I have alternative versions of lyrics text, which I would like to
> export in different files (or \book blocks). The music, order of
> staves, etc. is identical.
> 
> Ideally, I would want to do this as cleanly and with as little code
> duplication as possible.

Perhaps an easy way to do this is as in the attached files.

Place all the lyrics for one version in one file (o-sing.ily),
using different variable names for all the different sections,
books etc in the piece. (I've just used the voice names for brevity.)

Now write a corresponding file (sing-ye.ily) with the alternative
lyrics, but using all the same corresponding variable names.

Merely include the appropriate lyrics filename in the master file
to produce the appropriate output file(s).

This method uses one simple modification of the master file to
change all the lyrics in all the output files (by removing the
%% in my master file example).

If even that amount of modification of source files is not possible,
then you can instead use the same filename for the two versions
of the lyrics, but place them in two different directories (and
also a different directory from the master file). Then select
which lyrics file is included in the run by using an appropriate
--include= in the LilyPond command line.

Cheers,
David.
sopranotext = \lyricmode {
  O sing joy -- ful -- ly,
}
altotext = \lyricmode {
  O sing joy -- ful -- ly,
}
tenortext = \lyricmode {
  O sing joy -- ful -- ly,
}
basstext = \lyricmode {
  O sing joy -- ful -- ly,
}
sopranotext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
altotext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
tenortext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
basstext = \lyricmode {
  Sing ye joy -- ful -- ly,
}
\language english
\include "o-sing.ily"
%%\include "sing-ye.ily"

global = {
  \key af \major
  \time 3/4
  s2. * 2
}
soprano = \relative {
  af'2 af4
  af4. af8 af4
}
alto = \relative {
  ef'2 ef4
  f4. f8 ef4
}
tenor = \relative {
  c'2 c4
  df4. df8 ef4
}
bass = \relative {
  af2 af4
  df,4. df8 c4
}

\book {
  \bookOutputSuffix "choir"
  \score {
\new ChoirStaff <<
  \new Staff <<
\clef treble \global
\new Voice { \soprano }
\addlyrics { \sopranotext }
  >>
  \new Staff <<
\clef treble \global
\new Voice { \alto }
\addlyrics { \altotext }
  >>
  \new Staff <<
\clef "treble_8" \global
\new Voice { \tenor }
\addlyrics { \tenortext }
  >>
  \new Staff <<
\clef bass \global
\new Voice { \bass }
\addlyrics { \basstext }
  >>
>>
\layout { }
  }
}

\book {
  \bookOutputSuffix "piano"
  \score {
\new PianoStaff <<
  \new Staff = up <<
\clef treble \global
\new Voice { \voiceOne \soprano }
\addlyrics \with { alignAboveContext = up } { \sopranotext }
\new Voice { \voiceTwo \alto }
  >>
  \new Staff <<
\clef bass \global
\new Voice { \voiceOne \tenor }
\new Voice { \voiceTwo \bass }
\addlyrics { \basstext }
  >>
>>
\layout { }
  }
}


Re: Books with alternative lyrics minimizing code duplication?

2023-11-24 Thread Michael Werner
Hi,

On Fri, Nov 24, 2023 at 9:25 AM YTG 123  wrote:

> Hello,
>
> I have alternative versions of lyrics text, which I would like to export
> in different files (or \book blocks). The music, order of staves, etc.
> is identical.
>
> Ideally, I would want to do this as cleanly and with as little code
> duplication as possible.
>

I do something a bit like this on a regular basis - generating multiple
versions from the same music. In my case, instead of doing different lyrics
I'm doing some instrument specific formatting and such. But the basic idea
is pretty similar. Perhaps something like this?

\version "2.25.10"

music = { c'4 d' e' }
lyricsOne = \lyricmode { do re mi }
lyricsTwo = \lyricmode { a b c }

% Header info common to all versions
main_header =
\header {
  title = "Main Title"
  composer = "Written by Foo Bar"
}

% Here is the main body of the score, so we can call it as needed
main_score = <<
  \new Staff {
\new Voice = "VOne" {
  \music
}
  }
  \tag #'(showLyricsOne) {
\new Lyrics  \lyricsto "VOne" {
  \lyricsOne
}
  }
  \tag #'(showLyricsTwo) {
\new Lyrics  \lyricsto "VOne" {
  \lyricsTwo
}
  }
>>

% With what I usually do everything from here down is in a separate file,
that includes in everything above

\book {
  \paper {
output-suffix = "both_lyrics"
  }
  \header {
pdftitle = "Song Title - Both Lyrics"
subtitle = "Both Lyrics"
  }
  \main_header
  \score {
\main_score
\layout {
  % As needed
}
  }
}

\book {
  \paper {
output-suffix = "first_lyrics"
  }
  \header {
pdftitle = "Song Title - First Lyrics"
subtitle = "First Lyrics"
  }
  \main_header
  \score {
\keepWithTag #'showLyricsOne
%\removeWithTag #'showLyricsTwo
\main_score
\layout {
  % As needed
}
  }
}

\book {
  \paper {
output-suffix = "second_lyrics"
  }
  \header {
pdftitle = "Song Title - Second Lyrics"
subtitle = "Second Lyrics"
  }
  \main_header
  \score {
\keepWithTag #'showLyricsTwo
%\removeWithTag #'showLyricsOne
\main_score
\layout {
  % As needed
}
  }
}

As a source file named example1.ly this produces 3 PDFs:
example1-both_lyrics.pdf, example1-first_lyrics.pdf and
example1-second_lyrics.pdf
http://lilypond.org/doc/v2.25/Documentation/notation/output-file-names
goes over how to control the output file names.

Using pdftitle in a \header block to set the displayed PDF title gets
covered in
http://lilypond.org/doc/v2.25/Documentation/notation/creating-output-file-metadata

In this example I'm using tags to control which lyrics get shown when.
There are 2 ways to use them: \keepWithTag and \removeWithTag  Details on
how they both get used are in
http://lilypond.org/doc/v2.25/Documentation/notation/using-tags
Short version: \keepWithTag keeps music with that tag and untagged music,
while \removeWithTag keeps everything but the music with the selected tag.
There's more to it than that - especially if you get into using multiple
tags at the same time. But this example is simple enough that it could work
either way - swap the two commented tag commands in each score to try it
out, and you'll see that the output is the same.
-- 
Michael


Books with alternative lyrics minimizing code duplication?

2023-11-24 Thread YTG 123

Hello,

I have alternative versions of lyrics text, which I would like to export 
in different files (or \book blocks). The music, order of staves, etc. 
is identical.


Ideally, I would want to do this as cleanly and with as little code 
duplication as possible.


%%%

music = { c'4 d' e' }
lyricsOne = \lyricmode { do re mi }
lyricsTwo = \lyricmode { a b c }

%% Somehow, store the structure of the score in a variable and 
substitute lyrics later?
%% This is not so bad, but the actual use case has more staves, 
properties in \with, etc.
%% and the file has managed to get than 1,000 lines long (with the 
actual notes and

%% lyrics being in different files; just the \books).

\book {
    \new Staff << \music \addlyrics \lyricsOne \addlyrics \lyricsTwo >>
}

\book {
    \new Staff << \music \addlyrics \lyricsOne >>
}

\book {
    \new Staff << \music \addlyrics \lyricsTwo >>
}

%%%

Thank you.