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 "unknown time signature `" + s +
87 "'; resorting to default layout with numbers";
88 warning (_ (message.ch_C ()));
90 // Resort to default layout with numbers
91 return time_signature (me, n, d);
96 Time_signature::time_signature (Grob*me,int num, int den)
98 SCM chain = Font_interface::font_alist_chain (me);
100 Molecule n = Text_item::text2molecule (me,
101 ly_str02scm (to_str (num).ch_C ()),
103 Molecule d = Text_item::text2molecule (me,
104 ly_str02scm (to_str (den).ch_C ()),
106 n.align_to (X_AXIS, CENTER);
107 d.align_to (X_AXIS, CENTER);
111 m.add_at_edge (Y_AXIS, UP, n, 0.0);
112 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
117 m.align_to (Y_AXIS, CENTER);
120 m.align_to (X_AXIS, LEFT);
127 ADD_INTERFACE (Time_signature,"time-signature-interface",
128 "A time signature, in different styles.
129 The following values for 'style are are recognized:
133 4/4 and 2/2 are typeset as C and struck C, respectively. All
134 other time signatures are written with two digits.
137 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are
138 typeset with old-style mensuration marks. All other time
139 signatures are written with two digits.
142 All time signatures are typeset with a single
143 digit, e.g. 3/2 is written as 3. (Any symbol starting
144 with the digit @code{1} will do.)
146 @item @code{C}@var{M}@code{/}@var{N},
147 @code{old}@var{M}@code{/}@var{N} or
149 Tells LilyPond to use a specific symbol as time signature,
150 regardless of the actual time signature.
153 See also the test-file @file{input/test/time.ly}.