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"
17 #include "staff-symbol-referencer.hh"
19 MAKE_SCHEME_CALLBACK (Time_signature,brew_molecule,1);
21 TODO: make different functions for special and normal timesigs.
24 Time_signature::brew_molecule (SCM smob)
26 Grob * me = unsmob_grob (smob);
27 SCM st = me->get_grob_property ("style");
28 SCM frac = me->get_grob_property ("fraction");
33 n = gh_scm2int (ly_car (frac));
34 d = gh_scm2int (ly_cdr (frac));
40 String style (ly_scm2string (scm_symbol_to_string (st)));
43 m = numbered_time_signature (me, n, 0);
47 m = special_time_signature (me, st, n, d);
51 m = numbered_time_signature (me, n,d);
53 if (Staff_symbol_referencer::line_count (me) % 2 == 0)
54 m.translate_axis (Staff_symbol_referencer::staff_space (me)/2 , Y_AXIS);
56 return m.smobbed_copy ();
60 Time_signature::special_time_signature (Grob *me, SCM style, int n, int d)
62 String st = ly_scm2string (scm_symbol_to_string (style));
63 SCM scm_n = gh_int2scm (n);
64 SCM scm_d = gh_int2scm (d);
65 SCM exp = scm_list_n (ly_symbol2scm ("find-timesig-symbol"),
66 scm_n, scm_d, ly_quote_scm (style),
68 SCM scm_pair = scm_primitive_eval (exp);
69 SCM scm_font_char = ly_car (scm_pair);
70 SCM scm_font_family = ly_cdr (scm_pair);
71 String font_char = ly_scm2string (scm_font_char);
72 String font_family = ly_scm2string (scm_font_family);
73 me->set_grob_property("font-family", ly_symbol2scm (font_family.to_str0 ()));
76 Font_interface::get_default_font (me)->find_by_name ("timesig-" + font_char);
81 If there is no such symbol, we default without warning to the
84 return numbered_time_signature (me, n, d);
88 Time_signature::numbered_time_signature (Grob*me,int num, int den)
90 SCM chain = Font_interface::font_alist_chain (me);
91 me->set_grob_property("font-family", ly_symbol2scm ("number"));
93 Molecule n = Text_item::text2molecule (me,
94 scm_makfrom0str (to_string (num).to_str0 ()),
96 Molecule d = Text_item::text2molecule (me,
97 scm_makfrom0str (to_string (den).to_str0 ()),
99 n.align_to (X_AXIS, CENTER);
100 d.align_to (X_AXIS, CENTER);
104 m.add_at_edge (Y_AXIS, UP, n, 0.0);
105 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
110 m.align_to (Y_AXIS, CENTER);
113 m.align_to (X_AXIS, LEFT);
118 ADD_INTERFACE (Time_signature,"time-signature-interface",
119 "A time signature, in different styles.
120 The following values for 'style are are recognized:
124 4/4 and 2/2 are typeset as C and struck C, respectively. All
125 other time signatures are written with two digits.
128 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are
129 typeset with old-style mensuration marks. All other time
130 signatures are written with two digits.
133 All time signatures are typeset with a single
134 digit, e.g. 3/2 is written as 3. (Any symbol starting
135 with the digit @code{1} will do.)
137 @item @code{C}@var{M}@code{/}@var{N},
138 @code{old}@var{M}@code{/}@var{N} or
140 Tells LilyPond to use a specific symbol as time signature,
141 regardless of the actual time signature.
144 See also the test-file @file{input/test/time.ly}.