1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
12 @node Working on LilyPond projects
13 @chapter Working on LilyPond projects
15 This section explains how to solve or avoid certain common
16 problems. If you have programming experience, many of these
17 tips may seem obvious, but it is still advisable to read
22 * Suggestions for writing LilyPond input files::
23 * When things don't work::
28 @node Suggestions for writing LilyPond input files
29 @section Suggestions for writing LilyPond input files
31 Now you're ready to begin writing larger LilyPond input files --
32 not just the little examples in the tutorial, but whole pieces.
33 But how should you go about doing it?
35 As long as LilyPond can understand your input files and produce
36 the output that you want, it doesn't matter what your input files
37 look like. However, there are a few other things to consider when
38 writing LilyPond input files.
41 @item What if you make a mistake? The structure of a LilyPond
42 file can make certain errors easier (or harder) to find.
44 @item What if you want to share your input files with somebody
45 else? In fact, what if you want to alter your own input files in
46 a few years? Some LilyPond input files are understandable at
47 first glance; others may leave you scratching your head
50 @item What if you want to upgrade your LilyPond file for use
51 with a later version of LilyPond? The input syntax changes
52 occasionally as LilyPond improves. Most changes can be
53 done automatically with @code{convert-ly}, but some changes
54 might require manual assistance. LilyPond input files can be
55 structured in order to be easier (or harder) to update.
59 * General suggestions::
60 * Typesetting existing music::
62 * Saving typing with variables and functions::
67 @node General suggestions
68 @subsection General suggestions
70 Here are a few suggestions that can help you to avoid or fix
74 @item @strong{Include @code{\version} numbers in every file}. Note that all
75 templates contain @code{\version} information. We
76 highly recommend that you always include the @code{\version}, no matter
77 how small your file is. Speaking from personal experience, it's
78 quite frustrating to try to remember which version of LilyPond you were
79 using a few years ago. @command{convert-ly} requires you to declare
80 which version of LilyPond you used.
82 @item @strong{Include checks}: @ruser{Bar and bar number checks},
83 @ruser{Octave checks}. If you include checks every so often, then
84 if you make a mistake, you can pinpoint it quicker. How often is
85 @q{every so often}? It depends on the complexity of the music.
86 For very simple music, perhaps just once or twice. For very
87 complex music, perhaps every bar.
89 @item @strong{One bar per line of text}. If there is anything complicated,
91 itself or in the output you desire, it's often good to write only one bar
92 per line. Saving screen space by cramming eight bars per line just isn't
93 worth it if you have to @q{debug} your input files.
95 @item @strong{Comment your input files}. Use either bar numbers
97 references to musical themes (@q{second theme in violins,} @q{fourth
98 variation,} etc.). You may not need comments when you're writing the piece
99 for the first time, but if you want to go back to change something two or
100 three years later, or if you pass the source over to a friend, it will
102 challenging to determine your intentions or how your file is structured if
103 you didn't comment the file.
105 @item @strong{Indent your braces}. A lot of problems are caused by an
107 in the number of @code{@{} and @code{@}}.
109 @item @strong{Explicitly add durations} at the beginnings of sections
110 and variables. If you specify @code{c4 d e} at the beginning of a
111 phrase (instead of just @code{c d e}) you can save yourself some
112 problems if you rearrange your music later.
114 @item @strong{Separate tweaks} from music definitions. See
115 @ref{Saving typing with variables and functions}, and
121 @node Typesetting existing music
122 @subsection Typesetting existing music
124 If you are entering music from an existing score (i.e., typesetting a
125 piece of existing sheet music),
129 @item Enter one manuscript (the physical copy) system at a time (but still
130 only one bar per line of text), and
131 check each system when you finish it. You may use the
132 @code{showLastLength} command to speed up processing -- see
133 @ruser{Skipping corrected music}.
135 @item Define @code{mBreak = @{ \break @}} and insert @code{\mBreak}
136 in the input file whenever the manuscript has a line break. This
137 makes it much easier to compare the LilyPond music to the original
138 music. When you are finished proofreading your score, you may
139 define @code{mBreak = @{ @}} to remove all those line breaks. This
140 will allow LilyPond to place line breaks wherever it feels are
147 @subsection Large projects
149 When working on a large project, having a clear structure to your
150 lilypond input files becomes vital.
154 @item @strong{Use an variable for each voice}, with a minimum of
155 structure inside the definition. The structure of the
156 @code{\score} section is the most likely thing to change;
157 the @code{violin} definition is extremely unlikely to change
158 in a new version of LilyPond.
161 violin = \relative c'' @{
174 @item @strong{Separate tweaks from music definitions}. This
175 point was made in previously, but for large
176 projects it is absolutely vital. We might need to change
177 the definition of @code{fthenp}, but then we only need
178 to do this once, and we can still avoid touching anything
179 inside @code{violin}.
183 \dynamic f \italic \small @{ 2nd @} \hspace #0.1 \dynamic p @}
184 violin = \relative c'' @{
192 @node Saving typing with variables and functions
193 @subsection Saving typing with variables and functions
198 By this point, you've seen this kind of thing:
200 @lilypond[quote,verbatim,ragged-right]
201 hornNotes = \relative c'' { c4 b dis c }
209 You may even realize that this could be useful in minimalist music:
211 @lilypond[quote,verbatim,ragged-right]
212 fragA = \relative c'' { a4 a8. b16 }
213 fragB = \relative c'' { a8. gis16 ees4 }
214 violin = \new Staff { \fragA \fragA \fragB \fragA }
222 However, you can also use these variables (also known as
223 variables, macros, or (user-defined) command) for tweaks:
225 @lilypond[quote,verbatim,ragged-right]
226 dolce = \markup{ \italic \bold dolce }
227 padText = { \once \override TextScript #'padding = #5.0 }
228 fthenp=_\markup{ \dynamic f \italic \small { 2nd } \hspace #0.1 \dynamic p }
229 violin = \relative c'' {
231 c4._\dolce b8 a8 g a b |
233 c4.^"hi there!" d8 e' f g d |
234 c,4.\fthenp b8 c4 c-. |
241 \layout{ragged-right=##t}
245 These variables are obviously useful for saving
246 typing. But they're worth considering even if you
247 only use them once -- they reduce complexity. Let's
248 look at the previous example without any
249 variables. It's a lot harder to read, especially
253 violin = \relative c'' @{
255 c4._\markup@{ \italic \bold dolce @} b8 a8 g a b |
256 \once \override TextScript #'padding = #5.0
257 c4.^"hi there!" d8 e' f g d |
258 c,4.\markup@{ \dynamic f \italic \small @{ 2nd @}
259 \hspace #0.1 \dynamic p @} b8 c4 c-. |
264 So far we've seen static substitution -- when LilyPond
265 sees @code{\padText}, it replaces it with the stuff that
266 we've defined it to be (ie the stuff to the right of
269 LilyPond can handle non-static substitution, too (you
270 can think of these as functions).
272 @lilypond[quote,verbatim,ragged-right]
274 #(define-music-function (parser location padding) (number?)
276 \once \override TextScript #'padding = #$padding
284 c4^"piu mosso" fis a g
288 Using variables is also a good way to reduce work if the
289 LilyPond input syntax changes (see @ref{Updating old input files}). If
290 you have a single definition (such as @code{\dolce}) for all your
291 input files (see @ref{Style sheets}), then if the syntax changes, you
292 only need to update your single @code{\dolce} definition,
293 instead of making changes throughout every @code{.ly} file.
297 @subsection Style sheets
299 The output that LilyPond produces can be heavily modified; see
300 @ref{Tweaking output}, for details. But what if you have many
301 input files that you want to apply your tweaks to? Or what if you
302 simply want to separate your tweaks from the actual music? This
305 Let's look at an example. Don't worry if you don't understand
306 the parts with all the @code{#()}. This is explained in
307 @ref{Advanced tweaks with Scheme}.
309 @lilypond[quote,verbatim,ragged-right]
310 mpdolce = #(make-dynamic-script (markup #:hspace 1 #:translate (cons 5 0)
311 #:line(#:dynamic "mp" #:text #:italic "dolce" )))
312 tempoMark = #(define-music-function (parser location markp) (string?)
314 \once \override Score . RehearsalMark #'self-alignment-X = #left
315 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
316 \mark \markup { \bold $markp }
321 a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
322 \tempoMark "Poco piu mosso"
323 cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
327 There are some problems with overlapping output; we'll fix those using
328 the techniques in @ref{Moving objects}. But let's also
329 do something about the @code{mpdolce} and @code{tempoMark}
330 definitions. They produce the output we desire, but we might want
331 to use them in another piece. We could simply copy-and-paste them
332 at the top of every file, but that's an annoyance. It also leaves
333 those definitions in our input files, and I personally find all
334 the @code{#()} somewhat ugly. Let's hide them in another file:
337 %%% save this to a file called "definitions.ly"
338 mpdolce = #(make-dynamic-script (markup #:hspace 1 #:translate (cons 5 0)
339 #:line(#:dynamic "mp" #:text #:italic "dolce" )))
340 tempoMark = #(define-music-function (parser location markp) (string?)
342 \once \override Score . RehearsalMark #'self-alignment-X = #left
343 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
344 \mark \markup @{ \bold $markp @}
348 Now let's modify our music (let's save this file as @file{"music.ly"}).
350 @c We have to do this awkward example/lilypond-non-verbatim
351 @c because we can't do the \include stuff in the manual.
354 \include "definitions.ly"
358 a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
359 \once \override Score.RehearsalMark #'padding = #2.0
360 \tempoMark "Poco piu mosso"
361 cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
365 @lilypond[quote,ragged-right]
366 mpdolce = #(make-dynamic-script (markup #:hspace 1 #:translate (cons 5 0)
367 #:line(#:dynamic "mp" #:text #:italic "dolce" )))
368 tempoMark = #(define-music-function (parser location markp) (string?)
370 \once \override Score . RehearsalMark #'self-alignment-X = #left
371 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
372 \mark \markup { \bold $markp }
377 a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
378 \once \override Score.RehearsalMark #'padding = #2.0
379 \tempoMark "Poco piu mosso"
380 cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
384 That looks better, but let's make a few changes. The glissando is hard
385 to see, so let's make it thicker and closer to the note heads. Let's
386 put the metronome marking above the clef, instead of over the first
387 note. And finally, my composition professor hates @q{C} time signatures,
388 so we'd better make that @q{4/4} instead.
390 Don't change @file{music.ly}, though. Replace our @file{definitions.ly}
395 mpdolce = #(make-dynamic-script (markup #:hspace 1 #:translate (cons 5 0)
396 #:line( #:dynamic "mp" #:text #:italic "dolce" )))
397 tempoMark = #(define-music-function (parser location markp) (string?)
399 \once \override Score . RehearsalMark #'self-alignment-X = #left
400 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
401 \mark \markup @{ \bold $markp @}
406 \override MetronomeMark #'extra-offset = #'(-9 . 0)
407 \override MetronomeMark #'padding = #'3
410 \override TimeSignature #'style = #'numbered
413 \override Glissando #'thickness = #3
414 \override Glissando #'gap = #0.1
419 @lilypond[quote,ragged-right]
420 mpdolce = #(make-dynamic-script (markup #:hspace 1 #:translate (cons 5 0)
421 #:line( #:dynamic "mp" #:text #:italic "dolce" )))
422 tempoMark = #(define-music-function (parser location markp) (string?)
424 \once \override Score . RehearsalMark #'self-alignment-X = #left
425 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
426 \mark \markup { \bold $markp }
431 \override MetronomeMark #'extra-offset = #'(-9 . 0)
432 \override MetronomeMark #'padding = #'3
435 \override TimeSignature #'style = #'numbered
438 \override Glissando #'thickness = #3
439 \override Glissando #'gap = #0.1
445 a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
446 \once \override Score.RehearsalMark #'padding = #2.0
447 \tempoMark "Poco piu mosso"
448 cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
452 That looks nicer! But now suppose that I want to publish this
453 piece. My composition professor doesn't like @q{C} time
454 signatures, but I'm somewhat fond of them. Let's copy the
455 current @file{definitions.ly} to @file{web-publish.ly} and
456 modify that. Since this music is aimed at producing a pdf which
457 will be displayed on the screen, we'll also increase the
458 overall size of the output.
462 mpdolce = #(make-dynamic-script (markup #:hspace 1 #:translate (cons 5 0)
463 #:line( #:dynamic "mp" #:text #:italic "dolce" )))
464 tempoMark = #(define-music-function (parser location markp) (string?)
466 \once \override Score . RehearsalMark #'self-alignment-X = #left
467 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
468 \mark \markup @{ \bold $markp @}
471 #(set-global-staff-size 23)
474 \override MetronomeMark #'extra-offset = #'(-9 . 0)
475 \override MetronomeMark #'padding = #'3
480 \override Glissando #'thickness = #3
481 \override Glissando #'gap = #0.1
486 @lilypond[quote,ragged-right]
487 mpdolce = #(make-dynamic-script (markup #:hspace 1 #:translate (cons 5 0)
488 #:line( #:dynamic "mp" #:text #:italic "dolce" )))
489 tempoMark = #(define-music-function (parser location markp) (string?)
491 \once \override Score . RehearsalMark #'self-alignment-X = #left
492 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
493 \mark \markup { \bold $markp }
496 #(set-global-staff-size 23)
499 \override MetronomeMark #'extra-offset = #'(-9 . 0)
500 \override MetronomeMark #'padding = #'3
503 \override Glissando #'thickness = #3
504 \override Glissando #'gap = #0.1
510 a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
511 \once \override Score.RehearsalMark #'padding = #2.0
512 \tempoMark "Poco piu mosso"
513 cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
517 Now in our music, I simply replace
518 @code{\include "definitions.ly"} with
519 @code{\include "web-publish.ly"}. Of course, we could make this
520 even more convenient. We could make a @file{definitions.ly} file which
521 contains only the definitions of @code{mpdolce} and @code{tempoMark}, a
522 @file{web-publish.ly} file which contains only the @code{\layout}
523 section listed above, and a @file{university.ly} file which
524 contains only the tweaks to produce the output that my professor
525 prefers. The top of @file{music.ly} would then look like this:
528 \include "definitions.ly"
530 %%% Only uncomment one of these two lines!
531 \include "web-publish.ly"
532 %\include "university.ly"
535 This approach can be useful even if you are only producing
536 one set of parts. I use half a dozen different
537 @q{style sheet} files for my projects. I begin every music
538 file with @code{\include "../global.ly"}, which contains
542 \version @w{"@version{}"}
543 #(ly:set-option 'point-and-click #f)
544 \include "../init/init-defs.ly"
545 \include "../init/init-layout.ly"
546 \include "../init/init-headers.ly"
547 \include "../init/init-paper.ly"
551 @node When things don't work
552 @section When things don't work
555 * Updating old input files::
556 * Troubleshooting (taking it all apart)::
560 @node Updating old input files
561 @subsection Updating old input files
563 The LilyPond input syntax occasionally changes. As LilyPond itself
564 improves, the syntax (input language) is modified accordingly. Sometimes
565 these changes are made to make the input easier to read and write or
566 sometimes the changes are made to accommodate new features of LilyPond.
568 LilyPond comes with a file that makes this updating easier:
569 @code{convert-ly}. For details about how to run this program, see
570 @rprogram{Updating files with convert-ly}.
572 Unfortunately, @code{convert-ly} cannot handle all input changes. It
573 takes care of simple search-and-replace changes (such as @code{raggedright}
574 becoming @code{ragged-right}), but some changes are too
575 complicated. The syntax changes that @code{convert-ly} cannot handle
576 are listed in @rprogram{Updating files with convert-ly}.
578 For example, in LilyPond 2.4 and earlier, accents and non-English
579 letters were entered using LaTeX -- for example,
580 @code{No\"el} (this would print the French word for
581 @q{Christmas}). In LilyPond 2.6 and above, the special
582 @code{ë} must be entered directly into the LilyPond file as an
583 UTF-8 character. @code{convert-ly} cannot change all the LaTeX
584 special characters into UTF-8 characters; you must manually update
585 your old LilyPond input files.
588 @node Troubleshooting (taking it all apart)
589 @subsection Troubleshooting (taking it all apart)
591 Sooner or later, you will write a file that LilyPond cannot
592 compile. The messages that LilyPond gives may help
593 you find the error, but in many cases you need to do some
594 investigation to determine the source of the problem.
596 The most powerful tools for this purpose are the
597 single line comment (indicated by @code{%}) and the block
598 comment (indicated by @code{%@{ ... %@}}). If you don't
599 know where a problem is, start commenting out huge portions
600 of your input file. After you comment out a section, try
601 compiling the file again. If it works, then the problem
602 must exist in the portion you just commented. If it doesn't
603 work, then keep on commenting out material until you have
604 something that works.
606 In an extreme case, you might end up with only
620 (in other words, a file without any music)
622 If that happens, don't give up. Uncomment a bit -- say,
623 the bass part -- and see if it works. If it doesn't work,
624 then comment out all of the bass music (but leave
625 @code{\bass} in the @code{\score} uncommented.
628 bass = \relative c' @{
636 Now start slowly uncommenting more and more of the
637 @code{bass} part until you find the problem line.
639 Another very useful debugging technique is constructing
640 @ref{Minimal examples}.
643 @node Minimal examples
644 @subsection Minimal examples
646 A minimal example is an example which is as small as possible. These
647 examples are much easier to understand than long examples. Minimal
648 examples are used for
652 @item Sending a help request to mailing lists
653 @item Adding an example to the @uref{http://lsr.dsi.unimi.it/,
654 LilyPond Snippet Repository}
657 To construct an example which is as small as possible, the rule is
658 quite simple: remove anything which is not necessary. When trying to
659 remove unnecessary parts of a file, it is a very good idea to comment
660 out lines instead of deleting them. That way, if you discover that you
661 actually @emph{do} need some lines, you can uncomment them, instead of
662 typing them in from scratch.
664 There are two exceptions to the @qq{as small as possible} rule:
667 @item Include the @code{\version} number.
668 @item If possible, use @code{\paper@{ ragged-right=##t @}} at the
672 The whole point of a minimal example is to make it easy to read:
675 @item Avoid using complicated notes, keys, or time signatures, unless you
676 wish to demonstrate something is about the behavior of those items.
677 @item Do not use @code{\override} commands unless that is the point of the
683 @node Scores and parts
684 @section Scores and parts
686 TODO: this is really old stuff from the really old tutorial.
687 Rewrite, fix, etc. Or maybe delete entirely. -gp
688 Include section on tags -td
689 and then move to section 5. Working ... -td
691 In orchestral music, all notes are printed twice. Once in a part for
692 the musicians, and once in a full score for the conductor. Variables can
693 be used to avoid double work. The music is entered once, and stored in
694 a variable. The contents of that variable is then used to generate
695 both the part and the full score.
697 It is convenient to define the notes in a special file. For example,
698 suppose that the file @file{horn-music.ly} contains the following part
699 of a horn/@/bassoon duo
702 hornNotes = \relative c @{
709 Then, an individual part is made by putting the following in a file
712 \include "horn-music.ly"
714 instrument = "Horn in F"
718 \transpose f c' \hornNotes
725 \include "horn-music.ly"
729 substitutes the contents of @file{horn-music.ly} at this position in
730 the file, so @code{hornNotes} is defined afterwards. The command
731 @code{\transpose f@tie{}c'} indicates that the argument, being
732 @code{\hornNotes}, should be transposed by a fifth upwards. Sounding
733 @code{f} is denoted by notated @code{c'}, which corresponds with the
734 tuning of a normal French Horn in@tie{}F. The transposition can be seen
735 in the following output
737 @lilypond[quote,ragged-right]
738 \transpose f c' \relative c {
744 In ensemble pieces, one of the voices often does not play for many
745 measures. This is denoted by a special rest, the multi-measure
746 rest. It is entered with a capital @code{R} followed by a duration
747 (@code{1}@tie{}for a whole note, @code{2}@tie{}for a half note,
748 etc.). By multiplying the
749 duration, longer rests can be constructed. For example, this rest
750 takes 3@tie{}measures in 2/4 time
756 When printing the part, multi-rests
757 must be condensed. This is done by setting a run-time variable
760 \set Score.skipBars = ##t
764 This command sets the property @code{skipBars} in the
765 @code{Score} context to true (@code{##t}). Prepending the rest and
766 this option to the music above, leads to the following result
768 @lilypond[quote,ragged-right]
769 \transpose f c' \relative c {
771 \set Score.skipBars = ##t
778 The score is made by combining all of the music together. Assuming
779 that the other voice is in @code{bassoonNotes} in the file
780 @file{bassoon-music.ly}, a score is made with
783 \include "bassoon-music.ly"
784 \include "horn-music.ly"
787 \new Staff \hornNotes
788 \new Staff \bassoonNotes
795 @lilypond[quote,ragged-right]
803 r4 d,8 f | gis4 c | b bes |
804 a8 e f4 | g d | gis f