2 time-signature.cc -- implement Time_signature
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "molecule.hh"
12 #include "text-item.hh"
13 #include "time-signature.hh"
14 #include "paper-def.hh"
15 #include "font-interface.hh"
18 MAKE_SCHEME_CALLBACK (Time_signature,brew_molecule,1);
20 TODO: make different functions for special and normal timesigs.
23 Time_signature::brew_molecule (SCM smob)
25 Grob * me = unsmob_grob (smob);
26 SCM st = me->get_grob_property ("style");
27 SCM frac = me->get_grob_property ("fraction");
32 n = gh_scm2int (ly_car (frac));
33 d = gh_scm2int (ly_cdr (frac));
39 String style (ly_scm2string (scm_symbol_to_string (st)));
42 return time_signature (me, n, 0).smobbed_copy ();
46 return special_time_signature (me, style, n, d).smobbed_copy ();
50 return time_signature (me, n,d).smobbed_copy ();
54 Time_signature::special_time_signature (Grob*me, String s, int n, int d)
57 Randomly probing the font sucks?
60 SCM alist_chain = Font_interface::font_alist_chain (me);
63 Font_interface::add_style (me, ly_symbol2scm ("timesig-symbol"),
66 Font_metric *feta = Font_interface::get_font (me, style_chain);
69 First guess: s contains only the signature style, append fraction.
71 String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
73 Molecule m = feta->find_by_name (symbolname);
78 Second guess: s contains the full signature name
80 m = feta->find_by_name ("timesig-" + s);
81 m.align_to (X_AXIS, LEFT);
86 If there is no such symbol, we default without warning to the
89 return time_signature (me, n, d);
94 Time_signature::time_signature (Grob*me,int num, int den)
96 SCM chain = Font_interface::font_alist_chain (me);
98 Molecule n = Text_item::text2molecule (me,
99 ly_str02scm (to_str (num).ch_C ()),
101 Molecule d = Text_item::text2molecule (me,
102 ly_str02scm (to_str (den).ch_C ()),
104 n.align_to (X_AXIS, CENTER);
105 d.align_to (X_AXIS, CENTER);
109 m.add_at_edge (Y_AXIS, UP, n, 0.0);
110 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
115 m.align_to (Y_AXIS, CENTER);
118 m.align_to (X_AXIS, LEFT);
125 ADD_INTERFACE (Time_signature,"time-signature-interface",
126 "A time signature, in different styles.
127 The following values for 'style are are recognized:
131 4/4 and 2/2 are typeset as C and struck C, respectively. All
132 other time signatures are written with two digits.
135 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are
136 typeset with old-style mensuration marks. All other time
137 signatures are written with two digits.
140 All time signatures are typeset with a single
141 digit, e.g. 3/2 is written as 3. (Any symbol starting
142 with the digit @code{1} will do.)
144 @item @code{C}@var{M}@code{/}@var{N},
145 @code{old}@var{M}@code{/}@var{N} or
147 Tells LilyPond to use a specific symbol as time signature,
148 regardless of the actual time signature.
151 See also the test-file @file{input/test/time.ly}.