How to create a function to automate header creation? - lilypond

I have a few transcription to do, using lilypond.
It consists of a few songs, all of the same composer/poet, but there might be more to come.
I already have a few helper functions in a that I include in each score, but I'd like to have a function to automate header creation, something I could call like this:
\mkheader "my song"
or something similar.
This would avoid the need to write
\header {
composer = "the composer of all the songs"
title = "my song"
}
in each song.
Since two days ago, I've been (re-)reading the lilypond documentation, but I can't get it to work. Any ideas?

You are likely needing Include files.
Directory structure:
.
├── my_include.ly
├── my_main.ly
my_include.ly
\header {
composer = "the composer of all the songs"
title = "my song"
}
my_main.ly
\version "2.20.0"
\include "my_include.ly"
melody = \relative c {
\key c \major
\time 4/4
c c c c |
}
\score {
<<
\new Staff { \melody }
>>
}
It might be that you want to add extra information later in your main lilypond file, in which case you just add another header block
my_main.ly
\version "2.20.0"
\include "./my_include.ly"
\header {
subtitle = "my_subtitle"
subsubtitle = "my_subsubtitle"
}
melody = \relative c'' {
\key c \major
\time 4/4
c c c c |
}
\score {
<<
\new Staff { \melody }
>>
}

Related

Lilypond: Produce MIDI and PDF output simultaneously

When I am evoking lilypond in order to produce midi output, I comment in an empty midi block in the score block. Then, lilypond produces a midifile instead of a PDF file. I want to create both outputs simultaneously to be able to listen to the changes and see the changes in the pdf file. Is this possible? Commenting the midi block in and out becomes a bit cumbersome after a while, and an option to produce both outputs at the same time would help me a lot!
This is an example ly file to demonstrate my workflow:
\score {
\midi {} % Commented out each time I want to produce PDF
\new PianoStaff <<
\new Staff {
\key f \minor
\mp
\relative c''' {
c
}
}
\new Staff {
\relative c {
c
}
}
>>
}
As Ole V.V suggested in his comment, it is possible to create both outputs simultaneously by adding a layout block in the score block as follows:
\score {
\midi {} % Commented out each time I want to produce PDF
\layout{} % Adding this does the trick, thanks to Ole V.V's comment
\new PianoStaff <<
\new Staff {
\key f \minor
\mp
\relative c''' {
c
}
}
\new Staff {
\relative c {
c
}
}
>>
}

Lilypond : Adding lyrics into backslash temporary voices

I'm pretty new when it comes to details on Lilypond and I'm stuck on a problem.
Whenever I introduce two new temporary voices with backslash <<{ }\\\\{ }>>, the lyrics skip over those voices :
Lyrics = \lyricmode {Et lux per -- pe -- tu -- a }
\score {
\new ChoirStaff
<<
\new Voice = "soprano"
\relative c' {
\clef treble
c4 f8 f
<<{a a}\\{f f}>>
c'4
}
\new Lyrics \lyricsto "soprano" { \Lyrics }
>>
}
Here is the document: http://lilybin.com/xbi9lm/1
I've tried a lot of things, and one that does something interesting is this:
Lyrics = \lyricmode {Et lux per a }
LyricsTwo = \lyricmode {pe -- tu }
\score {
\new ChoirStaff
<<
\new Voice = "soprano"
\relative c' {
\clef treble
c4 f8 f
<<{a a}\\{f f}\new Lyrics \lyricsto "2" {\LyricsTwo}>>
c'4
}
\new Lyrics \lyricsto "soprano" { \Lyrics }
\new Voice = "alto"
\relative c' {
\clef treble
c1
}
>>
}
Here is the document : http://lilybin.com/xbi9lm/2
Using backslashes for temporary voices creates two voices named "1" and "2" so that's what I've tried, but somehow the lyrics get under the entire score ?
I use them a lot but for very short amount of notes/time.
I'm at a complete loss so if someone has a good solution for integrating lyrics into temporary multiple backslash voices, I'm all ears !
While for keyboard music I also use the << { … } \\ { … } >> notation a lot, for music with lyrics I prefer to give Lilypond one voice onto which to hang the lyrics. I leave out \\, and Lilypond will regard the inside of << … >> as belonging to the same voice. We want only one of the two to belong, so we explicitly declare a different voice for the other.
Lyrics = \lyricmode { Et lux per -- pe -- tu -- a }
\score {
\new ChoirStaff <<
\new Voice = "soprano" \relative c' {
\clef treble
c4 f8 f
<<
{ \voiceOne a a }
\new Voice { \voiceTwo f f }
>>
\oneVoice c'4
}
\new Lyrics \lyricsto "soprano" { \Lyrics }
\new Voice = "alto"
\relative c' {
\clef treble
c1
}
>>
}
Output:
The \voiceOne, \voiceTwo and \oneVoice macros I call are what your double-backslash notation also calls behind the scenes to get the voices look like voice 1 and 2 (mainly the stem directions). I trust you to fix the beaming.

Lilypond: Adjacent analysis brackets

I need several analysis bracket combinations which are rather unusual (at least I didn't find a lot help in the net). First of all I wanted overlapping analysis brackets, which I managed to achieve already. Now, what I also need is "adjacent brackets", meaning that one bracket ends on a note while on the same note another one starts. So in theory I would need this: "g4\stopGroup\startGroup". However, this results in simply one big bracket. Here is my example code, which currently has the problem that the g4 is in both voices and therefore visible twice, while it should only be there once, but both brackets should include it.
\version "2.19.61"
adjtwo = \relative c'' {
s2 g4\startGroup a b c\stopGroup d e
}
adjone = \relative c' {
\once \override HorizontalBracket #'direction = #UP
e\startGroup f g\stopGroup
}
\score {
\new Staff {
<<
\voiceOne \adjone
\voiceThree \adjtwo
>>
}
}
\layout {
\context {
\Voice
\consists "Horizontal_bracket_engraver"
}
}
Thanks for any help
Best regards
Is this what you're looking for?
\version "2.19.61"
\score {
\relative {
\override HorizontalBracket #'direction = #UP
e'\startGroup f g\stopGroup <>\startGroup a
b c\stopGroup d e
}
}
\layout {
\context {
\Voice
\consists "Horizontal_bracket_engraver"
}
}
A work around to make this, is the following:
put \starGroup and \stopGroup where you need. The unique condition is that you can not put a \stopGroup following a \startGroup. You have to put at least 1 note among their. You can put the \stopGroup after the following note, don't worry
fix the position and length of the bracket that are wrong drawn with \once \override HorizontalBracket.shorten-pair = #'(-3.0 . 1.5).
For your example, you can do the following:
adjone = \relative c' {
\once \override HorizontalBracket #'direction = #UP
e \startGroup f g \stopGroup
\once \override HorizontalBracket.shorten-pair = #'(-3.0 . 1.5)
a \startGroup b c \stopGroup d e
}
\score {
\new Staff {
<<
\voiceOne \adjone
>>
}
}
\layout {
\context {
\Voice
\consists "Horizontal_bracket_engraver"
}
}
And you get this score:
(I can not put images embed yet) Here is the link of the image: https://imgur.com/a/H1gN0wE

How can I include ossia without creating a blank space?

I am trying to add an ossia staff above the upper staff of a grand
staff. Working from this mailing list post, I have
constructed a minimal example that almost does what I want. The
problem is that the entire score contains a blank space for the ossia
staff, even in systems that have no ossia.
Here is the example (truly, a melodious composition):
\version "2.18.2"
ossia = \new Staff = "ossia" \with {
\remove "Time_signature_engraver"
fontSize = #-2
\override StaffSymbol #'staff-space = #(magstep -2)
\override Clef #'transparent = ##t
\override KeySignature #'stencil = ##f
} {
\key b \major
\override Staff.BarLine #'allow-span-bar = ##f
\stopStaff
s2.*100 % ???
}
treble = \new Staff = "treble" {
\clef treble
\key b \major
\relative c' {
\repeat unfold 10 { b8 cis dis fis dis cis }
b4 dis fis |
b4
<<
{ dis, fis }
\context Staff = "ossia" {
\startStaff \tuplet 3/2 { dis8 b dis } fis4 \stopStaff
}
>> |
b2. |
}
}
bass = \new Staff = "bass" {
\clef bass
\key b \major
\relative c {
\repeat unfold 12 { fis,4 fis4 fis4 | }
b2.
}
}
pianoStaff = \new PianoStaff {
\compressFullBarRests
\time 3/4
<<
\ossia
\treble
\bass
>>
}
\paper {
#(set-paper-size "letter")
indent = 25\mm
short-indent = 5\mm
}
\score {
<< \pianoStaff >>
% This changes nothing:
% \layout { \context { \Staff \RemoveEmptyStaves } }
}
Here is the output (PNG image, 85 KB).
Some interesting things to note:
If I remove the s2.*100 at line 13 (marked % ???), or change the
value to anything smaller than 12, the ossia staff renders
completely incorrectly. It appears below the bass clef, includes the
clef and time signature, and is in the key of C (i.e., the rendered
notes include accidentals). Basically, it looks like it's failed to
notice that the ossia staff exists and has constructed a brand new
one. I suspect that this is because the ossia staff is supposed to
extend past each point where it is used—i.e., when switching staff
contexts, one can go "back in time" but not forward. I don't really
understand this, but I can live with it, as it doesn't seem to have
an intrinsic effect as long as \compressFullBarRests is enabled.
I have included the paper size in the MWE to force consistent
dimensions on different systems.
As I noted in the score, adding \RemoveEmptyStaves does not remove
the empty staves.
My question is: how can I keep the ossia staff rendered as it does in
this example (small and above the treble clef) without adding the
empty space on all previous systems?
\RemoveEmptyStaves is not working because the staves are within a PianoStaff, so you must add \remove "Keep_alive_together_engraver" to the \layout block. Here's a minimal example of a documentation snippet slightly modified:
\version "2.18.2"
\new PianoStaff
<<
\new Staff = "ossia" \with {
\remove "Time_signature_engraver"
\hide Clef
fontSize = #-3
\override StaffSymbol.staff-space = #(magstep -3)
\override StaffSymbol.thickness = #(magstep -3)
} \relative c'' {
R1*3
c4 e8 d c2
}
\new Staff \relative c' {
c4 b c2
e4 f e2
g4 a g2 \break
c4 b c2
g4 a g2
e4 d c2
}
>>
\layout {
\context {
\Staff \RemoveEmptyStaves
\override VerticalAxisGroup.remove-first = ##t
}
\context {
\PianoStaff
\remove "Keep_alive_together_engraver"
}
}
Your example is quite big, not a real MWE. s2.*100 doesn't make any sense to me. I suggest that you submit a smaller example.

How do I limit the Staff.NoteHead overrides?

I often have a string of harmonics, so I decided to use a music function (the function is a tangent; if I place the override directly with the notes I get the same problem. The issue is the override itself):
harmonics =
#(define-music-function
(parser location notes)
(ly:music?)
#{
%\harmonicsOn
\override Staff.NoteHead #'style = #'harmonic-mixed
$notes
\revert Staff.NoteHead #'style
%\harmonicsOff
#}
)
\harmonicsOn and \harmonicsOff works, but they're always hollow notes so I don't want to use them. Overriding the notehead allows me to have solid heads on quarter notes.
My problem is that the note heads are overridden for all notes in the duration, not only the notes supplied to the function (see m. 2, 3 in the image below the following code):
melody = \relative c' { \stemUp
\repeat unfold 4 { r8 b g b e' b, | }
\bar "|."
}
harmony = \relative c' { \stemDown
e,2. |
\harmonics { e } |
\harmonics { e4 e } s |
e2. |
}
\score {
\new Staff {
\time 3/4 \clef "treble_8"
\key g \major
<<
\new Voice { \melody} \new Voice { \harmony}
>>
}
}
I'm looking for a way to modify only the notes I want (in this case, in \harmony), leaving the other notes within that duration untouched.
Edit: I tried with lilypond 2.17 using the new \temporary command, but I get the same result.
Full code | NoteHead Internals Documentation
Your problem is that your function uses the \override command, which affects all simultaneous grobs in a given context, and thus it is changing all noteheads in the Staff context (which contains both melody and harmony music). If you change the noteheads only in the Voice context, then your problem is solved:
harmonics =
#(define-music-function
(parser location notes)
(ly:music?)
#{
%\harmonicsOn
\override Voice.NoteHead #'style = #'harmonic-mixed
$notes
\revert Voice.NoteHead #'style
%\harmonicsOff
#}
)