]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/rhythms.itely
72817c5babf43c5bddcc711331d4cac8df046e22
[lilypond.git] / Documentation / user / rhythms.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @ignore
3     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
4
5     When revising a translation, copy the HEAD committish of the
6     version that you are working on.  See TRANSLATION for details.
7 @end ignore
8
9 @node Rhythms
10 @section Rhythms
11
12 @lilypondfile[ragged-right,line-width=16\cm,staffsize=16,quote]
13 {rhythms-headword.ly}
14
15 This section discusses rhythms, durations, and bars.
16
17 @menu
18 * Writing rhythms::             
19 * Writing rests::               
20 * Displaying rhythms::          
21 * Beams::                       
22 * Bars::                        
23 * Special rhythmic concerns::   
24 @end menu
25
26
27 @node Writing rhythms
28 @subsection Writing rhythms
29
30 @menu
31 * Durations::                   
32 * Tuplets::                     
33 * Scaling durations::           
34 @end menu
35
36 @node Durations
37 @unnumberedsubsubsec Durations
38
39 @cindex duration
40 @funindex \longa
41 @funindex \breve
42 @funindex \maxima
43
44 When entering notes, durations are designated by numbers and dots:
45 durations are entered as their reciprocal values.  For example, a
46 quarter note is entered using a @code{4} (since it is a 1/4 note),
47 while a half note is entered using a @code{2} (since it is a 1/2
48 note).  For notes longer than a whole you must use the
49 @code{\longa} (a double breve) and @code{\breve} commands.  Note
50 durations as short as 64th notes may be specified.
51
52 @c Two 64th notes are needed to obtain beams
53 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
54 \time 8/1
55 c\longa c\breve c1 c2
56 c4 c8 c16 c32 c64 c64
57 @end lilypond
58
59 @noindent
60 and the same durations with automatic beaming turned off 
61 see @ref{Automatic beams}:
62
63 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
64 \time 8/1
65 \autoBeamOff
66 c\longa c\breve c1 c2
67 c4 c8 c16 c32 c64 c64
68 @end lilypond
69
70 If the duration is omitted then it is set to the previously
71 entered duration.  The default for the first note is a quarter
72 note.
73
74 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
75 a a a2 a a4 a a1 a
76 @end lilypond
77
78
79 @funindex .
80
81 To obtain dotted note lengths, simply add a dot (@samp{.}) to the
82 number.  Double-dotted notes are produced in a similar way.
83
84 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
85 a4 b c4. b8 a4. b4.. c8.
86 @end lilypond
87
88 Some durations cannot be entered using only binary durations
89 and dots, and can only be represented by tying two or more 
90 notes together.  Tied notes are covered in @ref{Ties}.
91
92 @refcommands
93
94 Dots are normally moved up to avoid staff lines, except in
95 polyphonic situations.  The following commands may be used to
96 force a particular direction manually
97
98 @funindex \dotsUp
99 @code{\dotsUp},
100 @funindex \dotsDown
101 @code{\dotsDown},
102 @funindex \dotsNeutral
103 @code{\dotsNeutral}.
104
105 @c TODO: after deciding the link question, fix these.  -gp
106 Durations are entered in the same way in @code{drummode},
107 @code{chordmode}, @code{figuremode} and (optionally) 
108 in @code{lyricmode}.
109
110 @seealso
111
112 For ways of specifying durations for the syllables of lyrics
113 and ways of aligning lyrics to notes see @ref{Vocal music}
114
115 For a description of how to enter rests see @ref{Writing rests}
116
117 A note with the duration of a quadruple breve may be
118 entered with \maxima, but this is supported only within
119 ancient music notation.  See @ref{Ancient notation}
120
121 Optionally, notes can be spaced proportionately to their duration.
122 For details of this and other settings which control
123 proportional notation see @ref{Proportional notation}.
124
125 Program reference: @internalsref{Dots}, and
126 @internalsref{DotColumn}.
127
128
129 @node Tuplets
130 @unnumberedsubsubsec Tuplets
131
132 @cindex tuplets
133 @cindex triplets
134 @funindex \times
135
136 @c TODO Add Tuplet to glossary
137
138 Tuplets are made out of a music expression by multiplying all
139 durations with a fraction
140
141 @example
142 \times @var{fraction} @var{musicexpr}
143 @end example
144
145 @noindent
146 The duration of @var{musicexpr} will be multiplied by the 
147 fraction.  The fraction's denominator will be printed over or 
148 under the notes, optionally with a bracket.  The most common 
149 tuplet is the triplet in which 3 notes have the length of 2, so 
150 the notes are 2/3 of their written length.
151
152 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
153 g4 \times 2/3 {c4 c c} d4 d4
154 @end lilypond
155
156 Tuplets may be nested, for example,
157
158 @lilypond[fragment,ragged-right,verbatim,relative=2]
159 \override TupletNumber #'text = #tuplet-number::calc-fraction-text
160 \times 4/6 {
161   a4 a
162   \times 3/5 { a a a a a }
163 }
164 @end lilypond
165
166 @refcommands
167
168 @funindex \tupletUp
169 @code{\tupletUp},
170 @funindex \tupletDown
171 @code{\tupletDown},
172 @funindex \tupletNeutral
173 @code{\tupletNeutral}.
174
175
176 @commonprop
177
178 @funindex tupletNumberFormatFunction
179 @cindex tuplet formatting
180
181 The property @code{tupletSpannerDuration} specifies how long each
182 bracket should last.  With this, you can make lots of tuplets
183 while typing @code{\times} only once, thus saving lots of typing.
184 In the next example, there are two triplets shown, while
185 @code{\times} was only used once
186
187 @lilypond[quote,fragment,relative=2,ragged-right,verbatim]
188 \set tupletSpannerDuration = #(ly:make-moment 1 4)
189 \times 2/3 { c8 c c c c c }
190 @end lilypond
191
192 @noindent
193 For more information about @code{make-moment}, see
194 @ref{Time administration}.
195
196 The format of the number is determined by the property @code{text}
197 in @code{TupletNumber}.  The default prints only the denominator,
198 but if it is set to the function
199 @code{tuplet-number::calc-fraction-text}, @var{num}:@var{den} will
200 be printed instead.
201
202 To avoid printing tuplet numbers, use
203
204 @lilypond[quote,fragment,relative=2,ragged-right,verbatim]
205 \times 2/3 { c8 c c } \times 2/3 { c8 c c }
206 \override TupletNumber #'transparent = ##t
207 \times 2/3 { c8 c c } \times 2/3 { c8 c c }
208 @end lilypond
209
210 Use the @code{\tweak} function to override nested tuplets
211 beginning at the same music moment.  In this example,
212 @code{\tweak} specifies fraction text for the outer
213 @code{TupletNumber} and denominator text for the
214 @code{TupletNumber} of the first of the three inner tuplets.
215
216 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
217 \tweak #'text #tuplet-number::calc-fraction-text
218 \times 4/3 {
219    \tweak #'text #tuplet-number::calc-denominator-text
220    \times 2/3 { c8[ c8 c8] }
221    \times 2/3 { c8[ c8 c8] }
222    \times 2/3 { c8[ c8 c8] }
223 }
224 @end lilypond
225
226 Here @code{\tweak} and @code{\override} work together to specify
227 @code{TupletBracket} direction.  The first @code{\tweak} positions
228 the @code{TupletBracket} of the outer tuplet above the staff.  The
229 second @code{\tweak} positions the @code{TupletBracket} of the
230 first of the three inner tuplets below the staff.  Note that this
231 pair of @code{\tweak} functions affects only the outer tuplet and
232 the first of the three inner tuplets because only those two
233 tuplets begin at the same music moment.  We use @code{\override}
234 in the usual way to position the @code{TupletBrackets} of the
235 second and third of the inner tuplets below the staff.
236
237 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
238 \tweak #'text #tuplet-number::calc-fraction-text
239 \tweak #'direction #up
240 \times 4/3 {
241    \tweak #'direction #down
242    \times 2/3 { c8[ c8 c8] }
243    \override TupletBracket #'direction = #down
244    \times 2/3 { c8[ c8 c8] }
245    \times 2/3 { c8[ c8 c8] }
246 }
247 @end lilypond
248
249 Tuplet brackets can be made to run to prefatory matter or the next
250 note
251
252 @lilypond[ragged-right]
253 \new RhythmicStaff {
254   \set tupletFullLength = ##t
255   \time 4/4
256   \times 4/5 {
257     c4 c1
258   }
259   \set tupletFullLengthNote = ##t
260   \time 2/4
261   \times 2/3 {
262     c4 c c 
263   }
264   \time 3/4
265   c4 
266 }
267 @end lilypond
268
269 Tuplets which cross barlines will prevent a line break at that
270 point.
271
272 @seealso
273
274 Program reference: @internalsref{TupletBracket},
275 @internalsref{TupletNumber}, and @internalsref{TimeScaledMusic}.
276
277
278
279 @node Scaling durations
280 @unnumberedsubsubsec Scaling durations
281
282 You can alter the length of a duration by a fraction @var{N/M}
283 by appending @samp{*@var{N/M}} (or @samp{*@var{N}} if @var{M=1}).
284 This will not affect the appearance of the notes or rests
285 produced, but the altered duration will be used in calculating the
286 position within the bar and setting the duration in the MIDI
287 output.  Multiplying factors may be combined
288 such as @samp{*M*N}.
289
290 In the following example, the first three notes take up exactly
291 two beats, but no triplet bracket is printed.
292
293 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
294 \time 2/4
295 a4*2/3 gis4*2/3 a4*2/3
296 a4 a4 a4*2
297 b16*4 c4
298 @end lilypond
299
300 The duration of skip or spacing notes may also be modified by
301 a multiplier.  This is useful for skipping many bars, e.g., 
302 @samp{s1*23}.
303
304 @seealso
305
306 This manual: @ref{Tuplets}, @ref{Skips}.
307
308
309
310
311 @node Writing rests
312 @subsection Writing rests
313
314 @menu
315 * Rests::                       
316 * Skips::                       
317 * Multi measure rests::         
318 @end menu
319
320 @node Rests
321 @unnumberedsubsubsec Rests
322 @cindex Rests
323
324 @funindex \rest
325 @funindex r
326 @funindex \maxima
327
328 Rests are entered like notes with the note name @code{r}
329
330 @c \time 16/1 is used to avoid spurious barlines
331 @c and long tracts of empty bars
332 @lilypond[fragment,quote,ragged-right,verbatim]
333 \new Staff {
334   \time 16/1
335   \override Staff.TimeSignature #'stencil = ##f
336   r\maxima
337   r\longa r\breve r1 r2
338   r4 r8 r16 r32 r64
339 }
340 @end lilypond
341
342 Whole bar rests, centered in middle of the bar, must be entered as
343 multi-measure rests.  They can be used for a single bar as well as
344 many bars, and are discussed in @ref{Multi measure rests}.
345
346 To explicitly specify a rest's vertical position, write a note
347 followed by @code{\rest}.  A rest will be placed in the position
348 where the note would appear,
349
350 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
351 a4\rest d4\rest
352 @end lilypond
353
354 @noindent
355 This makes manual formatting of polyphonic music much easier,
356 since the automatic rest collision formatter will leave these
357 rests alone.
358
359 @seealso
360
361 Program reference: @internalsref{Rest}.
362
363
364 @node Skips
365 @unnumberedsubsubsec Skips
366
367 @cindex Skip
368 @cindex Invisible rest
369 @cindex Space note
370 @funindex \skip
371 @funindex s
372
373 An invisible rest (also called a @q{skip}) can be entered like a
374 note with note name @samp{s} or with @code{\skip @var{duration}}
375
376 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
377 a4 a4 s4 a4 \skip 1 a4
378 @end lilypond
379
380 The @code{s} syntax is only available in note mode and chord mode.
381 In other situations, for example, when entering lyrics, you should
382 use the @code{\skip} command
383
384 @lilypond[quote,ragged-right,verbatim,relative=2]
385 <<
386   { a2 a2 }
387   \new Lyrics \lyricmode { \skip 2 bla2 }
388 >>
389 @end lilypond
390
391 The skip command is merely an empty musical placeholder.  It does
392 not produce any output, not even transparent output.
393
394 The @code{s} skip command does create @internalsref{Staff} and
395 @internalsref{Voice} when necessary, similar to note and rest
396 commands.  For example, the following results in an empty staff.
397
398 @lilypond[quote,ragged-right,verbatim]
399 { s4 }
400 @end lilypond
401
402 The fragment @code{@{ \skip 4 @} } would produce an empty page.
403
404 @seealso
405
406 Program reference: @internalsref{SkipMusic}.
407
408
409 @node Multi measure rests
410 @unnumberedsubsubsec Multi measure rests
411
412 @cindex multi measure rests
413 @cindex full measure rests
414 @cindex Rests, multi measure
415 @cindex Rests, full measure
416 @cindex whole rests for a full measure
417 @funindex R
418
419 Rests for one or more full measures are entered using
420 @code{R} followed by a duration (see @ref{Durations}).
421 The duration should correspond to an integral number 
422 of bars, otherwise a barcheck warning is printed.  
423 Multi-measure rests are principally used to indicate
424 that a part in a multi-part score should be silent:
425
426 @lilypond[quote,fragment,verbatim,relative=2]
427 \set Score.skipBars = ##t
428 R1*4
429 R1*24
430 R1*4
431 b2^"Tutti" b4 a4
432 @end lilypond
433
434 A multi-measure rest can be expanded in the printed score
435 to show all the rest bars explicitly, or, as above, it can be 
436 condensed to a single bar
437 containing a multi-measure rest symbol, with the number of
438 bars of rest printed above the bar.  This expansion
439 is controlled by the property @code{Score.skipBars}.  If this is
440 set to true, empty measures will condensed to a single bar.
441
442 @lilypond[quote,ragged-right,fragment,verbatim]
443 \time 4/4 r1 | R1 | R1*2 | 
444 \time 2/4 R2 | 
445 \time 4/4
446 \set Score.skipBars = ##t 
447 R1*17 | R1*4 |
448 @end lilypond
449
450 The @code{1} in @code{R1} is similar to the duration notation 
451 used for notes and is the length of a bar in 2/2 or 4/4 time.
452 The duration in a multi-measure rest must always be an integral
453 number of bar-lengths, so in other time signatures augmentation
454 dots or fractions must be used:
455
456 @lilypond[quote,ragged-right,fragment,verbatim]
457 \set Score.skipBars = ##t
458 \time 3/4
459 R2. | R2.*2
460 \time 13/8
461 R1*13/8 | R1*13/8*12 |
462 \time 10/8 
463 R4*5*4 |
464 @end lilypond
465
466 An @code{R} spanning a single measure is printed as either a whole
467 or breve rest, centered in the measure, regardless of the time
468 signature.
469
470 If there are 10 or fewer measures of rest, LilyPond prints
471 @rglos{church rests} (a series of longa and breve rests)
472 in the staff and
473 prints a simple line otherwise.  This default number of 10
474 may be changed by overriding 
475 @code{MultiMeasureRest.expand-limit}.
476
477 @lilypond[quote,ragged-right,fragment,verbatim]
478 \set Score.skipBars = ##t
479 R1*2 | R1*5 | R1*9
480 \override MultiMeasureRest #'expand-limit = 3
481 R1*2 | R1*5 | R1*9
482 @end lilypond
483
484 Note that the vertical position on the staff of the multi-measure
485 rest symbol of either form cannot be changed.
486
487 @cindex text on multi-measure rest
488 @cindex script on multi-measure rest
489 @cindex fermata on multi-measure rest
490
491 Text can be added to multi-measure rests by using the
492 @var{note}-@code{markup} syntax @ref{Text markup}.  A variable
493 (@code{\fermataMarkup}) is provided for adding fermatas
494
495 @lilypond[quote,ragged-right,verbatim,fragment]
496 \set Score.skipBars = ##t
497 \time 3/4
498 R2.*10^\markup { \italic "ad lib." }
499 R2.^\fermataMarkup
500 @end lilypond
501
502 @warning{Text attached to a multi-measure rest is created 
503 by @code{MultiMeasureRestText}, not
504 @code{TextScript}.  Overrides must be directed to the correct
505 object, or they will be ignored.  See the following example.}
506
507 @lilypond[quote,ragged-right,verbatim,fragment]
508 \override TextScript #'padding = #5
509 R1^"low"
510 \override MultiMeasureRestText #'padding = #5
511 R1^"high"
512 @end lilypond
513
514 Text attached to a multi-measure rest will be centered above
515 (or below) it.  Long text attached in this way does not cause
516 the bar to expand, and may collide with text in adjacent bars.
517 Long text is better attached to a zero-length skip note preceding
518 the rest, preceded by @code{\fatText}, since this will cause the
519 bar to expand to accommodate the length of the text:
520
521 @lilypond[quote,ragged-right,verbatim,fragment]
522 \set Score.skipBars = ##t
523 \fatText
524 s1*0^\markup {[MAJOR GENERAL]}
525 R1*19
526 s1*0^\markup {[MABEL] }
527 s1*0_\markup {\italic {Cue: ... it is yours}}
528 R1*30
529 s1^\markup {CHORUS} % Chorus notes would go here
530 @end lilypond
531
532
533 @seealso
534
535 This manual: @ref{Text}
536
537 Program reference: 
538
539 @internalsref{MultiMeasureRest}.
540
541 The layout object @internalsref{MultiMeasureRestNumber} is for the
542 default number, and @internalsref{MultiMeasureRestText} for user
543 specified texts.
544
545
546 @refbugs
547
548 If an attempt is made to use fingerings (e.g., 
549 @code{R1*10-4}) to put numbers over multi-measure rests, the
550 fingering numeral (4) may collide with the bar counter 
551 numeral (10).  
552
553 @cindex condensing rests
554
555 There is no way to automatically condense multiple rests into a
556 single multi-measure rest.  Multi-measure rests do not take part
557 in rest collisions.
558
559 Be careful when entering multi-measure rests followed by whole
560 notes.  The following will enter two notes lasting four measures
561 each
562
563 @example
564 R1*4 cis cis
565 @end example
566
567
568 @node Displaying rhythms
569 @subsection Displaying rhythms
570
571 @menu
572 * Time signature::              
573 * Upbeats::                     
574 * Unmetered music::             
575 * Polymetric notation::         
576 * Automatic note splitting::    
577 * Setting automatic beam behavior::  
578 @end menu
579
580 @node Time signature
581 @unnumberedsubsubsec Time signature
582
583 @cindex Time signature
584 @cindex meter
585 @funindex \time
586
587 Time signature indicates the meter of a piece: a regular pattern
588 of strong and weak beats.  It is denoted by a fraction at the
589 start of the staff.
590
591 The time signature is set with the @code{\time} command
592
593 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
594 \time 2/4 c2 \time 3/4 c2.
595 @end lilypond
596
597 @commonprop
598
599 The symbol that is printed can be customized with the @code{style}
600 property.  Setting it to @code{#'()} uses fraction style for 4/4
601 and 2/2 time,
602
603 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
604 \time 4/4 c1
605 \time 2/2 c1
606 \override Staff.TimeSignature #'style = #'()
607 \time 4/4 c1
608 \time 2/2 c1
609 @end lilypond
610
611 A time signature is normally printed whenever the time signature
612 changes.  If this takes place at the end of a line a warning time
613 signature sign is printed at the end of the line and again at the
614 start of a new line.  This default behaviour can be modified by
615 setting the value of the @code{break-visibility} property.  This
616 takes three values which may be set to @code{#t} or @code{#f} to
617 specify whether the corresponding time signature is visible or not.
618 The order of the three values is @code{end of line visible},
619 @code{middle of line visible}, @code{beginning of line visible}.
620
621 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
622 % Do not print any time signatures at end of line
623 \override Staff.TimeSignature #'break-visibility = ##(#f #t #t)
624 \time 4/4 c1
625 \time 3/4 c2.
626 % Do not print the following 9/8 time signature
627 \once \override Staff.TimeSignature #'break-visibility = ##(#t #f #t)
628 \time 9/8 c4. c c
629 \time 2/2 c1
630 \break
631 \time 9/8 c4. c c
632 \time 12/8 c2. c2.
633 @end lilypond
634
635 There are many more options for its layout.  See @ref{Ancient time
636 signatures}, for more examples.
637
638 @code{\time} sets the property @code{timeSignatureFraction},
639 @code{beatLength} and @code{measureLength} in the @code{Timing}
640 context, which is normally aliased to @internalsref{Score}.  The
641 property @code{measureLength} determines where barlines should be
642 inserted, and how automatic beams should be generated.  Changing
643 the value of @code{timeSignatureFraction} also causes the symbol
644 to be printed.
645
646 @cindex Measure groupings
647  
648 More options are available through the Scheme function
649 @code{set-time-signature}.  In combination with the
650 @internalsref{Measure_grouping_engraver}, it will create
651 @internalsref{MeasureGrouping} signs.  Such signs ease reading
652 rhythmically complex modern music.  In the following example, the
653 9/8 measure is subdivided in 2, 2, 2 and 3.  This is passed to
654 @code{set-time-signature} as the third argument @code{(2 2 2 3)}
655
656 @lilypond[quote,ragged-right,verbatim]
657 \score {
658   \relative c'' {
659     #(set-time-signature 9 8 '(2 2 2 3))
660     g8[ g] d[ d] g[ g] a8[( bes g]) |
661     #(set-time-signature 5 8 '(3 2))
662     a4. g4
663   }
664   \layout {
665     \context {
666       \Staff
667       \consists "Measure_grouping_engraver"
668     }
669   }
670 }
671 @end lilypond
672
673
674 @seealso
675
676 Program reference: @internalsref{TimeSignature}, and
677 @internalsref{Timing_translator}.
678
679 Examples: @lsr{contemporary,compound-time-signature.ly}.
680
681
682 @refbugs
683
684 Automatic beaming does not use the measure grouping specified with
685 @code{set-time-signature}.
686
687
688 @node Upbeats
689 @unnumberedsubsubsec Upbeats
690
691 @cindex anacrusis
692 @cindex upbeat
693 @cindex partial measure
694 @cindex measure, partial
695 @cindex shorten measures
696 @funindex \partial
697
698 Partial measures, such as an anacrusis or upbeat, are entered
699 using the
700
701 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
702 \partial 16*5 c16 cis d dis e | a2. c,4 | b2
703 @end lilypond
704
705 The syntax for this command is
706
707 @example
708 \partial @var{duration}
709 @end example
710
711 where @code{duration} is the rhythmic length to be added before
712 the next bar.
713
714 This is internally translated into
715
716 @example
717 \set Timing.measurePosition = -@var{length of duration}
718 @end example
719
720 The property @code{measurePosition} contains a rational number
721 indicating how much of the measure has passed at this point.  Note
722 that this is a negative number; @code{\partial 4} is internally
723 translated to mean @qq{there is a quarter note left in the bar.}
724
725
726 @refbugs
727
728 This command does not take into account grace notes at the start
729 of the music.  When a piece starts with graces notes in the
730 pickup, then the @code{\partial} should follow the grace notes
731
732 @lilypond[verbatim,quote,ragged-right,relative,fragment]
733 \grace f16
734 \partial 4
735 g4
736 a2 g2
737 @end lilypond
738
739 @code{\partial} is only intended to be used at the beginning of a
740 piece.  If you use it after the beginning, some odd warnings may
741 occur.
742
743
744 @node Unmetered music
745 @unnumberedsubsubsec Unmetered music
746
747 @cindex cadenza
748 @funindex \cadenzaOn
749 @funindex \cadenzaOff
750
751 Barlines and bar numbers are calculated automatically.  For
752 unmetered music (cadenzas, for example), this is not desirable.
753 To turn off automatic barlines and bar numbers, use the commands
754 @code{\cadenzaOn} and @code{\cadenzaOff}.
755
756 @lilypond[verbatim,quote,ragged-right,relative=2,fragment]
757 c4 d e d
758 \cadenzaOn
759 c4 c d8 d d f4 g4.
760 \cadenzaOff
761 \bar "|"
762 d4 e d c
763 @end lilypond
764
765
766 @refbugs
767
768 LilyPond will only insert line breaks and page breaks at a
769 barline.  Unless the unmetered music ends before the end of the
770 staff line, you will need to insert invisible barlines
771
772 @example
773 \bar ""
774 @end example
775
776 @noindent
777 to indicate where breaks can occur.
778
779
780 @node Polymetric notation
781 @unnumberedsubsubsec Polymetric notation
782
783 @cindex double time signatures
784 @cindex signatures, polymetric
785 @cindex polymetric signatures
786 @cindex meter, polymetric
787
788 Double time signatures are not supported explicitly, but they can
789 be faked.  In the next example, the markup for the time signature
790 is created with a markup text.  This markup text is inserted in
791 the @internalsref{TimeSignature} grob.  See also
792 @lsr{contemporary,compound-time-signature}.
793
794 @lilypond[verbatim,ragged-right]
795 % create 2/4 + 5/8
796 tsMarkup =\markup {
797   \override #'(baseline-skip . 2) \number {
798     \column { "2" "4" }
799     \vcenter "+"
800     \bracket \column { "5" "8" }
801   }
802 }
803
804 {
805   \override Staff.TimeSignature #'stencil =
806     #ly:text-interface::print
807   \override Staff.TimeSignature #'text = #tsMarkup
808   \time 3/2
809   c'2 \bar ":" c'4 c'4.
810 }
811 @end lilypond
812
813 Each staff can also have its own time signature.  This is done by
814 moving the @internalsref{Timing_translator} to the
815 @internalsref{Staff} context.
816
817 @example
818 \layout @{
819   \context @{ \Score
820      \remove "Timing_translator"
821      \remove "Default_bar_line_engraver"
822   @}
823   \context @{
824     \Staff
825     \consists "Timing_translator"
826     \consists "Default_bar_line_engraver"
827   @}
828
829 @}
830 @end example
831
832
833 Now, each staff has its own time signature.
834
835 @example
836 <<
837   \new Staff @{
838     \time 3/4
839     c4 c c | c c c |
840   @}
841   \new Staff @{
842     \time 2/4
843     c4 c | c c | c c
844   @}
845   \new Staff @{
846     \time 3/8
847     c4. c8 c c c4. c8 c c
848   @}
849 >>
850 @end example
851
852 @lilypond[quote,ragged-right]
853 \layout{
854   \context{
855      \Score
856      \remove "Timing_translator"
857      \remove "Default_bar_line_engraver"
858     }
859   \context{ \Staff
860     \consists "Timing_translator"
861     \consists "Default_bar_line_engraver"
862   }
863 }
864
865 \relative c' <<
866   \new Staff {
867     \time 3/4
868     c4 c c | c c c |
869   }
870   \new Staff {
871     \time 2/4
872     c4 c | c c | c c
873   }
874   \new Staff {
875     \time 3/8
876     c4. c8 c c c4. c8 c c
877   }
878 >>
879 @end lilypond
880
881
882 A different form of polymetric notation is where note lengths have
883 different values across staves, but the bars are all the same 
884 length.
885
886 This notation can be created by setting a common time signature
887 for each staff but replacing it manually using
888 @code{timeSignatureFraction} to the desired fraction.  Then the
889 printed durations in each staff are scaled to the common time
890 signature.  The latter is done with @code{\compressMusic}, which
891 is used in a similar way to @code{\times}, but does not create 
892 a tuplet bracket.  The syntax is 
893
894 @example 
895 \compressMusic 
896 #'(@var{numerator} . @var{denominator}) @var{musicexpr} 
897 @end example
898
899
900
901 In this example, music with the time signatures of 3/4, 9/8, and
902 10/8 are used in parallel.  In the second staff, shown durations
903 are multiplied by 2/3, so that 2/3 * 9/8 = 3/4, and in the third
904 staff, shown durations are multiplied by 3/5, so that 3/5 * 10/8 =
905 3/4.
906
907 @lilypond[quote,ragged-right,verbatim,fragment]
908 \relative c' { <<
909   \new Staff {
910     \time 3/4
911     c4 c c | c c c |
912   }
913   \new Staff {
914     \time 3/4
915     \set Staff.timeSignatureFraction = #'(9 . 8)
916     \compressMusic #'(2 . 3)
917       \repeat unfold 6 { c8[ c c] }
918   }
919   \new Staff {
920     \time 3/4
921     \set Staff.timeSignatureFraction = #'(10 . 8)
922     \compressMusic #'(3 . 5) {
923       \repeat unfold 2 { c8[ c c] }
924       \repeat unfold 2 { c8[ c] }
925       | c4. c4. \times 2/3 { c8 c c } c4
926     }
927   }
928 >> }
929 @end lilypond
930
931
932 @refbugs
933
934 When using different time signatures in parallel, the spacing is
935 aligned vertically, but barlines distort the regular spacing.
936
937
938 @node Automatic note splitting
939 @unnumberedsubsubsec Automatic note splitting
940
941 Long notes which overrun barlines can be converted 
942 automatically to tied notes.  This is
943 done by replacing the @internalsref{Note_heads_engraver} by the
944 @internalsref{Completion_heads_engraver}.  In the following
945 examples, notes crossing the barline are split and tied.
946
947 @lilypond[quote,fragment,verbatim,relative=1,line-width=12\cm]
948 \new Voice \with {
949   \remove "Note_heads_engraver"
950   \consists "Completion_heads_engraver"
951 } {
952   c2. c8 d4 e f g a b c8 c2 b4 a g16 f4 e d c8. c2
953 }
954 @end lilypond
955
956 This engraver splits all running notes at the barline, and
957 inserts ties.  One of its uses is to debug complex scores: if the
958 measures are not entirely filled, then the ties exactly show how
959 much each measure is off.
960
961 If you want to allow line breaking on the barlines where
962 @internalsref{Completion_heads_engraver} splits notes, you must
963 also remove @internalsref{Forbid_line_break_engraver}.
964
965
966 @refbugs
967
968 Not all durations (especially those containing tuplets) can be
969 represented exactly with normal notes and dots, but the engraver
970 will not insert tuplets.
971
972 @code{Completion_heads_engraver} only affects notes; it does not
973 split rests.
974
975
976 @seealso
977
978 Program reference: @internalsref{Completion_heads_engraver}.
979
980
981 @node Setting automatic beam behavior
982 @unnumberedsubsubsec Setting automatic beam behavior
983
984 @funindex autoBeamSettings
985 @funindex (end * * * *)
986 @funindex (begin * * * *)
987 @cindex automatic beams, tuning
988 @cindex tuning automatic beaming
989
990 @c [TODO: use \applyContext]
991
992 In normal time signatures, automatic beams can start on any note but can
993 only end in a few positions within the measure: beams can end on a beat,
994 or at durations specified by the properties in
995 @code{autoBeamSettings}.  The properties in @code{autoBeamSettings}
996 consist of a list of rules for where beams can begin and end.  The
997 default @code{autoBeamSettings} rules are defined in
998 @file{scm/@/auto@/-beam@/.scm}.
999
1000 In order to add a rule to the list, use
1001 @example
1002 #(override-auto-beam-setting '(be p q n m) a b [context])
1003 @end example
1004
1005 @itemize
1006
1007 @item @code{be} is either "begin" or "end".
1008
1009 @item @code{p/q} is the duration of the note for which you want
1010 to add a rule.  A beam is considered to have the duration of its
1011 shortest note.  Set @code{p} and @code{q} to @code{'*'} to
1012 have this apply to any beam.
1013
1014 @item @code{n/m} is the time signature to which
1015 this rule should apply.  Set @code{n} and @code{m} to @code{'*'}
1016 to have this apply in any time signature.
1017
1018 @item @code{a/b} is the position in the bar at which the beam should
1019 begin/end.
1020
1021 @item @code{context} is optional, and it specifies the context at which
1022 the change should be made.  The default is @code{'Voice}.
1023 @code{#(score-override-auto-beam-setting '(A B C D) E F)} is equivalent to
1024 @code{#(override-auto-beam-setting '(A B C D) E F 'Score)}.
1025
1026 @end itemize
1027
1028 For example, if automatic beams should always end on the first quarter
1029 note, use
1030
1031 @example
1032 #(override-auto-beam-setting '(end * * * *) 1 4)
1033 @end example
1034
1035 You can force the beam settings to only take effect on beams whose shortest
1036 note is a certain duration
1037
1038 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1039 \time 2/4
1040 #(override-auto-beam-setting '(end 1 16 * *) 1 16)
1041 a16 a a a a a a a |
1042 a32 a a a a16 a a a a a |
1043 #(override-auto-beam-setting '(end 1 32 * *) 1 16)
1044 a32 a a a a16 a a a a a |
1045 @end lilypond
1046
1047 You can force the beam settings to only take effect in certain time
1048 signatures
1049
1050 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1051 \time 5/8
1052 #(override-auto-beam-setting '(end * * 5 8) 2 8)
1053 c8 c d d d
1054 \time 4/4
1055 e8 e f f e e d d
1056 \time 5/8
1057 c8 c d d d
1058 @end lilypond
1059
1060 You can also remove a previously set beam-ending rule by using
1061
1062 @example
1063 #(revert-auto-beam-setting '(be p q n m) a b [context])
1064 @end example
1065
1066 @noindent
1067 be, p, q, n, m, a, b and context are the same as above.  Note that the
1068 default rules are specified in @file{scm/@/auto@/-beam@/.scm},
1069 so you can revert rules that you did not explicitly create.
1070
1071 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1072 \time 4/4
1073 a16 a a a a a a a a a a a a a a a
1074 #(revert-auto-beam-setting '(end 1 16 4 4) 1 4)
1075 a16 a a a a a a a a a a a a a a a
1076 @end lilypond
1077
1078 The rule in a revert-auto-beam-setting statement must exactly match the
1079 original rule.  That is, no wildcard expansion is taken into account.
1080
1081 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1082 \time 1/4
1083 #(override-auto-beam-setting '(end 1 16 1 4) 1 8)
1084 a16 a a a
1085 #(revert-auto-beam-setting '(end 1 16 * *) 1 8) % this won't revert it!
1086 a a a a
1087 #(revert-auto-beam-setting '(end 1 16 1 4) 1 8) % this will
1088 a a a a
1089 @end lilypond
1090
1091
1092
1093 @c TODO:  old material -- not covered by above stuff, I think.
1094 If automatic beams should end on every quarter in 5/4 time, specify
1095 all endings
1096 @example
1097 #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
1098 #(override-auto-beam-setting '(end * * * *) 1 2 'Staff)
1099 #(override-auto-beam-setting '(end * * * *) 3 4 'Staff)
1100 #(override-auto-beam-setting '(end * * * *) 5 4 'Staff)
1101 @dots{}
1102 @end example
1103
1104 The same syntax can be used to specify beam starting points.  In this
1105 example, automatic beams can only end on a dotted quarter note
1106 @example
1107 #(override-auto-beam-setting '(end * * * *) 3 8)
1108 #(override-auto-beam-setting '(end * * * *) 1 2)
1109 #(override-auto-beam-setting '(end * * * *) 7 8)
1110 @end example
1111 In 4/4 time signature, this means that automatic beams could end only on
1112 3/8 and on the fourth beat of the measure (after 3/4, that is 2 times
1113 3/8, has passed within the measure).
1114
1115 If any unexpected beam behaviour occurs, check the default automatic beam
1116 settings in @file{scm/@/auto@/-beam@/.scm}
1117 for possible interference, because the beam
1118 endings defined there will still apply on top of your own overrides.  Any
1119 unwanted endings in the default vales must be reverted for your time
1120 signature(s).
1121
1122 For example, to typeset @code{(3 4 3 2)}-beam endings in 12/8, begin
1123 with
1124
1125 @example
1126 %%% revert default values in scm/auto-beam.scm regarding 12/8 time
1127 #(revert-auto-beam-setting '(end * * 12 8) 3 8)
1128 #(revert-auto-beam-setting '(end * * 12 8) 3 4)
1129 #(revert-auto-beam-setting '(end * * 12 8) 9 8)
1130
1131 %%% your new values
1132 #(override-auto-beam-setting '(end 1 8 12 8) 3 8)
1133 #(override-auto-beam-setting '(end 1 8 12 8) 7 8)
1134 #(override-auto-beam-setting '(end 1 8 12 8) 10 8)
1135 @end example
1136
1137 @cindex automatic beam generation
1138 @cindex autobeam
1139 @funindex autoBeaming
1140 @cindex lyrics
1141
1142 If beams are used to indicate melismata in songs, then automatic
1143 beaming should be switched off with @code{\autoBeamOff}.
1144
1145
1146 @refcommands
1147
1148 @funindex \autoBeamOff
1149 @code{\autoBeamOff},
1150 @funindex \autoBeamOn
1151 @code{\autoBeamOn}.
1152
1153 @commonprop
1154
1155 Beaming patterns may be altered with the @code{beatGrouping} property,
1156
1157 @lilypond[quote,verbatim,relative=2,fragment,ragged-right]
1158 \time 5/16
1159 \set beatGrouping = #'(2 3)
1160 c8[^"(2+3)" c16 c8]
1161 \set beatGrouping = #'(3 2)
1162 c8[^"(3+2)" c16 c8]
1163 @end lilypond
1164
1165
1166 @refbugs
1167
1168 If a score ends while an automatic beam has not been ended and is
1169 still accepting notes, this last beam will not be typeset at all.  The
1170 same holds polyphonic voices, entered with @code{<< @dots{} \\ @dots{}
1171 >>}.  If a polyphonic voice ends while an automatic beam is still
1172 accepting notes, it is not typeset.
1173
1174
1175
1176
1177 @node Beams
1178 @subsection Beams
1179
1180 @menu
1181 * Automatic beams::             
1182 * Manual beams::                
1183 @end menu
1184
1185 @node Automatic beams
1186 @unnumberedsubsubsec Automatic beams
1187
1188 By default beams are inserted automatically
1189
1190 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
1191 \time 2/4 c8 c c c
1192 \time 6/8 c c c c8. c16 c8
1193 @end lilypond
1194
1195 When these automatic decisions are not good enough, beaming 
1196 can be entered explicitly.  It is also possible to define beaming
1197 patterns that differ from the defaults.  See @ref{Manual beams}
1198 and @ref{Setting automatic beam behavior}.
1199
1200 @cindex autoBeamOn
1201 @cindex autoBeamOff
1202
1203 @noindent
1204 Automatic beaming may be turned off and on with
1205 @code{\autoBeamOff} and @code{\autoBeamOn} commands:
1206
1207 @lilypond[quote,ragged-right,fragment,relative=1,verbatim]
1208 c4 c8 c8. c16 c8. c16 c8
1209 \autoBeamOff
1210 c4 c8 c8. c16 c8.
1211 \autoBeamOn
1212 c16 c8
1213 @end lilypond
1214
1215
1216 @commonprop
1217
1218 @funindex stemLeftBeamCount
1219 @funindex stemRightBeamCount
1220
1221 LilyPond can automatically determine beaming patterns within a
1222 beam, but this automatic behavior can sometimes produce odd
1223 results; therefore the @code{stemLeftBeamCount} and
1224 @code{stemRightBeamCount} properties can be used to override the
1225 defaults.  If either property is set, its value will be used only
1226 once, and then it is erased.
1227
1228 @lilypond[quote,ragged-right,fragment,relative=1,verbatim]
1229 {
1230    f8[ r16
1231       f g a]
1232    f8[ r16
1233    \set stemLeftBeamCount = #1
1234       f g a]
1235 }
1236 @end lilypond
1237
1238 The property @code{subdivideBeams} can be set in order to
1239 subdivide all 16th or shorter beams.
1240 When set, multiple beams will be sub-divided at beat 
1241 positions, defined by the current value of @code{beatLength},
1242 by drawing only one beam over the beat.
1243
1244 @lilypond[fragment,ragged-right,quote,relative=2,verbatim]
1245 c16[ c c c c c c c]
1246 \set subdivideBeams = ##t
1247 c16[ c c c c c c c]
1248 \set Score.beatLength = #(ly:make-moment 1 8)
1249 c16[ c c c c c c c]
1250 @end lilypond
1251 @funindex subdivideBeams
1252
1253 @noindent
1254 For more information about @code{make-moment}, see
1255 @ref{Time administration}.
1256
1257 @c TODO Consider whether the section Setting automatic
1258 @c beam behavior should all be moved here.  For now
1259 @c here's a link to it.
1260
1261 For details about modifying the automatic beam behaviour
1262 see @ref{Setting automatic beam behavior}
1263
1264 @funindex breakable
1265
1266 Line breaks are normally forbidden when beams cross barlines.
1267 This behavior can be changed by setting the @code{breakable} 
1268 property: @code{\override Beam #'breakable = ##t}.
1269
1270 @cindex beams and line breaks
1271 @cindex beams, kneed
1272 @cindex kneed beams
1273 @cindex auto-knee-gap
1274
1275 Kneed beams are inserted automatically when a large gap is
1276 detected between the note heads.  This behavior can be tuned
1277 through the @code{auto-knee-gap} property.  A kneed beam is
1278 drawn if the gap is larger than the value of 
1279 @code{auto-knee-gap} plus the width of the beam object (which
1280 depends on the duration of the notes and the slope of the beam).
1281 By default @code{auto-knee-gap} is set to 5.5 staff spaces.
1282
1283 @lilypond[fragment,ragged-right,quote,verbatim]
1284 f8 f''8 f8 f''8
1285 \override Beam #'auto-knee-gap = #6
1286 f8 f''8 f8 f''8
1287 @end lilypond
1288
1289
1290 @seealso
1291
1292 Program reference: @internalsref{Beam}.
1293
1294
1295 @refbugs
1296
1297 Automatically kneed cross-staff beams cannot be used together with
1298 hidden staves.  See @ref{Hiding staves}.
1299
1300 Beams can collide with noteheads and accidentals in other voices
1301
1302 @node Manual beams
1303 @unnumberedsubsubsec Manual beams
1304
1305 @cindex beams, manual
1306
1307 Individual notes may be marked with @code{\noBeam} to prevent them
1308 from being beamed:
1309
1310 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
1311 \time 2/4 c8 c\noBeam c c
1312 @end lilypond
1313
1314 @funindex ]
1315 @funindex [
1316
1317 In some cases it may be necessary to override the automatic
1318 beaming algorithm.  For example, the autobeamer will not put beams
1319 over rests or barlines, and in choral scores the beaming is
1320 often set to follow the meter of the lyrics rather than the
1321 notes. Such beams can be specified manually by
1322 marking the begin and end point with @code{[} and @code{]}
1323
1324 @lilypond[quote,ragged-right,fragment,relative=1,verbatim]
1325 {
1326   r4 r8[ g' a r8] r8 g[ | a] r8
1327 }
1328 @end lilypond
1329
1330 @cindex beams, feathered
1331 @funindex \featherDurations 
1332
1333 Feathered beams are used to indicate that a small group of notes
1334 should be played at an increasing (or decreasing) tempo, without
1335 changing the overall tempo of the piece.  The extent of the 
1336 feathered beam must be indicated manually using @code{[} and
1337 @code{]}, and the beam feathering is turned on by specifying a 
1338 direction to the Beam property @code{grow-direction}.
1339
1340 If the placement of the notes and the sound in the MIDI output
1341 is to reflect the ritardando or accelerando indicated by the
1342 feathered beam the notes must be grouped as a
1343 music expression delimited by braces and preceded by a
1344 @code{featheredDurations} command which specifies the ratio
1345 between the durations of the first and last notes in the group.
1346
1347 The square brackets
1348 show the extent of the beam and the braces show
1349 which notes are to have their durations modified.  Normally 
1350 these would delimit the same group of notes, but this is not
1351 required: the two commands are independent. 
1352
1353 In the following example the eight 16th notes occupy exactly
1354 the same time as a half note, but the first note is twice
1355 as short as the last one, with the intermediate notes gradually
1356 lengthening.  The first four 32nd notes gradually speed up,
1357 while the last four 32nd notes are at a constant tempo.
1358
1359 @lilypond[ragged-right,relative=1,fragment,verbatim,quote]
1360 \override Beam #'grow-direction = #LEFT
1361 \featherDurations #(ly:make-moment 2 1)
1362 { c16[ c c c c c c c] }
1363 \override Beam #'grow-direction = #RIGHT
1364 \featherDurations #(ly:make-moment 2 3)
1365 { c32[ d e f] }
1366 % revert to non-feathered beams
1367 \override Beam #'grow-direction = #'()
1368 { g32[ a b c] }
1369 @end lilypond
1370
1371 @noindent
1372 The spacing in the printed output represents the 
1373 note durations only approximately, but the midi output is exact.
1374
1375
1376 @commonprop
1377
1378 Line breaking is prevented by beams which straddle barlines. The
1379 @samp{breakable} property of @code{Beam} allows this behaviour
1380 to be overridden:
1381
1382 @lilypond[ragged-right,relative=2,fragment,verbatim,quote]
1383 \override Beam #'breakable = ##t
1384 c8 \repeat unfold 15 {c[ c] } c
1385 @end lilypond
1386
1387
1388 @refbugs
1389
1390 The @code{\featherDurations} command only works with very short
1391 music snippets, and when numbers in the fraction are small.
1392
1393
1394 @node Bars
1395 @subsection Bars
1396
1397
1398 @menu
1399 * Bar lines::                   
1400 * Bar numbers::                 
1401 * Bar and bar number checks::   
1402 * Rehearsal marks::             
1403 @end menu
1404
1405 @node Bar lines
1406 @unnumberedsubsubsec Bar lines
1407
1408 @cindex Bar lines
1409 @cindex Barlines
1410 @funindex \bar
1411 @cindex measure lines
1412 @cindex repeat bars
1413
1414 Barlines delimit measures, and are also used to indicate
1415 repeats.  Normally, simple barlines are automatically inserted
1416 into the printed output at places based on the current time 
1417 signature.  
1418
1419 The simple barlines inserted automatically can be changed to 
1420 other types with the @code{\bar} command.  For example, a closing
1421 double barline is usually placed at the end of a piece:
1422
1423 @lilypond[quote,ragged-right,relative=1,fragment,verbatim]
1424 e4 d c2 \bar "||"
1425 @end lilypond
1426
1427 @warning{An incorrect duration can lead to poorly formatted
1428 music.}
1429  
1430 It is not invalid if the final note in a bar does not 
1431 end on the automatically entered barline: the note is assumed 
1432 to carry over into the next bar.  But if a long sequence
1433 of such carry-over bars appears the music can appear compressed
1434 or even flowing off the page.  This is because automatic line
1435 breaks happen only at the end of complete bars, i.e. where 
1436 the end of a note coincides with the end of a bar.
1437
1438 Line breaks are also permitted at manually inserted barlines
1439 even within incomplete bars.  To allow a line break without 
1440 printing a barline, use
1441
1442 @example
1443 \bar ""
1444 @end example
1445
1446 @noindent
1447 This will insert an invisible barline and allow (but not
1448 force) a line break to occur at this point.  The bar number 
1449 counter is not increased.  To force a line break see 
1450 @ref{Line breaking}.
1451
1452 This and other special barlines may be inserted manually at any
1453 point.  When they coincide with the end of a bar they replace
1454 the simple barline which would have been inserted there 
1455 automatically.  When they do not coincide
1456 with the end of a bar the specified barline is inserted at that
1457 point in the printed output.  Such insertions do not affect
1458 the calculation and placement of subsequent automatic barlines.  
1459
1460 The simple barline and four types of double barline are available
1461 for manual insertion:
1462
1463 @lilypond[quote,ragged-right,fragment,relative=1,verbatim]
1464 f1 \bar "|" g \bar "||" a \bar ".|" b \bar ".|." c \bar "|." d
1465 @end lilypond
1466
1467 @noindent
1468 together with dotted and dashed barlines:
1469
1470 @lilypond[quote,ragged-right,fragment,relative=1,verbatim]
1471 f1 \bar ":" g \bar "dashed" a
1472 @end lilypond
1473
1474 @noindent
1475 and three types of repeat barline:
1476
1477 @lilypond[quote,ragged-right,fragment,relative=1,verbatim]
1478 f1 \bar "|:" g \bar ":|:" a \bar ":|" b
1479 @end lilypond
1480
1481 Although the barline types signifying repeats may be inserted
1482 manually they do not in themselves cause LilyPond to recognise
1483 a repeated section.  Such repeated sections are better entered
1484 using the various repeat commands (see @ref{Repeats}), which
1485 automatically print the appropriate barlines.
1486
1487 In addition, you can specify @code{"||:"}, which is equivalent to
1488 @code{"|:"} except at line breaks, where it gives a double bar
1489 line at the end of the line and a start repeat at the beginning of
1490 the next line. 
1491
1492 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1493 \override Score.RehearsalMark #'padding = #3
1494 c c c c
1495 \bar "||:" 
1496 c c c c \break
1497 \bar "||:" 
1498 c c c c
1499 @end lilypond
1500
1501 In scores with many staves, a @code{\bar} command in one staff is
1502 automatically applied to all staves.  The resulting barlines are
1503 connected between different staves of a @code{StaffGroup},
1504 @code{PianoStaff}, or @code{GrandStaff}.
1505
1506 @lilypond[quote,ragged-right,fragment,verbatim]
1507 <<
1508   \new StaffGroup <<
1509     \new Staff {
1510       e'4 d'
1511       \bar "||"
1512       f' e'
1513     }
1514     \new Staff { \clef bass c4 g e g }
1515   >>
1516   \new Staff { \clef bass c2 c2 }
1517 >>
1518 @end lilypond
1519
1520
1521 @commonprop
1522
1523 @funindex whichBar
1524 @funindex defaultBarType
1525
1526 The command @code{\bar }@var{bartype} is a short cut for
1527 @code{\set Timing.whichBar = }@var{bartype}.  A barline is 
1528 created whenever the @code{whichBar} property is
1529 set.  
1530
1531 The default bar type used for automatically inserted barlines is
1532 @code{"|"}.  This may be changed at any time
1533 with @code{\set Timing.defaultBarType = }@var{bartype}.  
1534
1535 @seealso
1536
1537 In this manual: @ref{Repeats}, @ref{System start delimiters}.
1538
1539 Program reference: @internalsref{BarLine} (created at
1540 @internalsref{Staff} level), @internalsref{SpanBar} (across
1541 staves), @internalsref{Timing_translator} (for Timing 
1542 properties).
1543
1544
1545 @node Bar numbers
1546 @unnumberedsubsubsec Bar numbers
1547
1548 @cindex Bar numbers
1549 @cindex measure numbers
1550 @funindex currentBarNumber
1551
1552 Bar numbers are typeset by default at the start of every line
1553 except the first line.  The
1554 number itself is stored in the @code{currentBarNumber} property,
1555 which is normally updated automatically for every measure.  It
1556 may also be set manually:
1557
1558 @lilypond[verbatim,ragged-right,quote,fragment,relative]
1559 \repeat unfold 4 {c4 c c c} \break
1560 \set Score.currentBarNumber = #50
1561 \repeat unfold 4 {c4 c c c}
1562 @end lilypond
1563
1564 Bar numbers may only be printed at barlines; to print a bar
1565 number at the beginning of a piece, an empty barline must be
1566 inserted there, and a value other than @code{1} must be placed
1567 in @code{currentBarNumber}:
1568
1569 @lilypond[verbatim,ragged-right,quote,fragment,relative]
1570 \set Score.currentBarNumber = #50
1571 \bar ""
1572 \repeat unfold 4 {c4 c c c} \break
1573 \repeat unfold 4 {c4 c c c}
1574 @end lilypond
1575
1576 @commonprop
1577
1578 @funindex barNumberVisibility
1579 @cindex bar numbers, regular spacing
1580
1581 Bar numbers can be typeset at regular intervals instead of just 
1582 at the beginning of every line.  To do this the default 
1583 behaviour must be overridden to permit bar numbers to be 
1584 printed at places other than the start of a line.  
1585 This is controlled by the 
1586 @code{break-visibility} property of @code{BarNumber}.  This
1587 takes three values which may be set to @samp{#t} or @samp{#f} to
1588 specify whether the corresponding bar number is visible or not.
1589 The order of the three values is @samp{end of line visible, middle
1590 of line visible, beginning of line visible}.  In the following
1591 example bar numbers are printed at all possible places:
1592
1593 @lilypond[verbatim,ragged-right,quote,fragment,relative]
1594 \override Score.BarNumber #'break-visibility = ##(#t #t #t)
1595 \set Score.currentBarNumber = #11
1596 \bar ""  % Permit first bar number to be printed
1597 c1 c c c c
1598 \break
1599 c c c c c
1600 @end lilypond
1601
1602 @noindent
1603 and here the bar numbers are printed every two bars
1604 except at the end of the line:
1605
1606 @lilypond[verbatim,ragged-right,quote,fragment,relative]
1607 \override Score.BarNumber #'break-visibility = ##(#f #t #t)
1608 \set Score.currentBarNumber = #11
1609 \bar ""  % Permit first bar number to be printed
1610 % Print a bar number every 2nd bar
1611 \set Score.barNumberVisibility = #(every-nth-bar-number-visible 2)
1612 c1 c c c c
1613 \break
1614 c c c c c
1615 @end lilypond
1616
1617 The size of the bar number may be changed.  This is illustrated
1618 in the following example, which also shows how to enclose bar 
1619 numbers in boxes and circles, and shows an alternative way
1620 of specifying @samp{#(#f #t #t)} for @code{break-visibility}.
1621
1622 @lilypond[verbatim,ragged-right,quote,fragment,relative]
1623 % Prevent bar numbers at the end of a line and permit them elsewhere
1624 \override Score.BarNumber #'break-visibility
1625   = #end-of-line-invisible
1626
1627 % Increase the size of the bar number by 2 
1628 \override Score.BarNumber #'font-size = #2
1629 \repeat unfold 3 { c1 } \bar "|"
1630
1631 % Draw a box round the following bar number(s)
1632 \override Score.BarNumber  #'stencil
1633   = #(make-stencil-boxer 0.1 0.25 ly:text-interface::print)
1634 \repeat unfold 3 { c1 } \bar "|"
1635
1636 % Draw a circle round the following bar number(s)
1637 \override Score.BarNumber  #'stencil
1638   = #(make-stencil-circler 0.1 0.25 ly:text-interface::print)
1639 \repeat unfold 4 { c1 } \bar "|."
1640 @end lilypond
1641
1642 @cindex Bar number alignment
1643
1644 Bar numbers by default are left-aligned to their parent object.
1645 This is usually the left edge of a line or, if numbers are printed
1646 within a line, the left barline of the bar.  The numbers may also
1647 be positioned directly on the barline or right-aligned to the 
1648 barline:
1649
1650 @lilypond[verbatim,ragged-right,quote,fragment,relative]
1651 \set Score.currentBarNumber = #111
1652 \override Score.BarNumber #'break-visibility = ##(#t #t #t)
1653 % Increase the size of the bar number by 2
1654 \override Score.BarNumber #'font-size = #2
1655 % Print a bar number every 2nd bar
1656 \set Score.barNumberVisibility = #(every-nth-bar-number-visible 2)
1657 c1 c1
1658 % Centre-align bar numbers
1659 \override Score.BarNumber #'self-alignment-X = #0
1660 c1 c1
1661 % Right-align bar numbers
1662 \override Score.BarNumber #'self-alignment-X = #-1
1663 c1 c1
1664 @end lilypond
1665
1666 Bar numbers can be removed entirely by removing the Bar number
1667 engraver from the score context.
1668
1669 @lilypond[verbatim,ragged-right,quote]
1670 \layout {
1671   \context {
1672     \Score
1673     \remove "Bar_number_engraver"
1674   }
1675 }
1676 \relative c''{
1677   c4 c c c \break
1678   c4 c c c
1679 }
1680 @end lilypond
1681
1682
1683 @seealso
1684
1685 Program reference: @internalsref{BarNumber}.
1686
1687 Examples: @lsrdir{bar number}
1688
1689
1690 @refbugs
1691
1692 Bar numbers can collide with the top of the 
1693 @internalsref{StaffGroup} bracket, if there is one.
1694 To solve this, the @code{padding} property of 
1695 @internalsref{BarNumber} can be used to
1696 position the number correctly.
1697
1698
1699 @node Bar and bar number checks
1700 @unnumberedsubsubsec Bar and bar number checks
1701
1702 @cindex Bar check
1703 @funindex barCheckSynchronize
1704 @funindex |
1705
1706 Bar checks help detect errors in the entered durations.
1707 A bar check may be entered using the bar symbol, @samp{|}, 
1708 at any place where a barline is expected to fall.  
1709 If bar check lines are encountered at other places, 
1710 a list of warnings is printed in the log file,
1711 showing the line numbers and lines  
1712 in which the bar checks failed.  In the next
1713 example, the second bar check will signal an error
1714
1715 @example
1716 \time 3/4 c2 e4 | g2 |
1717 @end example
1718
1719 Bar checks can also be used in lyrics, for example
1720
1721 @example
1722 \lyricmode @{
1723   \time 2/4
1724   Twin -- kle | Twin -- kle |
1725 @}
1726 @end example
1727
1728 An incorrect duration can result in a completely garbled score,
1729 especially if the score is polyphonic, so a good place to start
1730 correcting input is by scanning for failed bar checks and
1731 incorrect durations.
1732
1733 @funindex |
1734 @funindex pipeSymbol
1735
1736 It is also possible to redefine the action taken when a bar check 
1737 or pipe symbol, @samp{|}, is encountered in the input, so that 
1738 it does something other than a bar check.  This is done by 
1739 assigning a music expression to @code{pipeSymbol}.  
1740 In the following example @samp{|} is set to insert a double bar 
1741 line wherever it appears in the input, rather than checking 
1742 for end of bar.
1743
1744 @lilypond[quote,ragged-right,verbatim]
1745 pipeSymbol = \bar "||"
1746
1747   c'2 c'2 |
1748   c'2 c'2
1749   c'2 | c'2
1750   c'2 c'2
1751 }
1752 @end lilypond
1753
1754 When copying large pieces of music, it can be helpful to check
1755 that the LilyPond bar number corresponds to the original that you
1756 are entering from.  This can be checked with
1757 @code{\barNumberCheck}, for example,
1758
1759 @verbatim
1760 \barNumberCheck #123
1761 @end verbatim
1762
1763 @noindent
1764 will print a warning if the @code{currentBarNumber} is not 123
1765 when it is processed.
1766
1767
1768 @node Rehearsal marks
1769 @unnumberedsubsubsec Rehearsal marks
1770
1771 @cindex Rehearsal marks
1772 @funindex \mark
1773
1774 To print a rehearsal mark, use the @code{\mark} command
1775
1776 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
1777 c1 \mark \default
1778 c1 \mark \default
1779 c1 \mark #8
1780 c1 \mark \default
1781 c1 \mark \default
1782 @end lilypond
1783
1784 @noindent
1785 The letter@tie{}@q{I} is skipped in accordance with engraving
1786 traditions.  If you wish to include the letter @q{I}, then use
1787
1788 @example
1789 \set Score.markFormatter = #format-mark-alphabet
1790 @end example
1791
1792 The mark is incremented automatically if you use @code{\mark
1793 \default}, but you can also use an integer argument to set the
1794 mark manually.  The value to use is stored in the property
1795 @code{rehearsalMark}.
1796
1797 The style is defined by the property @code{markFormatter}.  It is
1798 a function taking the current mark (an integer) and the current
1799 context as argument.  It should return a markup object.  In the
1800 following example, @code{markFormatter} is set to a pre-defined
1801 procedure.  After a few measures, it is set to a procedure that
1802 produces a boxed number.
1803
1804 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
1805 \set Score.markFormatter = #format-mark-numbers
1806 c1 \mark \default
1807 c1 \mark \default
1808 \set Score.markFormatter = #format-mark-box-numbers
1809 c1 \mark \default
1810 c1 \mark \default
1811 c1
1812 @end lilypond
1813
1814 The file @file{scm/@/translation@/-functions@/.scm} contains the
1815 definitions of @code{format-mark-numbers} (the default format),
1816 @code{format-mark-box-numbers}, @code{format-mark-letters} and
1817 @code{format-mark-box-letters}.  These can be used as inspiration
1818 for other formatting functions.
1819
1820 You may use @code{format-mark-barnumbers},
1821 @code{format-mark-box-barnumbers}, and
1822 @code{format-mark-circle-barnumbers} to get bar numbers instead of
1823 incremented numbers or letters.
1824
1825 Other styles of rehearsal mark can be specified manually
1826
1827 @example
1828 \mark "A1"
1829 @end example
1830
1831 @noindent
1832 @code{Score.markFormatter} does not affect marks specified in this
1833 manner.  However, it is possible to apply a @code{\markup} to the
1834 string.
1835
1836 @example
1837 \mark \markup@{ \box A1 @}
1838 @end example
1839
1840 @cindex segno
1841 @cindex coda
1842 @cindex D.S al Fine
1843
1844 Music glyphs (such as the segno sign) may be printed inside a
1845 @code{\mark}
1846
1847 @lilypond[fragment,quote,ragged-right,verbatim,relative]
1848 c1 \mark \markup { \musicglyph #"scripts.segno" }
1849 c1 \mark \markup { \musicglyph #"scripts.coda" }
1850 c1 \mark \markup { \musicglyph #"scripts.ufermata" }
1851 c1
1852 @end lilypond
1853
1854 @noindent
1855 See @ref{The Feta font}, for a list of symbols which may be
1856 printed with @code{\musicglyph}.
1857
1858 For common tweaks to the positioning of rehearsal marks, see
1859 @ref{Text marks}.
1860
1861 @seealso
1862
1863 This manual: @ref{Text marks}.
1864
1865 Program reference: @internalsref{RehearsalMark}.
1866
1867 Init files: @file{scm/@/translation@/-functions@/.scm} contains
1868 the definition of @code{format-mark-numbers} and
1869 @code{format-mark-letters}.  They can be used as inspiration for
1870 other formatting functions.
1871
1872 Examples: @lsr{parts,rehearsal-mark-numbers.ly}
1873
1874
1875 @node Special rhythmic concerns
1876 @subsection Special rhythmic concerns
1877
1878
1879 @menu
1880 * Grace notes::                 
1881 * Aligning to cadenzas::        
1882 * Time administration::         
1883 @end menu
1884
1885 @node Grace notes
1886 @unnumberedsubsubsec Grace notes
1887
1888 @funindex \grace
1889 @cindex ornaments
1890 @cindex grace notes
1891 @cindex appoggiatura
1892 @cindex acciaccatura
1893
1894 Grace notes are ornaments that are written out.  The most common
1895 ones are acciaccatura, which should be played as very short.  It
1896 is denoted by a slurred small note with a slashed stem.  The
1897 appoggiatura is a grace note that takes a fixed fraction of the
1898 main note, and is denoted as a slurred note in small print without
1899 a slash.  They are entered with the commands @code{\acciaccatura}
1900 and @code{\appoggiatura}, as demonstrated in the following example
1901
1902 @lilypond[quote,ragged-right,relative=2,verbatim,fragment]
1903 b4 \acciaccatura d8 c4 
1904 \appoggiatura e8 d4
1905 \acciaccatura { g16[ f] } e4
1906 @end lilypond
1907
1908 Both are special forms of the @code{\grace} command.  By prefixing
1909 this keyword to a music expression, a new one is formed, which
1910 will be printed in a smaller font and takes up no logical time in
1911 a measure.
1912
1913 @lilypond[quote,ragged-right,relative=2,verbatim,fragment]
1914 c4 \grace c16 c4
1915 \grace { c16[ d16] } c2 c4
1916 @end lilypond
1917
1918 @noindent
1919 Unlike @code{\acciaccatura} and @code{\appoggiatura}, the
1920 @code{\grace} command does not start a slur.
1921
1922 The placement of grace notes is synchronized between different
1923 staves.  In the following example, there are two sixteenth grace
1924 notes for every eighth grace note
1925
1926 @lilypond[quote,ragged-right,relative=2,verbatim,fragment]
1927 << \new Staff { e4 \grace { c16[ d e f] } e4 }
1928    \new Staff { c4 \grace { g8[ b] } c4 } >>
1929 @end lilypond
1930
1931 @funindex \afterGrace
1932
1933 If you want to end a note with a grace, use the @code{\afterGrace}
1934 command.  It takes two arguments: the main note, and the grace
1935 notes following the main note.
1936
1937 @lilypond[ragged-right, verbatim,relative=2,fragment]
1938 c1 \afterGrace d1 { c16[ d] } c4
1939 @end lilypond
1940
1941 This will put the grace notes after a @q{space} lasting 3/4 of the
1942 length of the main note.  The fraction 3/4 can be changed by
1943 setting @code{afterGraceFraction}, ie.
1944
1945 @example
1946 #(define afterGraceFraction (cons 7 8))
1947 @end example
1948
1949 @noindent
1950 will put the grace note at 7/8 of the main note.
1951
1952 The same effect can be achieved manually by doing
1953
1954 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
1955 \new Voice {
1956   << { d1^\trill_( }
1957      { s2 \grace { c16[ d] } } >>
1958   c4)
1959 }
1960 @end lilypond
1961
1962 @noindent
1963 By adjusting the duration of the skip note (here it is a
1964 half-note), the space between the main-note and the grace
1965 may be adjusted.
1966
1967 A @code{\grace} music expression will introduce special
1968 typesetting settings, for example, to produce smaller type, and
1969 set directions.  Hence, when introducing layout tweaks, they
1970 should be inside the grace expression, for example,
1971
1972 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
1973 \new Voice {
1974   \acciaccatura {
1975     \stemDown
1976     f16->
1977     \stemNeutral
1978   }
1979   g4
1980 }
1981 @end lilypond
1982
1983 @noindent
1984 The overrides should also be reverted inside the grace expression.
1985
1986 The layout of grace expressions can be changed throughout the
1987 music using the function @code{add-grace-property}.  The following
1988 example undefines the @code{Stem} direction for this grace, so
1989 that stems do not always point up.
1990
1991 @example
1992 \new Staff @{
1993   #(add-grace-property 'Voice 'Stem 'direction '())
1994   @dots{}
1995 @}
1996 @end example
1997
1998 @noindent
1999 Another option is to change the variables @code{startGraceMusic},
2000 @code{stopGraceMusic}, @code{startAcciaccaturaMusic},
2001 @code{stopAcciaccaturaMusic}, @code{startAppoggiaturaMusic},
2002 @code{stopAppoggiaturaMusic}.  The default values of these can be
2003 seen in the file @file{ly/@/grace@/-init@/.ly}.  By redefining
2004 them other effects may be obtained.
2005
2006 @noindent
2007 The slash through the stem in acciaccaturas can be obtained in
2008 other situations by @code{\override Stem  #'stroke-style =
2009 #"grace"}.
2010
2011
2012 @commonprop
2013
2014 Grace notes may be forced to use align with regular notes
2015 in other staves by setting @code{strict-grace-spacing} to
2016 ##t:
2017
2018 @lilypond[relative=2,ragged-right]
2019 <<
2020   \override Score.SpacingSpanner #'strict-grace-spacing = ##t
2021   \new Staff {
2022      c'4
2023      \afterGrace
2024      c'4
2025      { c'16[ c'8 c'16] }
2026      c'4
2027   }  
2028   \new Staff {
2029      c'16[ c'16 c'16 c'16]
2030      c'16[ c'16 c'16 c'16]
2031      c'4
2032   }
2033 >>
2034 @end lilypond
2035
2036
2037 @seealso
2038
2039 Program reference: @internalsref{GraceMusic}.
2040
2041
2042 @refbugs
2043
2044 A multi-note beamed acciaccatura is printed without a slash, 
2045 and looks exactly the same as a multi-note beamed appoggiatura.
2046 @c TODO Add link to LSR snippet to add slash when available 
2047
2048 Grace note synchronization can also lead to surprises.  Staff
2049 notation, such as key signatures, barlines, etc., are also
2050 synchronized.  Take care when you mix staves with grace notes and
2051 staves without, for example,
2052
2053 @lilypond[quote,ragged-right,relative=2,verbatim,fragment]
2054 << \new Staff { e4 \bar "|:" \grace c16 d4 }
2055    \new Staff { c4 \bar "|:" d4 } >>
2056 @end lilypond
2057
2058 @noindent
2059 This can be remedied by inserting grace skips of the corresponding
2060 durations in the other staves.  For the above example
2061
2062 @lilypond[quote,ragged-right,relative=2,verbatim,fragment]
2063 << \new Staff { e4 \bar "|:" \grace c16 d4 }
2064    \new Staff { c4 \bar "|:" \grace s16 d4 } >>
2065 @end lilypond
2066
2067 Grace sections should only be used within sequential music
2068 expressions.  Nesting or juxtaposing grace sections is not
2069 supported, and might produce crashes or other errors.
2070
2071 @node Aligning to cadenzas
2072 @unnumberedsubsubsec Aligning to cadenzas
2073
2074 In an orchestral context, cadenzas present a special problem: when
2075 constructing a score that includes a cadenza, all other
2076 instruments should skip just as many notes as the length of the
2077 cadenza, otherwise they will start too soon or too late.
2078
2079 A solution to this problem are the functions
2080 @code{mmrest-of-length} and @code{skip-of-length}.  These Scheme
2081 functions take a piece of music as argument, and generate a
2082 multi-rest or @code{\skip}, exactly as long as the piece.  The use
2083 of @code{mmrest-of-length} is demonstrated in the following
2084 example.
2085
2086 @lilypond[verbatim,ragged-right,quote]
2087 cadenza = \relative c' {
2088   c4 d8 << { e f g } \\ { d4. } >>
2089   g4 f2 g4 g
2090 }
2091
2092 \new GrandStaff <<
2093   \new Staff { \cadenza c'4 }
2094   \new Staff {
2095     #(ly:export (mmrest-of-length cadenza))
2096     c'4
2097   }
2098 >>
2099 @end lilypond
2100
2101
2102 @node Time administration
2103 @unnumberedsubsubsec Time administration
2104
2105 @cindex Time administration
2106
2107 @funindex currentBarNumber
2108 @funindex measurePosition
2109 @funindex measureLength
2110
2111 Time is administered by the
2112 @code{Timing_translator}, which by default is
2113 to be found in the @code{Score} context.  An
2114 alias, @code{Timing}, is added to the context in which
2115 the @code{Timing_translator} is placed.
2116
2117 The following properties of @code{Timing} are used
2118 to keep track of timing within the score.
2119  
2120 @table @code
2121 @item currentBarNumber
2122 The current measure number.  For an example showing the
2123 use of this property see @ref{Bar numbers}.
2124
2125 @item measureLength
2126 The length of the measures in the current time signature.  For a
2127 4/4 time this is@tie{}1, and for 6/8 it is 3/4.  Its value
2128 determines when barlines are inserted and how automatic beams
2129 should be generated.
2130
2131 @item measurePosition
2132 The point within the measure where we currently are.  This
2133 quantity is reset by subtracting @code{measureLength} whenever
2134 @code{measureLength} is reached or exceeded.  When that happens, 
2135 @code{currentBarNumber} is incremented.
2136
2137 @item timing
2138 If set to true, the above variables are updated for every time
2139 step.  When set to false, the engraver stays in the current
2140 measure indefinitely.
2141
2142 @end table
2143
2144 Timing can be changed by setting any of these variables
2145 explicitly.  In the next example, the default 4/4 time 
2146 signature is printed, but @code{measureLength} is set to 5/4.
2147 At 4/8 though the third bar, the @code{measurePosition} is
2148 advanced by 1/8 to 5/8, shortening that bar by 1/8.
2149 The next barline then falls at 9/8 rather than 5/4.
2150
2151 @lilypond[quote,ragged-right,verbatim,relative,fragment]
2152 \set Score.measureLength = #(ly:make-moment 5 4)
2153 c1 c4
2154 c1 c4
2155 c4 c4
2156 \set Score.measurePosition = #(ly:make-moment 5 8)
2157 b4 b4 b8
2158 c4 c1
2159 @end lilypond
2160
2161 @noindent
2162 As the example illustrates, @code{ly:make-moment n m} constructs a
2163 duration of n/m of a whole note.  For example,
2164 @code{ly:make-moment 1 8} is an eighth note duration and
2165 @code{ly:make-moment 7 16} is the duration of seven sixteenths
2166 notes.
2167
2168 @seealso
2169
2170 This manual: @ref{Bar numbers}, @ref{Unmetered music}
2171
2172 Program Reference: @internalsref{Timing_translator},
2173 @internalsref{Score}
2174
2175
2176