| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 4.6.1 Other uses for tweaks | ||
| 4.6.2 Using variables for tweaks | ||
| 4.6.3 Style sheets | ||
| 4.6.4 Other sources of information | ||
| 4.6.5 Advanced tweaks with Scheme |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| Tying notes across voices | ||
| Simulating a fermata in MIDI |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following example demonstrates how to connect notes in different voices using ties. Normally, only two notes in the same voice can be connected with ties. By using two voices, with the tied notes in one of them
and blanking the first up-stem in that voice, the tie appears to cross voices:
<< { \tweak Stem.transparent ##t b8~ 8\noBeam } \\ { b8[ g] } >>
To make sure that the just-blanked stem doesn’t squeeze the tie
too much, we can lengthen the stem by setting the
length to 8,
<< { \tweak Stem.transparent ##t \tweak Stem.length #8 b8~ 8\noBeam } \\ { b8[ g] } >>
Now for overriding the transparency of a graphical object,
we could have used the shorthand \hide as explained above.
Tweaking is a different operation, affecting only properties
generated from a single music expression. It turns out that we
can convert overrides into tweaks using \single, making it
possible to rewrite the above example as
<< { \single \hide Stem \single \hide Flag \tweak Stem.length #8 b8~ 8\noBeam } \\ { b8[ g] } >>
In this particular case, the difference to \once \hide is
not apparent. It is important when there are several objects at
the same point in musical time (like noteheads in a chord). In
that case, \once will affect all of those objects while
\single will only affect a single one, the one generated by
the immediately following music expression.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For outside-staff objects it is usually better to override the
object’s stencil property rather than its transparent
property when you wish to remove it from the printed output.
Setting the stencil property of an object to #f will
remove that object entirely from the printed output. This means it
has no effect on the placement of other objects placed relative to
it.
For example, if we wished to change the metronome setting in order
to simulate a fermata in the MIDI output we would not want the
metronome markings to appear in the printed output, and we would
not want it to influence the spacing between the two systems or
the positions of adjacent annotations on the staff. So setting
its stencil property to #f would be the best way.
We show here the effect of the two methods:
\score { \relative { % Visible tempo marking \tempo 4=120 a'4 a a \once \hide Score.MetronomeMark % Invisible tempo marking to lengthen fermata in MIDI \tempo 4=80 a4\fermata | % New tempo for next section \tempo 4=100 a4 a a a | } \layout { } \midi { } }
\score { \relative { % Visible tempo marking \tempo 4=120 a'4 a a \once \omit Score.MetronomeMark % Invisible tempo marking to lengthen fermata in MIDI \tempo 4=80 a4\fermata | % New tempo for next section \tempo 4=100 a4 a a a | } \layout { } \midi { } }
Both methods remove the metronome mark which lengthens the fermata from the printed output, and both affect the MIDI timing as required, but the transparent metronome mark in the first line forces the following tempo indication too high while the second (with the stencil removed) does not.
Music Glossary: (music-glossary)system section ‘system’ in Terminologie.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Override commands are often long and tedious to type, and they have to be absolutely correct. If the same overrides are to be used many times it may be worth defining variables to hold them.
Suppose we wish to emphasize certain words in lyrics by printing
them in bold italics. The \italic and \bold
commands only work within lyrics if they are embedded, together with
the word or words to be modified, within a \markup block,
which makes them tedious to enter. The need to embed the words
themselves prevents their use in simple variables. As an
alternative can we use \override and \revert commands?
\override Lyrics.LyricText.font-shape = #'italic \override Lyrics.LyricText.font-series = #'bold \revert Lyrics.LyricText.font-shape \revert Lyrics.LyricText.font-series |
These would also be extremely tedious to enter if there were many
words requiring emphasis. But we can define these as two
variables and use those to bracket the words to be emphasized.
Another advantage of using variables for these overrides is that
the spaces around the dot are not necessary, since they are not
being interpreted in \lyricmode directly. Here’s an example
of this, although in practice we would choose shorter names
for the variables to make them quicker to type:
emphasize = { \override Lyrics.LyricText.font-shape = #'italic \override Lyrics.LyricText.font-series = #'bold } normal = { \revert Lyrics.LyricText.font-shape \revert Lyrics.LyricText.font-series } global = { \key c \major \time 4/4 \partial 4 } SopranoMusic = \relative { c'4 | e4. e8 g4 g | a4 a g } AltoMusic = \relative { c'4 | c4. c8 e4 e | f4 f e } TenorMusic = \relative { e4 | g4. g8 c4. b8 | a8 b c d e4 } BassMusic = \relative { c4 | c4. c8 c4 c | f8 g a b c4 } VerseOne = \lyricmode { E -- | ter -- nal \emphasize Fa -- ther, | \normal strong to save, } VerseTwo = \lyricmode { O | \once \emphasize Christ, whose voice the | wa -- ters heard, } VerseThree = \lyricmode { O | \emphasize Ho -- ly Spi -- rit, | \normal who didst brood } VerseFour = \lyricmode { O | \emphasize Tri -- ni -- ty \normal of | love and pow'r } \score { \new ChoirStaff << \new Staff << \clef "treble" \new Voice = "Soprano" { \voiceOne \global \SopranoMusic } \new Voice = "Alto" { \voiceTwo \AltoMusic } \new Lyrics \lyricsto "Soprano" { \VerseOne } \new Lyrics \lyricsto "Soprano" { \VerseTwo } \new Lyrics \lyricsto "Soprano" { \VerseThree } \new Lyrics \lyricsto "Soprano" { \VerseFour } >> \new Staff << \clef "bass" \new Voice = "Tenor" { \voiceOne \TenorMusic } \new Voice = "Bass" { \voiceTwo \BassMusic } >> >> }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The output that LilyPond produces can be heavily modified; see Tweaking output, for details. But what if you have many input files that you want to apply your tweaks to? Or what if you simply want to separate your tweaks from the actual music? This is quite easy to do.
Let’s look at an example. Don’t worry if you don’t understand
the parts with all the #(). This is explained in
Advanced tweaks with Scheme.
mpdolce = #(make-dynamic-script #{ \markup { \hspace #0 \translate #'(5 . 0) \line { \dynamic "mp" \text \italic "dolce" } } #}) inst = #(define-music-function (string) (string?) #{ <>^\markup \bold \box #string #}) \relative { \tempo 4=50 a'4.\mpdolce d8 cis4--\glissando a | b4 bes a2 | \inst "Clarinet" cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2 | }
Let’s do something about the mpdolce and inst definitions.
They produce the output we desire, but we might want to use them in
another piece. We could simply copy-and-paste them at the top of every
file, but that’s an annoyance. It also leaves those definitions in our
input files, and I personally find all the #() somewhat ugly.
Let’s hide them in another file:
%%% save this to a file called "definitions.ily"
mpdolce =
#(make-dynamic-script
#{ \markup { \hspace #0
\translate #'(5 . 0)
\line { \dynamic "mp"
\text \italic "dolce" } }
#})
inst =
#(define-music-function
(string)
(string?)
#{ <>^\markup \bold \box #string #})
|
We will refer to this file using the \include command near
the top of the music file. (The extension ‘.ily’ is used to
distinguish this included file, which is not meant to be compiled
on its own, from the main file.)
Now let’s modify our music (let’s save this file as ‘music.ly’).
\include "definitions.ily"
\relative {
\tempo 4=50
a'4.\mpdolce d8 cis4--\glissando a |
b4 bes a2 |
\inst "Clarinet"
cis4.\< d8 e4 fis |
g8(\! fis)-. e( d)-. cis2 |
}
|
That looks better, but let’s make a few changes. The glissando is hard to see, so let’s make it thicker and closer to the note heads. Let’s put the metronome marking above the clef, instead of over the first note. And finally, my composition professor hates ‘C’ time signatures, so we’d better make that ‘4/4’ instead.
Don’t change ‘music.ly’, though. Replace our ‘definitions.ily’ with this:
%%% definitions.ily
mpdolce =
#(make-dynamic-script
#{ \markup { \hspace #0
\translate #'(5 . 0)
\line { \dynamic "mp"
\text \italic "dolce" } }
#})
inst =
#(define-music-function
(string)
(string?)
#{ <>^\markup \bold \box #string #})
\layout{
\context {
\Score
\override MetronomeMark.extra-offset = #'(-9 . 0)
\override MetronomeMark.padding = #'3
}
\context {
\Staff
\override TimeSignature.style = #'numbered
}
\context {
\Voice
\override Glissando.thickness = #3
\override Glissando.gap = #0.1
}
}
|
That looks nicer! But now suppose that I want to publish this piece. My composition professor doesn’t like ‘C’ time signatures, but I’m somewhat fond of them. Let’s copy the current ‘definitions.ily’ to ‘web-publish.ily’ and modify that. Since this music is aimed at producing a pdf which will be displayed on the screen, we’ll also increase the overall size of the output.
%%% web-publish.ily
mpdolce =
#(make-dynamic-script
#{ \markup { \hspace #0
\translate #'(5 . 0)
\line { \dynamic "mp"
\text \italic "dolce" } }
#})
inst =
#(define-music-function
(string)
(string?)
#{ <>^\markup \bold \box #string #})
#(set-global-staff-size 23)
\layout{
\context {
\Score
\override MetronomeMark.extra-offset = #'(-9 . 0)
\override MetronomeMark.padding = #'3
}
\context {
\Staff
}
\context {
\Voice
\override Glissando.thickness = #3
\override Glissando.gap = #0.1
}
}
|
Now in our music, I simply replace
\include "definitions.ily" with
\include "web-publish.ily". Of course, we could make this
even more convenient. We could make a ‘definitions.ily’ file which
contains only the definitions of mpdolce and inst, a
‘web-publish.ily’ file which contains only the \layout
section listed above, and a ‘university.ily’ file which
contains only the tweaks to produce the output that my professor
prefers. The top of ‘music.ly’ would then look like this:
\include "definitions.ily" %%% Only uncomment one of these two lines! \include "web-publish.ily" %\include "university.ily" |
This approach can be useful even if you are only producing
one set of parts. I use half a dozen different
‘style sheet’ files for my projects. I begin every music
file with \include "../global.ily", which contains
%%% global.ily \version "2.21.3" #(ly:set-option 'point-and-click #f) \include "../init/init-defs.ly" \include "../init/init-layout.ly" \include "../init/init-headers.ly" \include "../init/init-paper.ly" |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Internals Reference documentation contains a lot of information about LilyPond, but even more information can be gathered by looking at the internal LilyPond files. To explore these, you must first find the directory appropriate to your system. The location of this directory depends (a) on whether you obtained LilyPond by downloading a precompiled binary from lilypond.org or whether you installed it from a package manager (i.e. distributed with GNU/Linux, or installed under fink or cygwin) or compiled it from source, and (b) on which operating system it is being used:
Navigate to
‘INSTALLDIR/lilypond/usr/share/lilypond/current/’ |
Navigate to
‘INSTALLDIR/LilyPond.app/Contents/Resources/share/lilypond/current/’ |
by either cd-ing into this directory from the
Terminal, or control-clicking on the LilyPond application and
selecting ‘Show Package Contents’.
Using Windows Explorer, navigate to
‘INSTALLDIR/LilyPond/usr/share/lilypond/current/’ |
Navigate to
‘PREFIX/share/lilypond/X.Y.Z/’, where
PREFIX is set by your package manager or configure
script, and X.Y.Z is the LilyPond version number.
Within this directory the two interesting subdirectories are
Let’s begin by looking at some files in ‘ly/’.
Open ‘ly/property-init.ly’ in a text editor. The one
you normally use for .ly files will be fine. This file
contains the definitions of all the standard LilyPond predefined
commands, such as \stemUp and \slurDotted. You will
see that these are nothing more than definitions of variables
containing one or a group of \override commands. For
example, /tieDotted is defined to be:
tieDotted = {
\override Tie.dash-period = #0.75
\override Tie.dash-fraction = #0.1
}
|
If you do not like the default values these predefined commands can be redefined easily, just like any other variable, at the head of your input file.
The following are the most useful files to be found in ‘ly/’:
| Filename | Contents |
|---|---|
| ‘ly/engraver-init.ly’ | Definitions of engraver Contexts |
| ‘ly/paper-defaults-init.ly’ | Specifications of paper-related defaults |
| ‘ly/performer-init.ly’ | Definitions of performer Contexts |
| ‘ly/property-init.ly’ | Definitions of all common predefined commands |
| ‘ly/spanner-init.ly’ | Definitions of spanner-related predefined commands |
Other settings (such as the definitions of markup commands) are stored as ‘.scm’ (Scheme) files. The Scheme programming language is used to provide a programmable interface into LilyPond internal operation. Further explanation of these files is currently outside the scope of this manual, as a knowledge of the Scheme language is required. Users should be warned that a substantial amount of technical knowledge or time is required to understand Scheme and these files (see (extending)Scheme tutorial section ‘Scheme tutorial’ in Uitbreidingen).
If you have this knowledge, the Scheme files which may be of interest are:
| Filename | Contents |
|---|---|
| ‘scm/auto-beam.scm’ | Sub-beaming defaults |
| ‘scm/define-grobs.scm’ | Default settings for grob properties |
| ‘scm/define-markup-commands.scm’ | Specify all markup commands |
| ‘scm/midi.scm’ | Default settings for MIDI output |
| ‘scm/output-lib.scm’ | Settings that affect appearance of frets, colors, accidentals, bar lines, etc |
| ‘scm/parser-clef.scm’ | Definitions of supported clefs |
| ‘scm/script.scm’ | Default settings for articulations |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Although many things are possible with the \override and
\tweak commands, an even more powerful way of modifying
the action of LilyPond is available through a programmable
interface to the LilyPond internal operation. Code written in
the Scheme programming language can be incorporated directly in
the internal operation of LilyPond. Of course, at least a basic
knowledge of programming in Scheme is required to do this, and an
introduction is provided in the
(extending)Scheme tutorial section ‘Scheme tutorial’ in Uitbreidingen.
As an illustration of one of the many possibilities, instead of setting a property to a constant it can be set to a Scheme procedure which is then called whenever that property is accessed by LilyPond. The property can then be set dynamically to a value determined by the procedure at the time it is called. In this example we color the note head in accordance with its position on the staff.
#(define (color-notehead grob) "Color the notehead according to its position on the staff." (let ((mod-position (modulo (ly:grob-property grob 'staff-position) 7))) (case mod-position ;; Return rainbow colors ((1) (x11-color 'red )) ; for C ((2) (x11-color 'orange )) ; for D ((3) (x11-color 'yellow )) ; for E ((4) (x11-color 'green )) ; for F ((5) (x11-color 'blue )) ; for G ((6) (x11-color 'purple )) ; for A ((0) (x11-color 'violet )) ; for B ))) \relative { % Arrange to obtain color from color-notehead procedure \override NoteHead.color = #color-notehead a2 b | c2 d | e2 f | g2 a | }
Further examples showing the use of these programmable interfaces can be found in (extending)Callback functions section ‘Callback functions’ in Uitbreidingen.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by gub on Juli 13, 2020 using texi2html 1.82.
Andere talen: English, català, deutsch, español, français, italiano, 日本語.
Gebruik van automatische taalkeuze.