]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/hacking.texi
release: 1.3.61
[lilypond.git] / Documentation / hacking.texi
1 \input texinfo @c -*-texinfo-*-
2 @setfilename internals.info
3 @settitle LilyPond internals
4
5 @node Top, LilyPond internals, (dir), (dir)
6 @top
7
8
9 @menu
10 * LilyPond internals::
11 * Overview::
12 * mudela::                      
13 * Request_engraver::            
14 * Graphic elements::
15 * Score elements::
16 * Items::
17 * Spanners::
18 * Future work::
19 * Coding standards::
20 * Making patches::
21 * Localisation::
22 @end menu
23
24 @node LilyPond internals,  , Top, Top
25 @menu
26 * Overview::                      Overview
27 * mudela::                        mudela
28 * Request_engraver::              Request_engraver
29 @end menu
30
31
32 @chapter Getting involved
33
34 Please help us make LilyPond a better program. You can help LilyPond in
35 several ways. Not all tasks requiring programming or understanding the
36 full source code.  You can write to the mailing list
37 (@email{gnu-music-discuss@@gnu.org} for more information)
38
39 @unnumberedsubsec Users
40
41 Mutopia needs your help. The mutopia project is a collection of public
42 domain sheet music. You can help the project by entering music and
43 submitting. Point your browser to the
44 @uref{http://sca.uwaterloo.ca/Mutopia, Mutopia webpage}
45
46 @unnumberedsubsec Font designers
47
48 Our set of glyphs (the Feta font) is far from complete.  If you know  a
49 little MetaFont you can contribute a glyph
50
51 @unnumberedsubsec Writers
52
53 The documentation of LilyPond and related utilities needs a lot of work.
54
55 @unnumberedsubsec Translators
56
57 LilyPond is completely ready for internationalized messages, but there
58 are only three translations so far.
59
60 @unnumberedsubsec Hackers
61
62 There are lots of possibilities of improving the program itself. There are
63 both small projects and big ones. Most of them are listed in the TODO
64 file.  A interesting and very big project is writing a GUI frontend to
65 LilyPond.
66
67
68 @unnumberedsubsec Website designers
69
70 The current website for LilyPond is neat and simple, but it is not very
71 pretty.  We would like to have a website with pretty pictures, one that
72 looks appealing to new users.
73
74
75 @chapter LilyPond internals
76
77
78 This documents some aspects of the internals of GNU LilyPond. Some of
79 this stuff comes from e-mail I wrote, some from e-mail others wrote,
80 some are large comments taken away from the headers. This page may be
81 a little incoherent.  Unfortunately, it is also quite outdated.  A
82 more thorough  and understandable document is in the works.
83
84 You should use @code{doc++} to take a peek at the sources.
85
86 @node Overview, mudela, Top, Top
87 @section Overview
88
89 GNU LilyPond is a "multi-pass" system. The different passes have been
90 created so that they do not depend on each other. In a later stage
91 some parts may be moved into libraries, or seperate programs, or they
92 might be integrated in larger systems.
93
94 @table @samp
95
96 @item Parsing:
97
98 No difficult algorithms. The .ly file is read, and converted to a list
99 of @code{Scores}, which each contain @code{Music} and paper/midi-definitions.
100
101 @item Interpreting music
102
103 The music is walked through in time-order. The iterators which do the
104 walking report Music to Translators which use this information to
105 create elements, either MIDI or "visual" elements. The translators
106 form a hierarchy; the ones for paper output are Engravers, for MIDI
107 Performers.
108
109 The translators swallow Music (mostly atomic gobs called Requests),
110 create elements, broadcast them to other translators on higher or same
111 level in the hierarchy:
112
113 The stem of a voice A is broadcast to the staff which contains A, but
114 not to the stems, beams and noteheads of a different voice (say B) or
115 a different staff. The stem and noteheads of A are coupled, because
116 the the Note_heads_engraver broadcasts its heads, and the Stem_engraver catches
117 these.
118
119 The engraver which agrees to handle a request decides whether to to
120 honor the request, ignore it, or merge it with other requests. Merging
121 of requests is preferably done with other requests done by members of
122 the same voicegroups (beams, brackets, stems). In this way you can put
123 the voices of 2 instruments in a conductor's score so they make chords
124 (the Beam requests of both instruments will be merged).
125
126 @item Prebreaking
127
128 Breakable stuff (eg. clefs and bars) are copied into pre and
129 postbreaks.
130
131 @item Preprocessing
132
133 Some dependencies are resolved, such as the direction of stems, beams,
134 and "horizontal" placement issues (the order of clefs,  keys etc,
135 placement of chords in multi-voice music), 
136
137 @item Break calculation:
138
139 The lines and horizontal positions of the columns are determined.
140
141 @item Breaking
142
143 Through some magical interactions with Line_of_score and Super_elem
144 (check out the source) the "lines" are produced.
145
146 All other spanners can figure across which lines they are spread. If
147 applicable, they break themselves into pieces. After this, each piece
148 (or, if there are no pieces, the original spanner itself) throws out
149 any dependencies which are in the wrong line.
150
151 @item Postprocesing:
152
153 Some items and all spanners need computation after the Paper_column
154 positions are determined. Examples: slurs, vertical positions of
155 staffs.
156
157 @item Output paper
158
159 @end table
160
161 @node mudela, Request_engraver, Overview, Top
162 @section mudela
163
164 Most information is stored in the form of a request.  In music
165 typesetting, the user might want to cram a lot more symbols on the
166 paper than actually fits. To reflect this idea (the user asks more
167 than we can do), the container for this data is called Request.
168
169 In a lot of other formats this would be called an 'Event'
170
171 @table @samp
172 @item @code{Barcheck_req}
173     Checks during music processing if start of this voice element
174     coincides with the start of a measure. Handy to check if you left out
175     some voice elts.
176 @item @code{Note_req}
177     LilyPond has to decide if the ball should be hanging left or
178     right. This influences the horizontal dimensions of a column, and this
179     is why request processing should be done before horizontal spacing.
180     Other voices' frivolities may cause the need for accidentals, so this
181     is also for the to decide. The engraver can decide on positioning based on
182     ottava commands and the appropriate clef.
183 @item @code{Rest_req}
184     Typeset a rest.
185 @item @code{Span_req}
186     This type of request typically results in the creation of a @code{Spanner}
187 @item @code{Beam_req}
188     Start/stop a beam.
189     Engraver has to combine this request with the stem_request, since the
190     number of flags that a stem wants to carry will determine the
191     number of beams.
192 @item @code{Dynamic}
193     Each dynamic is bound to one note (a crescendo spanning multiple
194     notes is thought to be made of two "dynamics": a start and a stop).
195     Dynamic changes can occur in a smaller time than the length of its
196     note, therefore each @code{Dynamic} request carries a time, measured
197     from the start of its note.
198 @end table
199
200 @node Request_engraver, , mudela, Top
201 @section Request_engraver
202
203 In the previous section the idea of Request has been explained, but
204 this only solves one half of the problem. The other half is deciding
205 which requests should be honored, which should merged with other
206 requests, and which should be ignored. Consider this input
207
208 @example 
209
210         \type Staff < % chord
211                 @{ \meter 2/4; [c8 c8] @}
212                 @{\meter 2/4;  [e8 e8] @}
213         >
214  
215 @end example 
216
217 Both the cs and es are part of a staff (they are in the same
218 Voice_group), so they should share meters, but the two [ ] pairs
219 should be merged.
220
221 The judge in this "allocation" problem a set of brokers: the requests
222 are transmitted to so-called engravers which respond if they want to
223 accept a request eg, the @code{Notehead_engraver} will accept
224 @code{Note_req}s, and turn down @code{Slur_req}s. If the Music_iterator
225 cannot find a engraver that wants the request, it is junked (with a
226 warning message).
227
228 After all requests have been either assigned, or junked, the Engraver
229 will process the requests (which usually means creating an @code{Item}
230 or @code{Spanner}). If a @code{Request_engraver} creates something, it
231 tells the enclosing context. If all items/spanners have been created,
232 then each Engraver is notified of any created Score_element, via a
233 broadcasting system.
234
235 @unnumberedsubsec example:
236
237 @example 
238
239         c4
240  
241 @end example 
242
243 produces:
244
245 @example 
246
247         Note_request (duration 1/4)
248         Stem_request (duration 1/4)
249  
250 @end example 
251
252 Note_request will be taken by a @code{Notehead_engraver}, stem_request
253 will be taken by a @code{Stem_beam_engraver}. @code{Notehead_engraver}
254 creates a @code{Notehead}, @code{Stem_beam_engraver} creates a
255 @code{Stem}. Both announce this to the Staff_engraver. Staff_engraver
256 will tell @code{Stem_beam_engraver} about the @code{Notehead}, which
257 will add the @code{Notehead} to the @code{Stem} it just created.
258
259 To decide on merging, several engravers have been grouped. Please
260 check @file{init/engraver.ly}.
261
262
263
264 @node Graphic elements, , , Top 
265 @section Graphic elements
266
267
268 Music notation is composed of a sets of interrelated glyphs.  In
269 Lilypond every glyph usually is represented by one object, a so-called
270 Graphic Object.  The primary relations between graphic objects involve
271 positions:
272
273 @itemize @asis
274 @item consecutive notes are printed left to right, grouped  in a staff
275 @item simultaneous notes are horizontally aligned (internally grouped in
276 a paper column).
277 @item  the staccato mark is horizontally centered on the note it applies
278 to.
279 @end itemize
280
281 The abstract encoding of such relations is done with the concept
282 @dfn{reference point}.  The reference point (in X direction) of the
283 staccato mark is the note it applies to.  The (X) position of the
284 staccato mark is stored relative to the position of the note head.  This
285 means that the staccato will always maintain a fixed offset wrt to the
286 note head, whereever the head is moved to.
287
288 In the same vein, all notes on a staff have their Y positions stored
289 relative to an abstract object called Axis_group_spanner.  If the
290 Axis_group_spanner of one staff is moved, the absolute Y positions of
291 all objects in that spanner change along, in effect causing the staff
292 and all its contents to move as a whole.
293
294 Each graphic object stores a pointer and an relative offset for each
295 direction: one for the X-axis, one for the Y-axis.  For example, the X
296 parent of a Note_head usually is a Note_column.  The X parent of a
297 Note_column usually is either a Collision or a Paper_column. The X
298 parent of a Collision usually is a Paper_column.  If the Collision
299 moves, all Note_heads that have that Collision as parent also move, but
300 the absolute position of the Paper_column does not change.
301
302 To build a graphical score with Graphic_elements, conceptually, one
303 needs to have one Root object (in Lilypond: Line_of_score), and
304 recursively attach objects to the Root.   However, due to the nature
305 of the context selection mechanisms, it turns out to be more
306 advantageous to construct the tree the other way around: first small
307 trees (note heads, barlines etc.) are created, and these are
308 subsequently composed into larger trees, which are finally hung on a
309 Paper_column (in X direction) or Line_of_score (in Y direction). 
310
311 The structure of the X,Y parent relations are determined by the
312 engravers and notation contexts:
313
314 The most important X-axis parent relation depends on the timing: notes
315 that come earlier are attached to Paper_column that will be positioned
316 more to the left.
317
318 The most important Y-axis relation depends on containment of contexts:
319 notes (created in a Thread or Voice context) are put in the staff where
320 the originating context lives in.
321
322 Graphical_axis_groups are special graphic objects, that are designed to
323 function as a parent.  The size of a Graphical_axis_groups group is the
324 union of its children.
325
326 @node Score elements, ,  , Top
327
328 Besides relative positions there are lots of other relations between
329 elements. Lilypond does not contain other specialized relation
330 management (Like the relative positioning code).  Instead, objects can
331 be connected through dependencies, which sets the order in which objects
332 are to be processed.
333
334 Example: the direction of a beamed stem should equal the direction of
335 the beam.  When the stem is a added to the beam, a dependency on the
336 beam is set in the stem: this means that @code{Beam::do_pre_processing
337 ()} (which does various direction related things) will be called before
338 @code{Stem::do_pre_processing ()}.
339
340 The code that manages dependencies resides in the class
341 @code{Score_element}, a derived class of @code{Graphical_element}.  The
342 bulk of the code handles line breaking related issues.
343
344 To sketch the problems with line breaking: suppose a slur spans a line
345 break,
346 @example
347
348 c4(  c'''' c | \break d d )d
349
350 @end example
351 In this case, the slur will appear as two parts, the first part spanning
352 the first three notes (the @code{c}s), the second spanning the last
353 three (the @code{d}s).  Within Lilypond this is modeled as breaking the
354 slur in parts: from the Original slur, two new clones of the old slur
355 are made. Initially both clones depend on the six notes.  After the
356 hairy code in Score_element, Spanner and Item which does substitutions
357 in sets of dependencies, the first clone depends on the first three
358 notes, the second on the last three.
359
360 The major derived classes of Score_element are Item and  Spanner.
361 An item has one horizontal position.  A spanner hangs on two  items.
362
363 @node Items, , , Top
364 @section Items
365
366
367
368 An item is a score element that is associated with only one
369 Paper_column. Examples are note heads, clefs, super and superscripts, etc.
370 Item is a derived class of Score_element.
371
372 The shape of an item is known before the break calculations, and line
373 spacing depends on the size of items: very wide items need more space
374 than very small ones.
375
376 An additional complication is the behavior of items at linebreaks.  For
377 example, when you do a time signature change, you get only one symbol.
378 If it occurs at a linebreak, the new time signature must be printed both
379 before and after the linebreak.  Other `breakable symbols' such as
380 clefs, and bar lines also exhibit this behavior. 
381
382 if a line of music is broken, the next line usually gets a clef. So in
383 TeX terms, the clef is a postbreak. The same thing happens with meter
384 signs: Normally the meter follows the bar. If a line is broken at that
385 bar, the bar along with the meter stays on the "last" line, but the next
386 line also gets a meter sign after the clef.   To support this,
387 breakable items are generated in the three versions: original
388 (unbroken), left (before line break) and right (after line break).
389 During the line spacing, these versions are used to try how the spacing
390 of a  line works out.
391
392 Once the definitive spacing is determined, dependencies (and various
393 other pointers) are substituted such that all dependencies point at the
394 active items: either they point at the original, or they point at left
395 and right.
396
397 @node Spanners, , , Top
398 @section Spanners
399
400 Spanners are symbols that are of variable shape, eg. Slurs, beams, etc.
401 Spanners is a derived class of Score_element.
402
403 The final shape can only be determined after the line breaking process.
404 All spanners are spanned on two items, called the left and right
405 boundary item.  The X reference point is the left boundary item.
406
407
408 @node Future work, , , Top
409 @section Future work
410
411 There are plans to unify Spanner and Item, so there will no longer be
412 such a clear distinction between the two.  Right now, Score_elements are
413 always either Item or either Spanner.
414
415 Most of the properties of a graphic object are now member variables of
416 the classes involved.  To offer configurability, we want to move these
417 variables to scheme (GUILE) variables, and no longer use C++ code to
418 calculate them, but use Scheme functions.
419
420 @node Coding standards,  , , Top
421
422 @chapter CodingStyle - standards while programming for GNU
423 LilyPond
424
425 Functions and methods do not return errorcodes.
426
427
428 @unnumberedsubsec Languages
429
430 C++ and Python are preferred.  Perl is not.  Python code should use an
431 indent of 8, using TAB characters.
432
433 @unnumberedsubsec Filenames
434
435 Definitions of classes that are only accessed via pointers
436 (*) or references (&) shall not be included as include files.
437
438 filenames
439
440 @example 
441         ".hh"   Include files
442         ".cc"   Implementation files
443         ".icc"  Inline definition files
444         ".tcc"  non inline Template defs
445 @end example 
446
447 in emacs:
448
449 @example 
450         (setq auto-mode-alist
451               (append '(("\\.make$" . makefile-mode)
452                         ("\\.cc$" . c++-mode)
453                         ("\\.icc$" . c++-mode)
454                         ("\\.tcc$" . c++-mode)
455                         ("\\.hh$" . c++-mode)
456                         ("\\.pod$" . text-mode)         
457                         )
458                       auto-mode-alist))
459 @end example 
460
461
462 The class Class_name_abbreviation is coded in @file{class-name-abbr.*}
463
464 @unnumberedsubsec Indentation
465
466 Standard GNU coding style is used.   In emacs:
467
468 @example 
469         (add-hook 'c++-mode-hook
470                   '(lambda() (c-set-style "gnu")
471                      )
472                   )
473 @end example 
474
475 If you like using font-lock, you can also add this to your @file{.emacs}:
476
477 @example 
478         (setq font-lock-maximum-decoration t)
479         (setq c++-font-lock-keywords-3 
480               (append
481                c++-font-lock-keywords-3
482                '(("\\b\\([a-zA-Z_]+_\\)\\b" 1 font-lock-variable-name-face)
483                ("\\b\\([A-Z]+[a-z_]+\\)\\b" 1 font-lock-type-face))
484                ))
485 @end example 
486
487 @unnumberedsubsec Classes and Types
488
489 @example 
490         This_is_a_class
491 @end example 
492
493 @unnumberedsubsec Members
494
495 @example 
496         Class::member ()
497         Type Class::member_type_
498         Type Class::member_type ()
499 @end example 
500
501 the @code{type} is a Hungarian notation postfix for @code{Type}. See below
502
503 @unnumberedsubsec Macros
504
505 Macros should be written completely in uppercase
506
507 The code should not be compilable if proper macro declarations are not
508 included. 
509
510 Don't laugh. It took us a whole evening/night to figure out one of
511 these bugs, because we had a macro that looked like
512 @code{DECLARE_VIRTUAL_FUNCTIONS ()}. 
513
514 @unnumberedsubsec Broken code
515
516 Broken code (hardwired dependencies, hardwired constants, slow
517 algorithms and obvious limitations) should be marked as such: either
518 with a verbose TODO, or with a short "ugh" comment.
519
520 @unnumberedsubsec Comments
521
522 The source is commented in the DOC++ style.  Check out doc++ at
523 @uref{http://www.zib.de/Visual/software/doc++/index.html}
524
525 @example 
526
527         /*
528                 C style comments for multiline comments.
529                 They come before the thing to document.
530                 [...]
531         */
532
533         /**
534                 short description.
535                 Long class documentation.
536                 (Hungarian postfix)
537
538                 TODO Fix boring_member ()
539         */
540         class Class @{
541                 /**
542                   short description.
543                   long description
544                 */
545
546                 Data data_member_;
547
548                 /**
549                         short memo. long doco of member ()
550                         @@param description of arguments
551                         @@return Rettype
552                 */
553                 Rettype member (Argtype);
554
555                 /// memo only
556                 boring_member () @{
557                         data_member_ = 121; // ugh
558                 @}
559         @};
560  
561 @end example 
562
563         
564 Unfortunately most of the code isn't really documented that good.
565
566 @unnumberedsec Hungarian notation naming convention
567
568 Proposed is a naming convention derived from the so-called
569 @emph{Hungarian Notation}.  Macros, @code{enum}s and @code{const}s are all
570 uppercase, with the parts of the names separated by underscores.
571
572 The hungarian notation  is to be used when variables are not declared
573 near usage (mostly in member variables and functions).
574
575 @unnumberedsubsec Types
576
577 @table @samp
578 @item @code{byte}
579     unsigned char. (The postfix _by is ambiguous)
580 @item @code{b}
581     bool
582 @item @code{bi}
583     bit
584 @item @code{ch}
585     char
586 @item @code{f}
587     float
588 @item @code{i}
589     signed integer
590 @item @code{str}
591     string class
592 @item @code{sz}
593     Zero terminated c string
594 @item @code{u}
595     unsigned integer
596 @end table
597
598 @unnumberedsubsec User defined types
599
600 @example 
601
602         /** Slur blah. blah.
603         (slur)
604         */
605         class Slur @{@};
606         Slur* slur_p = new Slur;
607  
608 @end example 
609
610 @unnumberedsubsec Modifiers
611
612 The following types modify the meaning of the prefix. 
613 These are preceded by the prefixes:
614
615 @table @samp
616 @item @code{a}
617     array
618 @item @code{array}
619     user built array.
620 @item @code{c}
621     const. Note that the proper order is @code{Type const}
622     i.s.o. @code{const Type}
623 @item @code{C}
624     A const pointer. This would be equivalent to @code{_c_l}, but since any
625     "const" pointer has to be a link (you can't delete a const pointer),
626     it is superfluous.
627 @item @code{l}
628     temporary pointer to object (link)
629 @item @code{p}
630     pointer to newed object
631 @item @code{r}
632     reference
633 @end table
634
635 @unnumberedsubsec Adjective
636
637 Adjectives such as global and static should be spelled out in full.
638 They come before the noun that they refer to, just as in normal english.
639
640 @example 
641
642 foo_global_i: a global variable of type int commonly called "foo".
643  
644 @end example 
645
646 static class members do not need the static_ prefix in the name (the
647 Class::var notation usually makes it clear that it is static)
648
649 @table @samp
650 @item @code{loop_i}
651     Variable loop: an integer
652 @item @code{u}
653     Temporary variable: an unsigned integer
654 @item @code{test_ch}
655     Variable test: a character
656 @item @code{first_name_str}
657     Variable first_name: a String class object
658 @item @code{last_name_ch_a}
659     Variable last_name: a @code{char} array
660 @item @code{foo_i_p}
661     Variable foo: an @code{Int*} that you must delete
662 @item @code{bar_i_l}
663     Variable bar: an @code{Int*} that you must not delete
664 @end table
665
666 Generally default arguments are taboo, except for nil pointers.
667
668 The naming convention can be quite conveniently memorised, by
669 expressing the type in english, and abbreviating it
670
671 @example 
672
673         static Array<int*> foo
674  
675 @end example 
676
677 @code{foo} can be described as "the static int-pointer user-array", so you get
678
679 @example 
680
681         foo_static_l_arr
682  
683 @end example 
684
685
686 @unnumberedsec Miscellaneous
687     
688 For some tasks, some scripts are supplied, notably creating patches, a
689 mirror of the website, generating the header to put over cc and hh
690 files, doing a release.
691
692 Use them.
693
694 @node Making patches,  , , Top
695
696
697 @unnumberedsec name
698     
699
700 PATCHES - track and distribute your code changes
701
702 This page documents how to distribute your changes to GNU lilypond
703     
704 We would like to have unified context diffs with full pathnames.  A
705 script automating supplied with Lily.
706
707 Distributing a change normally goes like this:
708
709 @itemize @bullet
710 @item make your fix/add your code 
711 @item Add changes to CHANGES, and add yourself to Documentation/topdocs/AUTHORS.texi
712 @item generate a patch, 
713 @item e-mail your patch to one of the mailing lists
714     gnu-music-discuss@@gnu.org or bug-gnu-music@@gnu.org
715 @end itemize
716
717 Please do not send entire files, even if the patch is bigger than the
718 original.  A patch makes it clear what is changed, and it won't
719 overwrite previous (not yet released) changes.
720
721 @unnumberedsec Generating a patch
722
723 Simple version: run
724
725 @example
726         make -C lilypond-x.y.z/ distclean
727         make -C lilypond-x.y.z.NEW/ distclean
728         diff -urN lilypond-x.y.z/ lilypond-x.y.z.NEW/
729 @end example
730
731 Complicated (but automated) version:
732
733 In @file{VERSION}, set MY_PATCH_LEVEL:
734
735 @example 
736
737     VERSION:
738         ...
739         MY_PATCH_LEVEL=jcn1
740  
741 @end example 
742
743 In @file{CHANGES}, enter a summary of changes:
744
745 @example 
746         pl 0.1.73.jcn1
747                 - added PATCHES.texi
748 @end example 
749
750 Then, from the top of Lily's source tree, type
751
752 @example 
753     make release
754 @end example 
755
756 These handy python scripts assume a directory structure which looks
757 like:
758
759 @example 
760
761     lilypond -> lilypond-x.y.z   # symlink to development directory
762     lilypond-x.y.z/              # current development
763     patches/                     # patches between different releases
764     releases/                    # .tar.gz releases
765
766 @end example 
767
768 (Some scripts also assume this lives in  @file{$HOME/usr/src}).
769
770         
771 @unnumberedsec Applying patches
772     
773
774 If you're following LilyPond development regularly, you probably want to
775 download just the patch for each subsequent release.
776 After downloading the patch (into the patches directory, of course), simply 
777 apply it:
778
779 @example 
780
781     gzip -dc ../patches/lilypond-0.1.74.diff.gz | patch -p1 -E
782  
783 @end example 
784
785 and don't forget to make automatically generated files:
786
787 @example 
788
789     autoconf footnote(patches don't include automatically generated files, 
790     i.e. file(configure) and files generated by file(configure).)
791
792     configure
793  
794 @end example 
795
796 @node Localisation, , , Top 
797
798 @chapter Localisation - User messages in LilyPond
799
800 @section Introduction
801
802 This document provides some guidelines for uniformising user messages.
803 In the absence of other standards, we'll be using these rules when coding
804 for for LilyPond@footnote{
805 In addition to the C++ coding standards that come with Lily
806 }.  Hopefully, this can be replaced by general GNU
807 guidelines in the future.  
808
809 Not-preferred messages are marked with @code{+}.
810 By convention, agrammatical examples are marked with @code{*}.
811
812
813 @section Guidelines
814
815 @itemize @bullet
816
817 @item
818 Every message to the user should be localised (and thus be marked
819 for localisation).  This includes warning and error messages.
820
821 @item
822 Don't localise/gettextify:
823
824 @itemize @minus
825 @item @code{programming_error ()}s
826 @item @code{programming_warning ()}s
827 @item debug strings
828 @item output strings (PostScript, TeX)@footnote{
829 This may seem ridiculously obvious, however, makeinfo-3.12s localises
830 output strings.  Sending bug report now ---jcn
831 }
832 @end itemize
833
834
835
836 @item
837 Messages to be localised must be encapsulated in @code{_ (STRING)}
838 or @code{_f (FORMAT, ...)}.  Eg:
839
840 @example
841 warning (_ ("Need music in a score"));
842 error (_f ("Can't open file: `%s'", file_name));
843 @end example
844
845 In some rare cases you may need to call @code{gettext ()} by hand.
846 This happens when you pre-define (a list of) string constants for later
847 use.  In that case, you'll probably also need to mark these string
848 constants for translation, using @code{_i (STRING)}.  The @code{_i}
849 macro is a no-op, it only serves as a marker for @file{xgettext}.
850
851 @example
852 char const* messages[] = @{
853   _i ("enable debugging output"),
854   _i ("ignore mudela version"),
855   0
856 @};
857
858 void
859 foo (int i)
860 @{
861   puts (gettext (messages [i]));
862 @}
863 @end example
864
865 See also
866 @file{flower/getopt-long.cc} and @file{lily/main.cc}.
867
868 @item
869 Don't use leading or trailing whitespace in messages.
870
871 @item
872 Messages containing a final verb, or a gerund (@code{-ing}-form)
873 always start with a capital.  Other (simpler) messages start with
874 a lowercase letter:
875
876 @example
877 The word `foo' is not declared.
878 `foo': not declared.
879 Not declaring: `foo'.
880 @end example
881
882 @item
883 To avoid having a number of different messages for the same situation,
884 we'll use quoting like this @code{"message: `%s'"} for all strings.
885 Numbers are not quoted:
886
887 @example
888 _f ("Can't open file: `%s'", name_str)
889 _f ("Can't find charater number: %d", i)
890 @end example
891
892 @item
893 Think about translation issues.  
894 In a lot of cases,it's better to translate a whole message.
895 The english grammar mustn't be imposed on the translator.
896 So, iso
897
898 @example
899 _ ("Stem at ") + moment.str () + _(" doen't fit in beam")
900 @end example
901
902 @noindent
903 have
904
905 @example
906 _f ("Stem at %s doen't fit in beam", moment.str ())
907 @end example
908
909 @item
910 Split up multi-sentence messages, whenever possible.  Instead of
911
912 @example
913 warning (_f ("out of tune!  Can't find: `%s', "Key_engraver"));
914
915 warning (_f ("Can't find font `%s', loading default", 
916              font_name));
917 @end example
918
919 @noindent
920 rather say:
921
922 @example
923 warning (_ ("out of tune:");
924 warning (_f ("Can't find: `%s', "Key_engraver"));
925
926 warning (_f ("Can't find font: `%s', font_name));
927 warning (_f ("Loading default font"));
928 @end example
929
930 @item
931 If you must have multiple-sentence messages, use full punctuation.
932 Use two spaces after end of sentence punctuation.
933 No punctuation (esp. period) is used at the end of simple messages.
934
935 @example
936    _f ("Non-matching braces in text `%s', adding braces", text)
937    _ ("Debug output disabled.  Compiled with NPRINT.")
938    _f ("Huh?  Not a Request: `%s'.  Ignoring.", request)
939 @end example
940
941 @item
942 Don't modularise too much; a lot of words cannot be translated
943 without context.
944 It's probably safe to treat most occurences of words like
945 stem, beam, crescendo as separately translatable words.
946
947 @item
948 When translating, it is preferrable to put interesting information 
949 at the end of the message, rather than embedded in the middle.
950 This especially applies to frequently used messages, even if this
951 would mean sacrificing a bit of eloquency.  This holds for original
952 messages too, of course.
953
954 @example
955     en: can't open: `foo.ly'
956 +   nl: kan `foo.ly' niet openen (1)
957     kan niet openen: `foo.ly'*   (2)
958     niet te openen: `foo.ly'*    (3)
959 @end example
960
961 The first nl message, although gramatically and stylishly correct,
962 is not friendly for parsing by humans (even if they speak dutch).
963 I guess we'd prefer something like (2) or (3).
964
965 @item
966 Please don't run make po/po-update with GNU gettext < 0.10.35
967
968 @end itemize
969
970 @bye
971
972     
973
974 @bye
975
976