| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is the final section of the tutorial; it demonstrates how to add the final touches to simple pieces, and provides an introduction to the rest of the manual.
| 2.4.1 Organizing pieces with variables | ||
| 2.4.2 Adding titles | ||
| 2.4.3 Absolute note names | ||
| 2.4.4 After the tutorial |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When all of the elements discussed earlier are combined to produce larger files, the music expressions get a lot bigger. In polyphonic music with many staves, the input files can become very confusing. We can reduce this confusion by using variables.
With variables (also known as identifiers or macros), we can break up complex music expressions. A variable is assigned as follows:
namedMusic = { … }
|
The contents of the music expression namedMusic can be used
later by placing a backslash in front of the name
(\namedMusic, just like a normal LilyPond command).
violin = \new Staff { \relative { a'4 b c b } } cello = \new Staff { \relative { \clef "bass" e2 d } } { << \violin \cello >> }
By convention, variable names consist of alphabetic characters only. For detailed information, see (notation)File structure section ‘File structure’ in Notation Reference.
Variables must be defined before the main music expression, but may be used as many times as required anywhere after they have been defined. They may even be used in a later definition of another variable, giving a way of shortening the input if a section of music is repeated many times.
tripletA = \relative { \tuplet 3/2 { c'8 e g } } barA = { \tripletA \tripletA \tripletA \tripletA } { \barA \barA }
Variables may be used for many other types of objects in the input. For example,
myWidth = 60 % a number to pass to a \paper variable (the unit is millimeter)
myName = "Wendy" % a string to pass to a markup
aFivePaper = \paper { #(set-paper-size "a5") }
|
Depending on its contents, the variable can be used in different places. The following example uses the above variables:
\paper {
\aFivePaper
line-width = \myWidth
}
{
c4^\myName
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The title, composer, opus number, and similar information are
entered in the \header block. This exists outside of the
main music expression; the \header block is usually placed
underneath the version number.
\version "2.21.3"
\header {
title = "Symphony"
composer = "Me"
opus = "Op. 9"
}
{
… music …
}
|
When the file is processed, the title and composer are printed above the music. More information on titling can be found in (notation)Creating titles headers and footers section ‘Creating titles headers and footers’ in Notation Reference.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
So far we have used \relative to define pitches.
This is usually the fastest way to enter most music. Without
\relative, pitches are interpreted in absolute mode.
In this mode, LilyPond treats all pitches as absolute values. A
c' will always mean middle C, a b will always mean
the note one step below middle C, and a g, will always mean
the note on the bottom staff of the bass clef.
{ \clef "bass" c'4 b g, g, | g,4 f, f c' | }
Writing a melody in the treble clef involves a lot
of quote ' marks. Consider this fragment from Mozart:
{ \key a \major \time 6/8 cis''8. d''16 cis''8 e''4 e''8 | b'8. cis''16 b'8 d''4 d''8 | }
Common octave marks can be indicated just once, using the command
\fixed followed by a reference pitch:
\fixed c'' { \key a \major \time 6/8 cis8. d16 cis8 e4 e8 | b,8. cis16 b,8 d4 d8 | }
With \relative, the previous example needs no octave marks
because this melody moves in steps no larger than three staff positions:
\relative { \key a \major \time 6/8 cis''8. d16 cis8 e4 e8 | b8. cis16 b8 d4 d8 | }
If you make a mistake with an octave mark (' or ,)
while working in \relative mode, it is very obvious – many
notes will be in the wrong octave. When working in absolute mode,
a single mistake will not be as visible, and will not be as easy
to find.
However, absolute mode is useful for music which has large intervals, and is extremely useful for computer-generated LilyPond files. When cutting and pasting melody fragments, absolute mode preserves the original octave.
Sometimes music is arranged in more complex ways. If you are
using \relative inside of \relative, the outer and
inner relative sections are independent:
\relative { c'4 \relative { f'' g } c }
To use absolute mode inside of \relative, put the absolute
music inside \fixed c { … } and the absolute pitches
will not affect the octaves of the relative music:
\relative { c'4 \fixed c { f'' g'' } c | c4 \fixed c'' { f g } c }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
After finishing the tutorial, you should probably try writing a piece or two. Start by adding notes to one of the Templates. If you need any notation that was not covered in the tutorial, look at the Notation Reference, starting with (notation)Musical notation section ‘Musical notation’ in Notation Reference. If you want to write for an instrument ensemble that is not covered in the templates, take a look at Extending the templates.
Once you have written a few short pieces, read the rest of the Learning Manual (chapters 3-5). There’s nothing wrong with reading it now, of course! However, the rest of the Learning Manual assumes that you are familiar with LilyPond input. You may wish to skim these chapters right now, and come back to them after you have more experience.
In this tutorial and in the rest of the Learning Manual, there is a paragraph See also at the end of each section, which contains cross-references to other sections: you should not follow these cross-references at first reading; when you have read all of the Learning Manual, you may want to read some sections again and follow cross-references for further reading.
If you have not done so already, please read Overview of manuals. There is a lot of information about LilyPond, so newcomers often do not know where they should look for help. If you spend five minutes reading that section carefully, you might save yourself hours of frustration looking in the wrong places!
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by gub on July 13, 2020 using texi2html 1.82.
Outros idiomas: català, česky, deutsch, español, français, magyar, italiano, 日本語, nederlands.
Sobre seleção automática de idioma.