2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "time-signature.hh"
23 #include "font-interface.hh"
24 #include "international.hh"
25 #include "output-def.hh"
26 #include "text-interface.hh"
31 this file should go ; The formatting can completely be done with
35 MAKE_SCHEME_CALLBACK (Time_signature, print, 1);
37 Time_signature::print (SCM smob)
39 Grob *me = Grob::unsmob (smob);
40 SCM st = me->get_property ("style");
41 SCM frac = me->get_property ("fraction");
44 if (scm_is_pair (frac))
46 n = scm_to_int (scm_car (frac));
47 d = scm_to_int (scm_cdr (frac));
51 if (st == ly_symbol2scm ("single-digit"))
52 m = numbered_time_signature (me, n, 0);
53 else if (scm_is_symbol (st))
54 m = special_time_signature (me, st, n, d);
56 m = numbered_time_signature (me, n, d);
58 return m.smobbed_copy ();
62 Time_signature::special_time_signature (Grob *me, SCM scm_style, int n, int d)
64 string style = robust_symbol2string (scm_style, "default");
66 if (style == "numbered")
67 return numbered_time_signature (me, n, d);
69 if ((style == "default") || (style == ""))
70 style = ::to_string ("C");
71 else if (style == "single-C")
73 if ((n != 2) && (n != 4))
74 return numbered_time_signature (me, n, 0);
75 /* for any d, print 2/d as cut-C, 4/d as C */
76 style = ::to_string ("C");
82 if /* neither C2/2 nor C4/4 */
83 (((n != 2) || (d != 2))
84 && ((n != 4) || (d != 4)))
85 return numbered_time_signature (me, n, d);
88 string char_name = style + ::to_string (n) + ::to_string (d);
89 me->set_property ("font-encoding", ly_symbol2scm ("fetaMusic"));
90 Stencil out = Font_interface::get_default_font (me)
91 ->find_by_name ("timesig." + char_name);
95 /* If there is no such symbol, we default to the numbered style.
96 (Here really with a warning!) */
97 me->warning (_f ("time signature symbol `%s' not found; "
98 "reverting to numbered style", char_name));
99 return numbered_time_signature (me, n, d);
103 Time_signature::numbered_time_signature (Grob *me, int num, int den)
105 SCM chain = me->get_property_alist_chain (Font_interface::text_font_alist_chain (me));
106 chain = scm_cons (scm_list_1 (scm_cons (ly_symbol2scm ("font-encoding"),
107 ly_symbol2scm ("fetaText"))),
110 SCM sn = Text_interface::interpret_markup (me->layout ()->self_scm (), chain,
111 ly_string2scm (::to_string (num)));
112 SCM sd = Text_interface::interpret_markup (me->layout ()->self_scm (), chain,
113 ly_string2scm (::to_string (den)));
115 Stencil n = *Stencil::unsmob (sn);
116 Stencil d = *Stencil::unsmob (sd);
118 n.align_to (X_AXIS, CENTER);
119 d.align_to (X_AXIS, CENTER);
123 m.add_at_edge (Y_AXIS, UP, n, 0.0);
124 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
129 m.align_to (Y_AXIS, CENTER);
132 m.align_to (X_AXIS, LEFT);
137 ADD_INTERFACE (Time_signature,
138 "A time signature, in different styles. The following values"
139 " for @code{style} are are recognized:\n"
143 "4/4 and 2/2 are typeset as C and struck C, respectively."
144 " All other time signatures are written with two digits."
145 " The value @code{default} is equivalent to @code{C}.\n"
146 "@item neomensural\n"
147 "2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8, and 9/8 are"
148 " typeset with neo-mensural style mensuration marks. All"
149 " other time signatures are written with two digits.\n"
151 "2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8, and 9/8 are"
152 " typeset with mensural style mensuration marks. All other"
153 " time signatures are written with two digits.\n"
154 "@item single-digit\n"
155 "All time signatures are typeset with a single digit, e.g.,"
156 " 3/2 is written as 3.\n"
158 "All time signatures are typeset with two digits.\n"