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>
12 #include "text-item.hh"
13 #include "time-signature.hh"
14 #include "output-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, print, 1);
30 Time_signature::print (SCM smob)
32 Grob * me = unsmob_grob (smob);
33 SCM st = me->get_property ("style");
34 SCM frac = me->get_property ("fraction");
37 if (ly_c_pair_p (frac))
39 n = scm_to_int (ly_car (frac));
40 d = scm_to_int (ly_cdr (frac));
44 if (st == ly_symbol2scm ("single-digit"))
46 m = numbered_time_signature (me, n, 0);
48 else if (scm_is_symbol (st))
50 m = special_time_signature (me, st, n, d);
53 m = numbered_time_signature (me, n,d);
55 if (Staff_symbol_referencer::line_count (me) % 2 == 0)
56 m.translate_axis (Staff_symbol_referencer::staff_space (me)/2 , Y_AXIS);
58 return m.smobbed_copy ();
62 Time_signature::special_time_signature (Grob *me, SCM scm_style, int n, int d)
64 String style = ly_scm2string (scm_symbol_to_string (scm_style));
66 if (style == "numbered")
67 return numbered_time_signature (me, n, d);
69 if ((style == "default") || (style == ""))
70 style = to_string ("C");
74 if /* neither C2/2 nor C4/4 */
75 (((n != 2) || (d != 2)) &&
76 ((n != 4) || (d != 4)))
78 return numbered_time_signature (me, n, d);
82 String char_name = style + to_string (n) + "/" + to_string (d);
83 me->set_property ("font-encoding", ly_symbol2scm ("fetaMusic"));
84 Stencil out = Font_interface::get_default_font (me)
85 ->find_by_name ("timesig-" + char_name);
89 /* If there is no such symbol, we default to the numbered style.
90 (Here really with a warning!) */
91 me->warning (_f ("time signature symbol `%s' not found; "
92 "reverting to numbered style", char_name));
93 return numbered_time_signature (me, n, d);
97 Time_signature::numbered_time_signature (Grob*me,int num, int den)
99 SCM chain = me->get_property_alist_chain (Font_interface::text_font_alist_chain (me));
100 chain = scm_cons (scm_list_1 (scm_cons (ly_symbol2scm ("font-encoding"),
101 ly_symbol2scm ("fetaNumber"))),
104 SCM sn = Text_interface::interpret_markup (me->get_paper ()->self_scm (), chain,
105 scm_makfrom0str (to_string (num).to_str0 ()));
106 SCM sd = Text_interface::interpret_markup (me->get_paper ()->self_scm (), chain,
107 scm_makfrom0str (to_string (den).to_str0 ()));
109 Stencil n = *unsmob_stencil (sn);
110 Stencil d = *unsmob_stencil (sd);
112 n.align_to (X_AXIS, CENTER);
113 d.align_to (X_AXIS, CENTER);
117 m.add_at_edge (Y_AXIS, UP, n, 0.0, 0);
118 m.add_at_edge (Y_AXIS, DOWN, d, 0.0,0);
123 m.align_to (Y_AXIS, CENTER);
126 m.align_to (X_AXIS, LEFT);
131 ADD_INTERFACE (Time_signature, "time-signature-interface",
132 "A time signature, in different styles.\n"
133 " The following values for 'style are are recognized:\n"
137 " 4/4 and 2/2 are typeset as C and struck C, respectively. All\n"
138 " other time signatures are written with two digits.\n"
140 " @item @code{neomensural}\n"
141 " 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are\n"
142 " typeset with neo-mensural style mensuration marks. All other time\n"
143 " signatures are written with two digits.\n"
145 " @item @code{mensural}\n"
146 " 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are\n"
147 " typeset with mensural style mensuration marks. All other time\n"
148 " signatures are written with two digits.\n"
150 " @item @code{single-digit}\n"
151 " All time signatures are typeset with a single\n"
152 " digit, e.g. 3/2 is written as 3.\n"
155 "See also the test-file @file{input/test/time.ly}.\n",