2 time-signature.cc -- implement Time_signature
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2004 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"
23 this file should go ; The formatting can completely be done with
28 MAKE_SCHEME_CALLBACK (Time_signature, brew_molecule, 1);
30 Time_signature::brew_molecule (SCM smob)
32 Grob * me = unsmob_grob (smob);
33 SCM st = me->get_grob_property ("style");
34 SCM frac = me->get_grob_property ("fraction");
39 n = gh_scm2int (ly_car (frac));
40 d = gh_scm2int (ly_cdr (frac));
46 String style (ly_scm2string (scm_symbol_to_string (st)));
49 m = numbered_time_signature (me, n, 0);
53 m = special_time_signature (me, st, n, d);
57 m = numbered_time_signature (me, n,d);
59 if (Staff_symbol_referencer::line_count (me) % 2 == 0)
60 m.translate_axis (Staff_symbol_referencer::staff_space (me)/2 , Y_AXIS);
62 return m.smobbed_copy ();
66 Time_signature::special_time_signature (Grob *me, SCM scm_style, int n, int d)
68 String style = ly_scm2string (scm_symbol_to_string (scm_style));
70 if (style == "numbered")
71 return numbered_time_signature (me, n, d);
73 if ((style == "default") || (style == ""))
74 style = to_string ("C");
78 if /* neither C2/2 nor C4/4 */
79 (((n != 2) || (d != 2)) &&
80 ((n != 4) || (d != 4)))
82 return numbered_time_signature (me, n, d);
86 String char_name = style + to_string (n) + "/" + to_string (d);
87 me->set_grob_property ("font-family", ly_symbol2scm ("music"));
88 Molecule out = Font_interface::get_default_font (me)
89 ->find_by_name ("timesig-" + char_name);
93 /* If there is no such symbol, we default to the numbered style.
94 (Here really with a warning!) */
95 me->warning (_f ("time signature symbol `%s' not found; "
96 "reverting to numbered style", char_name));
97 return numbered_time_signature (me, n, d);
101 Time_signature::numbered_time_signature (Grob*me,int num, int den)
103 SCM chain = Font_interface::font_alist_chain (me);
104 me->set_grob_property ("font-family", ly_symbol2scm ("number"));
107 Text_item::interpret_markup (me->get_paper ()->self_scm(), chain,
108 scm_makfrom0str (to_string (num).to_str0 ()));
110 Text_item::interpret_markup (me->get_paper ()->self_scm(), chain,
111 scm_makfrom0str (to_string (den).to_str0 ()));
113 Molecule n = *unsmob_molecule (sn);
114 Molecule d = *unsmob_molecule (sd);
116 n.align_to (X_AXIS, CENTER);
117 d.align_to (X_AXIS, CENTER);
121 m.add_at_edge (Y_AXIS, UP, n, 0.0, 0);
122 m.add_at_edge (Y_AXIS, DOWN, d, 0.0,0);
127 m.align_to (Y_AXIS, CENTER);
130 m.align_to (X_AXIS, LEFT);
135 ADD_INTERFACE (Time_signature, "time-signature-interface",
136 "A time signature, in different styles.\n"
137 " The following values for 'style are are recognized:\n"
141 " 4/4 and 2/2 are typeset as C and struck C, respectively. All\n"
142 " other time signatures are written with two digits.\n"
144 " @item @code{neo_mensural}\n"
145 " 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are\n"
146 " typeset with neo-mensural style mensuration marks. All other time\n"
147 " signatures are written with two digits.\n"
149 " @item @code{mensural}\n"
150 " 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are\n"
151 " typeset with mensural style mensuration marks. All other time\n"
152 " signatures are written with two digits.\n"
154 " @item @code{1xxx}\n"
155 " All time signatures are typeset with a single\n"
156 " digit, e.g. 3/2 is written as 3. (Any symbol starting\n"
157 " with the digit @code{1} will do.)\n"
160 "See also the test-file @file{input/test/time.ly}.\n",