What's this? Searching the LSR Browse by date Contributing Snippet database | Browsing items 852−939 out of 940 |
In 20th century music, where time signatures tend to change a lot, it is
sometimes recommended to put the time signatures on top of the score (or above
each StaffGroup
in the case of an orchestral score). This can be achieved by
creating a dummy staff which only contains the Time_signature_engraver
.
In this specific example, a separate identifier is used to define every time signature change, which saves the bother of entering them again when typing the actual music (careful though: it makes getting lost easier!).
Notice the overriding of the X-offset
property: a specific trick to make the
time signatures align with the barlines, thanks to Han-Wen.
\include "tune1.ly"
\include "tune2.ly"
In your piece-files you might have \tocItem
commands to build the table of contents.
If you replace those \tocItem
commands with the newly defined \part
command, you can use
#(set-toc-section! "section")
in the master file:
#(set-toc-section! "tunes")
\include "tune1.ly"
\include "tune2.ly"
#(set-toc-section! "parts")
\include "part1.ly"
\include "part2.ly"
Now every section is introduced with a section line in the table of contents only if the section title was set before. If you reorder the parts (includes), the sections will still appear in the right place.
This is meant for compiling a collection of pieces, which also compile themselves.
For a complete opus with pieces Please see snippet 368
To change an input file written in a foreign language to your favorite language use \include "…language….ly"
and \displayLilyMusic { \melody }
.
The translation is by default written to the log; you can redirect this output to a file of your choice using the command lilypond.exe >yourfile.ly
(with windows).
The result of the snippet will be in absolute pitch:
{ c8 d e f g a b c | cflat dflat eflat fflat gflat aflat bflat cflat | csharp dsharp esharp fsharp gsharp aflat bsharp csharp | \bar "|." }
Music engraving by LilyPond 2.1x.xx—www.lilypond.org, that is automatically added to your scores.
Not only can you fully remove it, by setting the tagline variable to f
(just add tagline = ##f
in your header block), but you are also welcome to translate it (and the LilyPond authors invite you to do so if you want to promote this great software) or customize it the way you like it!
In this snippet, we have taken the original tagline definition in the titling-init.ly file, and therefore we can tweak it the way we want. The right version number will automatically be added.
Double accidentals should be removed
B sharp -> C
E sharp -> F
C flat -> B
F flat -> E
In this manner, the most natural enharmonic notes are chosen.
Changing the clef glyph, its position, or the ottavation does not
change the position of subsequent notes on the staff. To get key
signatures on their correct staff lines, middleCClefPosition
must also be specified, with positive or negative values moving
middle C up or down respectively, relative to the staff's
center line.
For example, \clef "treble_8"
is equivalent to setting
the clefGlyph
, clefPosition
(the vertical position
of the clef itself on the staff), middleCPosition
, and
clefTransposition
. Note that when any of these properties
(except middleCPosition
) are changed a new clef symbol is
printed.
The following examples show the possibilities when setting these properties manually. On the first line, the manual changes preserve the standard relative positioning of clefs and notes, whereas on the second line, they do not.
\partCombine
function takes two music expressions each containing a part, and distributes them among four Voice
s named two,
one,
solo, and
chordsdepending on when and how the parts are merged into a common voice. The voices output from
\partCombine
can have their layout properties adjusted in the usual way. Here we define extensions of \partCombine
to make it easier to put four voices on a staff.
soprano = { d'4 | cis' b e' d'8 cis' | cis'2 b } alto = { fis4 | e8 fis gis ais b4 b | b ais fis2 } tenor = { a8 b | cis' dis' e'4 b8 cis' d'4 | gis cis' dis'2 } bass = { fis8 gis | a4 gis g fis | eis fis b,2 } \new Staff << \key b\minor \clef alto \partial 4 \transpose b b' \partCombineUp \soprano \alto \partCombineDown \tenor \bass >>
voices, without making the score look like a multi-stave polyphonic score.
The purpose of the \elseTag command is to make the use of tagged music easier.
This exemple shows the same music, without and with \elseTag.
In the old manner (first exemple), you have to write all the tag names you want,and to omit only the one you don't want.
In the second exemple, \elseTag exclude automatically the tag you don't want, and keep all the others.
\elseTag has the same syntaxe than \tag and has to be use in conjonction with \keepWithTag.
Sometimes, an author may want to display rests not with their usual symbols, but e.g. use a circle instead of a quarter rest and a circle with a rectangle below for eighth rests.
This snippet provides a Scheme function for the Rest's #'stencil property, which creates circles instead of the usual rest symbols for quarter and eighth rests, but uses the standard symbols for all other rests. This is done by checking the duration-log property of the rest object and provide a custom stencil for log values of 2 and 3 (because 1/4 = 2-2 and 1/8 = 2-3). For all other values, the built-in rest formatter function is called.
To enable this style only for some parts of a score, don't set the stencil globally, but call the \override somewhere inside the score and \revert it after the section with the custom style:
\relative c' { e4. r8 e4 r4 \override Rest #'stencil = #ly:rest-interface::dot-rests e4. r8 e4 r4 \revert Rest #'stencil e4. r8 e4 r4 }
To enable this style globally, simply override the #'stencil property of the Rest object in a layout block:
\layout { \context { \Voice \override Rest #'stencil = #ly:rest-interface::dot-rests } }
Often it is easier to manage line and page-breaking information by
keeping it separate from the music by introducing an extra voice
containing only skips along with the \break
,
pageBreak
and other layout information.
This pattern becomes especially helpful when overriding
line-break-system-details
and the other useful but long
properties of NonMusicalPaperColumnGrob
.
Lyric hyphens have several user-modifiable properties such as length and thickness; this doesn’t allow, however, for further tweaking, for example, rendering hyphens as rounded boxes to better match the font possibly used for LyricText
, or even printing hyphens as actual glyphs rather than drawing basic boxes.
This snippet rewrites the LyricHyphen
stencil procedure to use a proper glyph… or indeed any arbitrary markup.
Some grobs can be accessed “laterally” from within another grob’s callback. These are usually listed as “layout objects” in the “Internal properties” section of a grob-interface. The function ly:grob-object is used to access these grobs.
Demonstrated below are some ways of accessing grobs from within a NoteHead callback, but the technique is not limited to NoteHeads. However, the NoteHead callback is particularly important, since it is the implicit callback used by the \tweak
command.
The example function defined below ("display-grobs") is probably not that useful, but it demonstrates that the grobs are indeed being accessed.
Example console output:
#
()
#
\verse
markup command to include \lyricmode
text. You can decide to use a linebreak character or wrap lines in the marked places.
words = \lyricmode { Du lil -- le \markup \italic fis -- \markup \italic ker \nl Du \markup \italic lil -- \markup \italic le fis -- ker } \markup { \override #'(line-width . 40) % set the line width \override #'(display-nl . #t) % show a newline character or break lines (default) \override #`(make-line . ,make-wordwrap-markup) % use word-wrapped and left aligned % or justified (default) lines/paragraphs \verse #words }
If you want to create a custom shape or symbol, you can use the make-connected-path-stencil
scheme function. This function takes the following six arguments, and returns a stencil
.
1. A list of lists defining the coordinates of the path. The path automatically starts at the origin point of (0 0). To draw a straight line to the next point, simply indicate the X and Y coordinates of the next point like this: (1 -3)
To draw a cubic Bézier curve to the next point, enter a list of six numbers like this: (-6 -2 -6 7 0 5)
The first two numbers are the X and Y coordinates of the first control point. The middle two are the X and Y coordinates of the second control point. The last two are the X and Y coordinates of the destination point.
2. A number indicating the thickness of the line.
3. A number that scales the stencil on the X-axis.
4. A number that scales the stencil on the Y-axis.
5. A boolean (#t / #f) indicating whether the path automatically connects back to the origin point (0 0).
6. A boolean (#t / #f) indicating whether the shape created by the path is to be filled.
This snippet demonstrates using stencils
as an override for other stencils
, and also how they can be used in \markup
. The snippet also shows how to use ly:stencil-translate
to shift the position of the stencil. This is sometimes needed since the origin point of the path is "hard-coded" to always be (0 0).
Using make-connected-path-stencil
has several advantages compared with using ly:make-stencil
and path
(as shown here: http://lsr.di.unimi.it/LSR/Item?id=623). One is that you do not have to manually specify the width and height of the stencil, since it gets calculated automatically.
MarkLine
contexts (such as in
LSR1010) in a
Frenched score can be problematic if all the staves between two
MarkLine
s are removed in one system. The
Keep_alive_together_engraver
can be used within each
StaffGroup
to keep the MarkLine
alive only as long
as the other staves in the group stay alive.
LilyPond supports a number of pre-defined clefs, all of which show the clef symbol on some staff line. If you need the clef symbol between two lines, say, you can either manually set Staff.clefGlyph
, Staff.clefPosition
, and Staff.middleCPosition
to the appropriate values, or you can add your own clef definition so that you can use \clef myCustomClef
, for example. This can be achieved by using the add-new-clef
function which has the form:
(add-new-clef "myCustomClef" "clefs.GLYPH" clef-position octavation c0-position)
The parameters are as follows.
"myCustomClef"
is the name of the new clef.
"clefs.GLYPH"
describes the actual clef glyph (e.g., "clefs.g" for the treble clef, "clefs.neomensural.c" for the neomensural c glyph, etc.).
clef-position
determines the position of the clef, counted from the center line of the staff. For example, a value of 1 means the clef is shown between the center line and the line above, 4 means the clef is shown on the top line, -2 means it is shown on the second line of the staff.
octavation
describes the octave transposition, which is typically 0.
c0-position
determines the position of middle C on the staff relative to clef-position
. For example, a value of -2 means middle C will be two staff positions (lines or spaces) below clef-position
.
The stencil expression path
can be used to override stencils for any printed object. The advantage of using path
instead of embedded-ps
is that path
is supported by both the PostScript and SVG backends, and uses the same syntax.
There are six commands available to use in a path
expression, and all commands use prefix notation. The six commands are moveto, rmoveto, lineto, rlineto, curveto,
and rcurveto
. Note that the commands that begin with r are the relative variants of the other three commands.
The commands moveto, rmoveto, lineto,
and rlineto
take 2 arguments; they are the X and Y coordinates for the destination point.
The commands curveto
and rcurveto
create cubic Bézier curves, and take 6 arguments; the first two are the X and Y coordinates for the first control point, the second two are the X and Y coordinates for the second control point, and the last two are the X and Y coordinates for the destination point.
In addition this snippet shows how to create a filled stencil using path,
and adds a scheme function to automatically resize custom stencils when individual staves are resized.
scm/midi.scm
. Using scheme, one can easily create a lilypond file displaying all supported midi names automatically.Using tags, it is possible to produce both mensural and modern
notation from the same music. In this snippet, a function
\menrest
is introduced, allowing mensural rests to be pitched as
in the original, but with modern rests in the standard staff position.
Tags can also be used where other differences are needed: for example
using whole measure rests
(R1
, R\breve
, etc.) in
modern music, but normal rests (r1
, r\breve
, etc.) in
the mensural version. Converting mensural music to its modern
equivalent is usually referred to as transcription.
high bass cleflooks exactly the same as the standard bass clef, but the music has to be played one octave up (compared with the treble clef). So it's equivalent to a "bass^8" clef where the octavation eight above the clef is removed.
basset hornand the
bass clarinet, too.
high bass clef.
Here's an example using Scheme code and the input-tag
property to provide a way to mark up music in the manner similar to the "outlining" rehearsal technique recommended by James Boyk and Abigail
Whiteside.
The basic idea of outlining is to practice passages at tempo from the very start by omitting most of the notes and gradually add more and more of the notes. It's a good rehearsal technique, but it takes some time to get used to. Hence the thought that a convenient way to visually and aurally demonstrate the technique might be useful.
This snippet defines a music function, \oLevel, that can be nested around sequences of notes to indicate an outline level. Once the music has been marked up with the \oLevel function, it can be rendered at any desired level of outlining by calling \outlineMusic in the score block with a numerical value to indicate the desired level of detail. It's somewhat similar to the way programmers often provide a "debug-level" command-line option. The higher the level, the more detail in the output.
As implemented here, the notes that are beyond the desired level of detail are replaced by repeats of prior notes and are shown with grey noteheads. See the attached image and example .ly file for more detail. Other implementations are certainly possible, e.g. replacing the notes with rests instead of showing them as repeated notes in grey.
From a programming standpoint, the input-tag
property seems like a
nice tool anytime you need to encode some information in the notation
for later use when the output is rendered in a way that can't be
handled by the \keepWithTag and \removeWithTag functions. There's one pitfall that took me a while to figure out -- ly:music-deep-copy
does NOT copy the contents of input-tag
even though it's a documented
property. You need to provide some logic to handle that if you are
generating multiple versions of the music and need to alter tags in
the process of doing so.
Any graphical object can be printed over a white background to
mask parts of objects that lie beneath. This can be useful to
improve the appearance of collisions in complex situations when
repositioning objects is impractical. It is necessary to explicitly
set the layer
property to control which objects are masked
by the white background.
In this example the collision of the tie with the time signature is
improved by masking out the part of the tie that crosses the time
signature, setting the whiteout
property of TimeSignature
.
To do this, TimeSignature
is moved to a layer above Tie
, which
is left in the default layer 1, and StaffSymbol
is moved to a
layer above TimeSignature
so it is not masked.
tieWaitForNote
property to #t
. The
same
feature is also useful, for example, to tie a tremolo to a
chord,
but in principle, it can also be used for ordinary
consecutive
notes.
'thickness
property of slurs variable depending on its length.variable-bow-thickness
which requires four values, two for min and max bow length (min-l
and max-l
, respectively) and two for min and max bow thickness (min-t
and max-t
, respectively). The final thickness is determined by the following conditions:min-l
, then thickness = min-t
max-l
, then thickness = max-t
min-l
≤ Length ≤ max-l
, then thickness = linearly interpolated between min-t
and max-t
Right now, LilyPond's abilities to format footnote text strings are quite limited: each footnote on a page is processed and emitted separately, with some whitespace (footnote-padding
) inbetween. footnote-padding
is also inserted between the footnote separator markup and the first footnote. A consequence of this very simplistic output model (i.e., using padding and not baseline-to-baseline distances) is uneven vertical spacing if some footnote text doesn't contain both ascenders (like letter ‘d’) and descenders (like letter ‘p’).
This snippet fixes the vertical spacing of footnotes. It defines a new command \Footnote
that accepts either a markup (for single-line footnotes) or a markup list (for multi-line footnotes). The baseline-to-baseline distance of the lines in multi-line footnotes is controlled by the top-level baseline skip in the paper variable text-font-defaults.baseline-skip
.
All DynamicLineSpanner
objects (hairpins and dynamic texts) are
placed with their reference line at least 'staff-padding
from
the staff, unless other notation forces them to be farther.
Setting 'staff-padding
to a sufficiently large value aligns the
dynamics.
The same idea, together with \textLengthOn
, is used to align the text scripts along their baseline.
Hymntemplate, the four voices are regrouped on only two staves.
Vocal ensemble template. This demonstrates one of the strengths of LilyPond – you can use a music definition more than once. If any changes are made to the vocal notes (say,
tenorMusic
), then the changes will also apply to the piano reduction.
Though volte are best specified using
\repeat volta
, the context property repeatCommands
must be used in cases where the volta text needs more advanced
formatting with \markup
.
Since repeatCommands
takes a list, the simplest method of
including markup is to use an identifier for the text and embed
it in the command list using the Scheme syntax
#(list (list 'volta textIdentifier))
. Start- and
end-repeat commands can be added as separate list elements: