Compile fix.
[lilypond.git] / lily / time-signature.cc
blob85b3b878b619c393044f960d94ad877e68b19a62
1 /*
2 time-signature.cc -- implement Time_signature
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "time-signature.hh"
11 #include "grob.hh"
12 #include "font-interface.hh"
13 #include "international.hh"
14 #include "output-def.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "text-interface.hh"
17 #include "warn.hh"
20 TODO:
22 this file should go ; The formatting can completely be done with
23 markups.
26 MAKE_SCHEME_CALLBACK (Time_signature, print, 1);
27 SCM
28 Time_signature::print (SCM smob)
30 Grob *me = unsmob_grob (smob);
31 SCM st = me->get_property ("style");
32 SCM frac = me->get_property ("fraction");
33 int n = 4;
34 int d = 4;
35 if (scm_is_pair (frac))
37 n = scm_to_int (scm_car (frac));
38 d = scm_to_int (scm_cdr (frac));
41 Stencil m;
42 if (st == ly_symbol2scm ("single-digit"))
43 m = numbered_time_signature (me, n, 0);
44 else if (scm_is_symbol (st))
45 m = special_time_signature (me, st, n, d);
46 else
47 m = numbered_time_signature (me, n, d);
49 if (Staff_symbol_referencer::line_count (me) % 2 == 0)
50 m.translate_axis (Staff_symbol_referencer::staff_space (me) / 2, Y_AXIS);
52 return m.smobbed_copy ();
55 Stencil
56 Time_signature::special_time_signature (Grob *me, SCM scm_style, int n, int d)
58 string style = ly_scm2string (scm_symbol_to_string (scm_style));
60 if (style == "numbered")
61 return numbered_time_signature (me, n, d);
63 if ((style == "default") || (style == ""))
64 style = to_string ("C");
66 if (style == "C")
68 if /* neither C2/2 nor C4/4 */
69 (((n != 2) || (d != 2))
70 && ((n != 4) || (d != 4)))
71 return numbered_time_signature (me, n, d);
74 string char_name = style + to_string (n) + to_string (d);
75 me->set_property ("font-encoding", ly_symbol2scm ("fetaMusic"));
76 Stencil out = Font_interface::get_default_font (me)
77 ->find_by_name ("timesig." + char_name);
78 if (!out.is_empty ())
79 return out;
81 /* If there is no such symbol, we default to the numbered style.
82 (Here really with a warning!) */
83 me->warning (_f ("time signature symbol `%s' not found; "
84 "reverting to numbered style", char_name));
85 return numbered_time_signature (me, n, d);
88 Stencil
89 Time_signature::numbered_time_signature (Grob *me, int num, int den)
91 SCM chain = me->get_property_alist_chain (Font_interface::text_font_alist_chain (me));
92 chain = scm_cons (scm_list_1 (scm_cons (ly_symbol2scm ("font-encoding"),
93 ly_symbol2scm ("fetaNumber"))),
94 chain);
96 SCM sn = Text_interface::interpret_markup (me->layout ()->self_scm (), chain,
97 ly_string2scm (to_string (num)));
98 SCM sd = Text_interface::interpret_markup (me->layout ()->self_scm (), chain,
99 ly_string2scm (to_string (den)));
101 Stencil n = *unsmob_stencil (sn);
102 Stencil d = *unsmob_stencil (sd);
104 n.align_to (X_AXIS, CENTER);
105 d.align_to (X_AXIS, CENTER);
106 Stencil m;
107 if (den)
109 m.add_at_edge (Y_AXIS, UP, n, 0.0);
110 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
112 else
114 m = n;
115 m.align_to (Y_AXIS, CENTER);
118 m.align_to (X_AXIS, LEFT);
120 return m;
123 ADD_INTERFACE (Time_signature,
124 "A time signature, in different styles. The following values"
125 " for @code{style} are are recognized:\n"
126 "\n"
127 "@table @code\n"
128 "@item C\n"
129 "4/4 and 2/2 are typeset as C and struck C, respectively."
130 " All other time signatures are written with two digits.\n"
131 "@item neomensural\n"
132 "2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8, and 9/8 are"
133 " typeset with neo-mensural style mensuration marks. All"
134 " other time signatures are written with two digits.\n"
135 "@item mensural\n"
136 "2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8, and 9/8 are"
137 " typeset with mensural style mensuration marks. All other"
138 " time signatures are written with two digits.\n"
139 "@item single-digit\n"
140 "All time signatures are typeset with a single digit, e.g.,"
141 " 3/2 is written as 3.\n"
142 "@end table\n"
143 "\n"
144 "See also the test-file @file{input/test/time.ly}.",
146 /* properties */
147 "fraction "
148 "style "