]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/development.itexi
9165ff38ab1cdbacdb0799b27bb61c0efa3f3dc1
[lilypond.git] / Documentation / user / development.itexi
1 @c -*-texinfo-*-
2
3 @c Move chapter
4
5 @node Development
6 @chapter Development
7
8 @menu
9 * CodingStyle::
10 * Making patches::
11 * Localisation::
12 * Helping with development:: 
13 @end menu
14
15 @node CodingStyle
16 @section CodingStyle - standards while programming for GNU LilyPond
17
18 As a general rule, you should always try to continue computations, even
19 if there is some kind of error. When the program stops, it is often very
20 hard for a user to pinpoint what part of the input causes an
21 error. Finding the culprit is much easier if there is some viewable
22 output.
23
24 So functions and methods do not return errorcodes, they never crash, but
25 report a programming_error and try to carry on.
26
27 @unnumberedsubsec Languages
28
29 C++ and Python are preferred.  Python code should use an indent of 8,
30 using TAB characters.
31
32 @unnumberedsubsec Filenames
33
34 Definitions of classes that are only accessed via pointers
35 (*) or references (&) shall not be included as include files.
36
37 filenames
38
39 @example 
40         ".hh"   Include files
41         ".cc"   Implementation files
42         ".icc"  Inline definition files
43         ".tcc"  non inline Template defs
44 @end example 
45
46 in emacs:
47
48 @example 
49         (setq auto-mode-alist
50               (append '(("\\.make$" . makefile-mode)
51                         ("\\.cc$" . c++-mode)
52                         ("\\.icc$" . c++-mode)
53                         ("\\.tcc$" . c++-mode)
54                         ("\\.hh$" . c++-mode)
55                         ("\\.pod$" . text-mode)         
56                         )
57                       auto-mode-alist))
58 @end example 
59
60
61 The class Class_name is coded in @file{class-name.*}
62
63 @unnumberedsubsec Indentation
64
65 Standard GNU coding style is used.   In emacs:
66
67 @example 
68         (add-hook 'c++-mode-hook
69                   '(lambda() (c-set-style "gnu")
70                      )
71                   )
72 @end example 
73
74 If you like using font-lock, you can also add this to your @file{.emacs}:
75
76 @example 
77         (setq font-lock-maximum-decoration t)
78         (setq c++-font-lock-keywords-3 
79               (append
80                c++-font-lock-keywords-3
81                '(("\\b\\([a-zA-Z_]+_\\)\\b" 1 font-lock-variable-name-face)
82                ("\\b\\([A-Z]+[a-z_]+\\)\\b" 1 font-lock-type-face))
83                ))
84 @end example 
85
86 @unnumberedsubsec Classes and Types
87
88 @example 
89         This_is_a_class
90 @end example 
91
92 @unnumberedsubsec Members
93
94 @example 
95         Class::member ()
96         Type Class::member_type_
97         Type Class::member_type ()
98 @end example 
99
100 the @code{type} is a Hungarian notation postfix for @code{Type}. See below
101
102 @unnumberedsubsec Macros
103
104 Macro names should be written in uppercase completely.
105
106 @unnumberedsubsec Broken code
107
108 Try not to write broken code. This includes hardwired dependencies,
109 hardwired constants, slow algorithms and obvious limitations. If you can
110 not avoid it, mark the place clearly, and add a comment explaining
111 shortcomings of the code.
112
113 @unnumberedsec Hungarian notation naming convention
114
115 The C++ part of LilyPond uses a naming convention derived from the
116 so-called @emph{Hungarian Notation}.  Macros, @code{enum}s and
117 @code{const}s are all uppercase, with the parts of the names separated
118 by underscores.
119
120 The hungarian notation  is to be used when variables are not declared
121 near usage (mostly in member variables and functions).
122
123 @unnumberedsubsec Types
124
125 @table @code
126 @item @code{byte}
127     unsigned char. (The postfix _by is ambiguous)
128 @item @code{b}
129     bool
130 @item @code{bi}
131     bit
132 @item @code{ch}
133     char
134 @item @code{f}
135     float
136 @item @code{i}
137     signed integer
138 @item @code{str}
139     string class
140 @item @code{sz}
141     Zero terminated c string
142 @item @code{u}
143     unsigned integer
144 @end table
145
146 @unnumberedsubsec User defined types
147
148 @example 
149
150         /*
151                 Slur blah. blah.
152         */
153         class Slur @{
154                 ...
155         @};
156         Slur* slur_p = new Slur;
157  
158 @end example 
159
160 @unnumberedsubsec Modifiers
161
162 The following types modify the meaning of the prefix. 
163 These are preceded by the prefixes:
164
165 @table @code
166 @item @code{a}
167     array
168 @item @code{arr}
169     user built array.
170 @item @code{c}
171     const. Note that the proper order is @code{Type const}
172         and not @code{const Type}
173 @item @code{C}
174     A const pointer. This would be equivalent to @code{_c_l}, but since any
175     "const" pointer has to be a link (you can't delete a const pointer),
176     it is superfluous.
177 @item @code{l}
178     temporary pointer to object (link)
179 @item @code{p}
180     pointer to newed object
181 @item @code{r}
182     reference
183 @end table
184
185 @unnumberedsubsec Adjective
186
187 Adjectives such as global and static should be spelled out in full.
188 They come before the noun that they refer to, just as in normal english.
189
190 @example 
191
192 foo_global_i: a global variable of type int commonly called "foo".
193  
194 @end example 
195
196 static class members do not need the static_ prefix in the name (the
197 Class::var notation usually makes it clear that it is static)
198
199 @table @code
200 @item @code{loop_i}
201     Variable loop: an integer
202 @item @code{u}
203     Temporary variable: an unsigned integer
204 @item @code{test_ch}
205     Variable test: a character
206 @item @code{first_name_str}
207     Variable first_name: a String class object
208 @item @code{last_name_ch_a}
209     Variable last_name: a @code{char} array
210 @item @code{foo_i_p}
211     Variable foo: an @code{Int*} that you must delete
212 @item @code{bar_i_l}
213     Variable bar: an @code{Int*} that you must not delete
214 @end table
215
216 Generally default arguments are taboo, except for nil pointers.
217
218 The naming convention can be quite conveniently memorised, by
219 expressing the type in english, and abbreviating it
220
221 @example 
222
223         static Array<int*> foo
224  
225 @end example 
226
227 @code{foo} can be described as "the static int-pointer user-array", so you get
228
229 @example 
230
231         foo_static_l_arr
232  
233 @end example 
234
235
236 @unnumberedsec Miscellaneous
237     
238 For some tasks, some scripts are supplied, notably creating patches, a
239 mirror of the website, generating the header to put over cc and hh
240 files, doing a release.
241
242 Use them.
243
244 @node Making patches
245 @section Making patches
246
247 @unnumberedsec  Track and distribute your code changes
248
249 This page documents how to distribute your changes to GNU lilypond
250     
251 We would like to have unified context diffs with full pathnames.  A
252 script automating supplied with Lily.
253
254 Distributing a change normally goes like this:
255
256 @itemize @bullet
257 @item make your fix/add your code 
258 @item Add changes to CHANGES, and add yourself to Documentation/topdocs/AUTHORS.texi
259 @item generate a patch, 
260 @item e-mail your patch to one of the mailing lists
261     gnu-music-discuss@@gnu.org or bug-gnu-music@@gnu.org
262 @end itemize
263
264 Please do not send entire files, even if the patch is bigger than the
265 original.  A patch makes it clear what is changed, and it won't
266 overwrite previous (not yet released) changes.
267
268 @unnumberedsec Generating a patch
269
270 Simple version: run
271
272 @example
273         make -C lilypond-x.y.z/ distclean
274         make -C lilypond-x.y.z.NEW/ distclean
275         diff -urN lilypond-x.y.z/ lilypond-x.y.z.NEW/
276 @end example
277
278 Complicated (but automated) version:
279
280 In @file{VERSION}, set MY_PATCH_LEVEL:
281
282 @example 
283
284     VERSION:
285         ...
286         MY_PATCH_LEVEL=jcn1
287  
288 @end example 
289
290 In @file{CHANGES}, enter a summary of changes:
291
292 @example 
293         0.1.73.jcn1
294         ===========
295
296         * A concise, yet clearly readable description of what changed.
297
298 @end example 
299
300 Then, from the top of Lily's source tree, type
301
302 @example 
303     make release
304 @end example 
305
306 These handy python scripts assume a directory structure which looks
307 like:
308
309 @example 
310
311     lilypond -> lilypond-x.y.z   # symlink to development directory
312     lilypond-x.y.z/              # current development
313     patches/                     # patches between different releases
314     releases/                    # .tar.gz releases
315
316 @end example 
317
318 @unnumberedsec Applying patches
319
320 [outdated: please use xdeltas]
321
322 If you're following LilyPond development regularly, you probably want to
323 download just the patch for each subsequent release.
324 After downloading the patch (into the patches directory, of course), simply 
325 apply it:
326
327 @example 
328
329     gzip -dc ../patches/lilypond-0.1.74.diff.gz | patch -p1 -E
330  
331 @end example 
332
333 and don't forget to make automatically generated files:
334
335 @example 
336
337     autoconf footnote(patches don't include automatically generated files, 
338     i.e. file(configure) and files generated by file(configure).)
339
340     configure
341  
342 @end example 
343
344 @node Localisation
345 @section Localisation - User messages in LilyPond
346
347 This document provides some guidelines for uniformising user messages.
348 In the absence of other standards, we'll be using these rules when coding
349  for LilyPond.  Hopefully, this can be replaced by general GNU
350 guidelines in the future.
351
352 Not-preferred messages are marked with @code{+}.  By convention,
353 agrammatical examples are marked with @code{*}.
354
355 @subsection Guidelines
356
357 @itemize @bullet
358
359 @item
360 Every message to the user should be localised (and thus be marked
361 for localisation).  This includes warning and error messages.
362
363 @item
364 Don't localise/gettextify:
365
366 @itemize @minus
367 @item @code{programming_error ()}s
368 @item @code{programming_warning ()}s
369 @item debug strings
370 @item output strings (PostScript, TeX)
371 @end itemize
372
373 @item
374 Messages to be localised must be encapsulated in @code{_ (STRING)}
375 or @code{_f (FORMAT, ...)}.  Eg:
376
377 @example
378 warning (_ ("Need music in a score"));
379 error (_f ("Can't open file: `%s'", file_name));
380 @end example
381
382 In some rare cases you may need to call @code{gettext ()} by hand.
383 This happens when you pre-define (a list of) string constants for later
384 use.  In that case, you'll probably also need to mark these string
385 constants for translation, using @code{_i (STRING)}.  The @code{_i}
386 macro is a no-op, it only serves as a marker for @file{xgettext}.
387
388 @example
389 char const* messages[] = @{
390   _i ("enable debugging output"),
391   _i ("ignore lilypond version"),
392   0
393 @};
394
395 void
396 foo (int i)
397 @{
398   puts (gettext (messages [i]));
399 @}
400 @end example
401
402 See also
403 @file{flower/getopt-long.cc} and @file{lily/main.cc}.
404
405 @item
406 Don't use leading or trailing whitespace in messages.
407
408 @item
409 Messages containing a final verb, or a gerund (@code{-ing}-form)
410 always start with a capital.  Other (simpler) messages start with
411 a lowercase letter:
412
413 @example
414 The word `foo' is not declared.
415 `foo': not declared.
416 Not declaring: `foo'.
417 @end example
418
419 @item
420 To avoid having a number of different messages for the same situation,
421 we'll use quoting like this @code{"message: `%s'"} for all strings.
422 Numbers are not quoted:
423
424 @example
425 _f ("Can't open file: `%s'", name_str)
426 _f ("Can't find charater number: %d", i)
427 @end example
428
429 @item
430 Think about translation issues.  In a lot of cases, it is better to
431 translate a whole message.  The english grammar mustn't be imposed on
432 the translator.  So, iso
433
434 @example
435 _ ("Stem at ") + moment.str () + _(" doen't fit in beam")
436 @end example
437
438 @noindent
439 have
440
441 @example
442 _f ("Stem at %s doen't fit in beam", moment.str ())
443 @end example
444
445 @item
446 Split up multi-sentence messages, whenever possible.  Instead of
447
448 @example
449 warning (_f ("out of tune!  Can't find: `%s', "Key_engraver"));
450
451 warning (_f ("Can't find font `%s', loading default", 
452              font_name));
453 @end example
454
455 @noindent
456 rather say:
457
458 @example
459 warning (_ ("out of tune:");
460 warning (_f ("Can't find: `%s', "Key_engraver"));
461
462 warning (_f ("Can't find font: `%s', font_name));
463 warning (_f ("Loading default font"));
464 @end example
465
466 @item
467 If you must have multiple-sentence messages, use full punctuation.
468 Use two spaces after end of sentence punctuation.
469 No punctuation (esp. period) is used at the end of simple messages.
470
471 @example
472    _f ("Non-matching braces in text `%s', adding braces", text)
473    _ ("Debug output disabled.  Compiled with NPRINT.")
474    _f ("Huh?  Not a Request: `%s'.  Ignoring.", request)
475 @end example
476
477 @item
478 Don't modularise too much; a lot of words cannot be translated
479 without context.
480 It's probably safe to treat most occurences of words like
481 stem, beam, crescendo as separately translatable words.
482
483 @item
484 When translating, it is preferrable to put interesting information 
485 at the end of the message, rather than embedded in the middle.
486 This especially applies to frequently used messages, even if this
487 would mean sacrificing a bit of eloquency.  This holds for original
488 messages too, of course.
489
490 @example
491     en: can't open: `foo.ly'
492 +   nl: kan `foo.ly' niet openen (1)
493     kan niet openen: `foo.ly'*   (2)
494     niet te openen: `foo.ly'*    (3)
495 @end example
496
497 The first nl message, although gramatically and stylishly correct,
498 is not friendly for parsing by humans (even if they speak dutch).
499 I guess we'd prefer something like (2) or (3).
500
501 @item
502 Please don't run make po/po-update with GNU gettext < 0.10.35
503
504 @end itemize
505
506 @node Helping with development
507 @section Getting involved
508
509 If you want to help developing  LilyPond your  efforts are appreciated.
510 You can help LilyPond in several ways. Not all tasks requiring
511 programming or understanding the full source code.
512
513 Please don't expect us to give you instructions on what you should
514 do. We're just a bunch of simple hackers, and we're absolutely
515 incompetent about management, design in advance, delegating work.
516 Some people write to us "I want to help, what should I do?", but we
517 never know what to answer them.
518
519 If you want to hack, just start hacking. You can send us the result as
520 a patch, and we'll gladly incorporate it.
521
522 If you need some hints on where to get started: there are a number of
523 specific areas where you could do work.  
524
525 @unnumberedsubsec Users
526
527 Mutopia needs your help. The mutopia project is a collection of public
528 domain sheet music. You can help the project by entering music (either
529 by hand, or by converting from scans or MIDI) and submitting it. Point
530 your browser to the @uref{http://sca.uwaterloo.ca/Mutopia, Mutopia
531 webpage}.
532
533 @unnumberedsubsec Writers
534
535 The documentation of LilyPond and related utilities needs a lot of
536 work. The documentation is written in
537 @uref{http://www.gnu.org/software/texinfo,texinfo}. The documentation of
538 LilyPond is sorely lacking in terms of completeness, depth and
539 organisation.
540
541 Write if you know how to write english documentation in texinfo, and
542 know about music and music notation.  You must also know how to use
543 LilyPond (or be prepared to learn using it).  The task is not especially
544 hard, but it is a lot of work, and you must be familiar with LilyPond.
545
546 @unnumberedsubsec Translators
547
548 LilyPond is completely ready for internationalized messages, but there
549 are only a few translations so far (dutch, italian, german, japanese,
550 french, russian).  Translation involves writing a .po file, which is
551 relatively easy, and does not even require running LilyPond.
552
553 @unnumberedsubsec Hackers
554
555 There are lots of possibilities of improving the program itself. There
556 are both small projects and big ones. Most of them are listed in our
557 TODO file, listed on the homepage of Jan and
558 @uref{http://www.cs.uu.nl/~hanwen/lily-devel,Han-Wen}.  Modifying
559 LilyPond almost always requires patches to the C++ part.
560
561 If you still don't have any idea what to do, you might want to browse
562 the mailing lists; Users do lots of feature requests, and you could
563 implement any of them.
564
565
566 There are also numerous other interesting projects that are more or less
567 related  to LilyPond
568
569 @itemize @bullet
570 @item Writing convertors, eg. from NIFF and MIDI (we tried writing one with
571 limited success: midi2ly, included with lilypond.)
572
573 We found that writing them in Python is the easiest.
574
575 @item Writing a GUI frontend to
576 LilyPond. At the moment @uref{denemo,denemo.sourceforge.net} is the most
577 advanced.
578
579 @item Helping write @uref{http://solfege.sourceforge.net/,solfege
580 tools}
581
582 @item Helping @uref{primrose.sourceforge.net,primrose}, a tool for
583 scanning sheet music.
584 @end itemize
585
586 @node ETF format
587 @section  An incomplete description of the Enigma Transport Format
588
589 Enigma Transport Format (ETF for short) is a format designed by Coda music
590 technology, and it is used in the proprietary notation package
591 Finale. Since it is very poorly documented, I'll attempt some
592 documentation here.
593
594 ETF is an memory dump where object pointers have been replaced by object
595 numbers. The numbers are larger than 0 and the number 0 is used to
596 denote the nil pointer.  The dump is encoded in ASCII (where the mac
597 version uses CR, and the PC CR/LF as line delimiters)
598
599 A file is divided into sections like this
600
601 @example
602 ^section-header
603 DATA
604 ^section-header
605 DATA
606
607 (etc.)
608 @end example
609
610 @var{DATA} is stored in the form of tagged lines, where a tagged line looks
611 like
612
613 @example
614 ^TG(N1[,N2]) X1 X2 X3 (etc)
615 @end example
616
617 The caret is at the start of the line, @code{TG} is a two letter tag,
618 and @var{N1} (and optionally @var{N2}) are numbers identifying the
619 object to be described. @var{X3}, @var{X4} etc contain data in the form
620 of either a signed 16 bit number, or a 32 bit number (in hex, with a $
621 sign prepended). The number of Xs per line for a certain tag is
622 constant.
623
624 The numbers in @code{N1} need not be consecutive or ascending, mostly.
625
626
627 If an object is too large to fit on a single line (which typically has
628 only five X's), it is put on multiple lines and padded with zero's, eg.
629
630 @example
631 ^GF(1,2) 3 0 1 2 3
632 ^GF(1,2) 4 0 0 0 0
633 @end example
634
635 (the GF object requires 6 16 bit words, hence the 4 padding zeroes).
636
637 Note structure:
638
639 Each staff can contain up to four layers, where a layer correspond to a
640 horizontal `line' of notes.  Each layer is broken up into frames, where
641 each frame is one measure of a layer.
642
643 @example
644   ^GF(s,m) @var{c} @var{flags} @var{f1} @var{f2} @var{f3}
645   ^GF(s,m) @var{f4} 0 0 0 0
646 @end example
647
648 Here @var{s} is the staff number, @var{m} the measure number,
649 @var{flags} is a 16-bit bit-vector, and @var{f1} to @var{f4} are frame
650 identifiers. @var{c} is a clef-identifier.
651
652 There is a second variant of the @code{GF} tag, which has only one line;
653 it looks like
654
655 @example
656   ^GF(s,m) @var{fr} @var{c} @var{x} @var{y} @var{z}
657 @end example
658
659 here, @code{fr} is a frame number, @code{c} the clef number. The
660 function of x, y , z is unknown.
661
662 A frame is described by the FR tag
663
664 @example
665   ^FR(@var{n}) @var{n1} @var{n2} 0 0
666 @end example
667
668 This means frame number @var{n} runs from note @var{n1} to note @var{n2}
669 Where `running from' is interpreted as ``that part of a linked note list
670 that starts with note @var{n1} and ends with note @var{n2}''. This is
671 something different from the sequence of notes
672 @var{n1}, @var{n1 + 1} , ... , @var{n2 - 1}, @var{n2}. 
673
674 Notes (or more accurately chord-notes/rests) are described as follows:
675
676 @example
677   ^eE(@var{n}) @var{l1 l2 dur pos $flags extflags pitchcount}
678      pitchrecords
679 @end example
680
681 This is note number @var{n} (in list where @var{l1} and @var{l2} are
682 previous and next).
683
684 Durations are stored as a number where 1024 is the quarter note, 512 the
685 eighth, etc. Dotted notes are stored by multiplying the dur field
686 appropriately.
687
688 pitchcount is the number of pitch records. Each pitchrecord looks like
689 @example
690         pitch $flags
691 @end example
692 (note that the line starts with spaces, and not with  a caret)
693
694
695 pitch is a 16 bit number, where the lower order 4-bits is a signed
696 nybble which adds an alteration (0 = natural,  1 = sharp, etc.)
697 The remaining 12 bits encodes the note-name (octave inclusive.)
698
699 Both the alteration and the note-name are relative to the scale as
700 defined by the key-signature in this measure.  The person who invented
701 this should have his head checked out.
702
703 The key and time signature are defined in the MS field
704 @example
705   ^MS(n) space key beats beatlen y z
706 @end example
707
708 @var{n} is the measure number.  @var{space} is the width of the
709 measure (?), @var{key} the number of the keysignature (0 = C major, 1 G
710 major, etc. 255 = F major, 254 = Bflat major). beats and beatlen
711 determine time signature.
712
713 Key and time are determined score wide. The mind boggles at how they
714 plan to do polytonal and polymetric music. And how do they do
715 mid-measure keychanges?
716
717 Slurs are (among others) stored with an Sx tag
718
719 @example
720   ^Sx(@var{slurnumber}) @var{stuff}
721 @end example
722
723 The slur has many parameters. The 6th number on the first line is the
724 starting note, the 3rd number on the 4th line the ending note.
725
726
727 Some other information can be found in the Finale Plug-in Development
728 (there is a vague manual, and some source files that are useful).
729
730 You can download the PDK from Coda's website,
731 @uref{http://www.codamusic.com/coda/Fin2000_pdk_download.asp}. You do
732 need to register as a user (you can also do it if you have never bought
733 an coda product).
734
735
736 More tags:
737 @example
738 RU - repeat
739 ES - end repeat
740 ET - end repeat text
741 BR - backw repeat
742 mt - measure text
743 pT - page text
744 TX - text blocks
745 SD - shape
746 DY - score expr
747 AC - tempo
748 GF - clef
749 IS - staff spec
750 DO (shape expression), 
751 DT (text expression), 
752 IK (chord playback), 
753 IS (staff spec), 
754 IV (chord suffix), 
755 IX (articulation definition - documented in edata.h), 
756 Iu (instrument used - documented in edata.h), 
757 LA (layer preferences - documented in eprfdata.h), 
758 MN (measure number region), 
759 MS (measure spec), 
760 PS (page spec), 
761 RS (repeat style - documented in edata.h), 
762 RT (text repeat style text - documented in edata.h), 
763 SD (shape), 
764 SS (staff system spec), 
765 TX (text block), 
766 pT (page text)
767
768 TP - tuplet
769
770 sl - slur shapetag
771 @end example
772
773