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