| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section introduces some basic LilyPond syntax to help get you started writing input files.
| 1.2.1 Simple notation | ||
| 1.2.2 Working on input files |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| Pitches | ||
| Durations (rhythms) | ||
| Rests | ||
| Time signature | ||
| Tempo marks | ||
| Clef | ||
| All together |
LilyPond will add some notation elements automatically. In the next example, we have only specified four pitches, but LilyPond has added a clef, time signature, and rhythms.
{ c' e' g' e' }
This behavior may be altered, but in most cases these automatic values are useful.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Music Glossary: (music-glossary)pitch section ‘pitch’ in Music Glossary, (music-glossary)interval section ‘interval’ in Music Glossary, (music-glossary)scale section ‘scale’ in Music Glossary, (music-glossary)middle C section ‘middle C’ in Music Glossary, (music-glossary)octave section ‘octave’ in Music Glossary, (music-glossary)accidental section ‘accidental’ in Music Glossary.
LilyPond uses lower-case letters for pitches.
Note names in all examples in this section use the Dutch
naming system (white piano keys are c-b). However, LilyPond
does support many different naming schemes like English or
‘Fixed-Do’ (do-re-mi-...).
See
(notation)Note names in other languages section ‘Note names in other languages’ in Notation Reference.
The letters c through b denote pitches in the
‘small octave’ below middle C. Added '
or , suffixes indicate higher or lower octaves.
Here is a scale starting on middle C, and an arpeggio:
{ c' d' e' f' g' a' b' c'' g c' e' g' c'' e'' g'' c''' }
The easiest way to enter notes is by using \relative mode.
In this mode, the octave is chosen automatically by assuming the
following note is always to be placed closest to the previous
note, i.e., it is to be placed in the octave which is within three
staff spaces of the previous note. We begin by entering the most
elementary piece of music, a scale, in which every note
is within just one staff space of the previous note.
\relative { c' d e f g a b c }
The initial note is middle C, denoted by c'.
Each successive note is
placed closest to the previous note – in other words, the first
c is the closest C to middle C. This is followed by the
closest D to the previous note. We can create melodies which have
larger intervals, still using only \relative mode:
\relative { d' f a g c b f d }
In the previous example, the first note – the d' with one
'-mark – is the D in the octave starting from middle C
and going up to B.
By adding (or removing) quotes ' or commas , from
the first note, we can change the starting octave:
\relative { e'' c a c }
Relative mode can be confusing initially, but is the easiest way to enter most melodies. Let us see how this relative calculation works in practice. Starting from a B, which is on the middle line in a treble clef, you can reach a C, D and E within 3 staff spaces going up, and an A, G and F within 3 staff spaces going down. So if the note following a B is a C, D or E it will be assumed to be above the B, and an A, G or F will be assumed to be below.
\relative { b' c % c is 1 staff space up, so is the c above b d % d is 2 up or 5 down, so is the d above b e % e is 3 up or 4 down, so is the e above b a % a is 6 up or 1 down, so is the a below b g % g is 5 up or 2 down, so is the g below b f % f is 4 up or 3 down, so is the f below }
Exactly the same happens even when any of these notes are sharpened or flattened. Accidentals are totally ignored in the calculation of relative position. Precisely the same staff space counting is done from a note at any other position on the staff.
To add intervals that are larger than three staff spaces, we can
raise the octave by adding a single quote ' (or
apostrophe) to the note name. We can lower the octave by adding a
comma , to the note name.
\relative { a' a, c' f, g g'' a,, f' }
To change a note by two (or more!) octaves, we use multiple
'' or ,, – but be careful that you use two single
quotes '' and not one double quote " !
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Music Glossary: (music-glossary)beam section ‘beam’ in Music Glossary, (music-glossary)duration section ‘duration’ in Music Glossary, (music-glossary)whole note section ‘whole note’ in Music Glossary, (music-glossary)half note section ‘half note’ in Music Glossary, (music-glossary)quarter note section ‘quarter note’ in Music Glossary, (music-glossary)dotted note section ‘dotted note’ in Music Glossary.
The duration of a note is specified by a number after
the note name: 1 for a whole note, 2 for
a half note, 4 for a quarter note and
so on. Beams are added automatically.
If you do not specify a duration, the previous duration is used for the next note. The duration of the first note defaults to a quarter note.
\relative { a'1 a2 a4 a8 a a16 a a a a32 a a a a64 a a a a a a a a2 }
To create dotted notes, add a dot . to the
duration number. The duration of a dotted note must be stated
explicitly (i.e., with a number).
\relative { a'4 a a4. a8 a8. a16 a a8. a8 a4. }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Music Glossary: (music-glossary)rest section ‘rest’ in Music Glossary.
A rest is entered just like a note with the name
r :
\relative { a'4 r r2 r8 a r4 r4. r8 }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Music Glossary: (music-glossary)time signature section ‘time signature’ in Music Glossary.
The time signature can be set with the \time
command:
\relative { \time 3/4 a'4 a a \time 6/8 a4. a \time 4/4 a4 a a a }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Music Glossary: (music-glossary)tempo indication section ‘tempo indication’ in Music Glossary, (music-glossary)metronome section ‘metronome’ in Music Glossary.
The tempo indication and metronome mark can be
set with the \tempo command:
\relative { \time 3/4 \tempo "Andante" a'4 a a \time 6/8 \tempo 4. = 96 a4. a \time 4/4 \tempo "Presto" 4 = 120 a4 a a a }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Music Glossary: (music-glossary)clef section ‘clef’ in Music Glossary.
The clef can be set using the \clef command:
\relative { \clef "treble" c'1 \clef "alto" c1 \clef "tenor" c1 \clef "bass" c1 }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is a small example showing all these elements together:
\relative { \clef "bass" \time 3/4 \tempo "Andante" 4 = 120 c,2 e8 c' g'2. f4 e d c4 c, r }
Notation Reference: (notation)Writing pitches section ‘Writing pitches’ in Notation Reference, (notation)Writing rhythms section ‘Writing rhythms’ in Notation Reference, (notation)Writing rests section ‘Writing rests’ in Notation Reference, (notation)Time signature section ‘Time signature’ in Notation Reference, (notation)Clef section ‘Clef’ in Notation Reference.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
LilyPond input files are similar to source files in many common
programming languages. They contain a version statement, are case
sensitive, and white-space is generally ignored. Expressions are
formed with curly braces { }, and comments are
denoted with % or %{ … %} .
If the previous sentences sound like nonsense, don’t worry! We’ll explain what all these terms mean:
\version "2.21.3" |
By convention, the version statement is placed at the top of the LilyPond file.
The version statement is important for at least two reasons. First, it allows automatic updating of the input file as LilyPond syntax changes. Second, it describes the version of LilyPond needed to compile the file.
If the version statement is omitted from an input file, LilyPond will print a warning during the compilation of the file.
a, b, s, t) or upper case (e.g. A, B, S, T).
Notes are lower case: ‘{ c d e }’ is valid input;
‘{ C D E }’ will produce an error message.
{ c4 d
e }
|
Of course, the previous example is hard to read. A good rule of thumb is to indent code blocks with two spaces:
{
c4 d e
}
|
However, whitespace is required to separate many syntactical elements from others. In other words, whitespace can always be added, but not always eliminated. Since missing whitespace can give rise to strange errors, it is advisable to always insert whitespace before and after every syntactic element, for example, before and after every curly brace.
() in mathematics.
The braces should be surrounded by a space unless they are at the
beginning or end of a line to avoid ambiguities.
A LilyPond command followed by a simple expression in braces (such
as ‘\relative { … }’) also counts as a
single music expression.
% introduces a line comment; anything after % on
that line is ignored. By convention, a line comment is placed
above the code it refers to.
a4 a a a % this comment refers to the Bs b2 b |
A block comment marks a whole section of music input as a comment.
Anything that is enclosed in %{ and %} is ignored.
However, block comments do not ‘nest’. This means that you
cannot place a block comment inside another block comment. If you
try, the first %} will terminate both block
comments. The following fragment shows possible uses for
comments:
% notes for twinkle twinkle follow
c4 c g' g a a g2
%{
This line, and the notes below are ignored,
since they are in a block comment.
f4 f e e d d c2
%}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by gub on July 13, 2020 using texi2html 1.82.
其他语言:català, česky, deutsch, español, français, magyar, italiano, 日本語, nederlands。
关于 自动语言选择