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>
10 #include "time-signature.hh"
12 #include "text-item.hh"
13 #include "output-def.hh"
14 #include "font-interface.hh"
16 #include "staff-symbol-referencer.hh"
21 this file should go ; The formatting can completely be done with
26 MAKE_SCHEME_CALLBACK (Time_signature, print, 1);
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");
35 if (scm_is_pair (frac))
37 n = scm_to_int (scm_car (frac));
38 d = scm_to_int (scm_cdr (frac));
42 if (st == ly_symbol2scm ("single-digit"))
44 m = numbered_time_signature (me, n, 0);
46 else if (scm_is_symbol (st))
48 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 scm_style, int n, int d)
62 String style = ly_scm2string (scm_symbol_to_string (scm_style));
64 if (style == "numbered")
65 return numbered_time_signature (me, n, d);
67 if ((style == "default") || (style == ""))
68 style = to_string ("C");
72 if /* neither C2/2 nor C4/4 */
73 (((n != 2) || (d != 2)) &&
74 ((n != 4) || (d != 4)))
76 return numbered_time_signature (me, n, d);
80 String char_name = style + to_string (n) + to_string (d);
81 me->set_property ("font-encoding", ly_symbol2scm ("fetaMusic"));
82 Stencil out = Font_interface::get_default_font (me)
83 ->find_by_name ("timesig." + char_name);
87 /* If there is no such symbol, we default to the numbered style.
88 (Here really with a warning!) */
89 me->warning (_f ("time signature symbol `%s' not found; "
90 "reverting to numbered style", char_name));
91 return numbered_time_signature (me, n, d);
95 Time_signature::numbered_time_signature (Grob*me,int num, int den)
97 SCM chain = me->get_property_alist_chain (Font_interface::text_font_alist_chain (me));
98 chain = scm_cons (scm_list_1 (scm_cons (ly_symbol2scm ("font-encoding"),
99 ly_symbol2scm ("fetaNumber"))),
102 SCM sn = Text_interface::interpret_markup (me->get_layout ()->self_scm (), chain,
103 scm_makfrom0str (to_string (num).to_str0 ()));
104 SCM sd = Text_interface::interpret_markup (me->get_layout ()->self_scm (), chain,
105 scm_makfrom0str (to_string (den).to_str0 ()));
107 Stencil n = *unsmob_stencil (sn);
108 Stencil d = *unsmob_stencil (sd);
110 n.align_to (X_AXIS, CENTER);
111 d.align_to (X_AXIS, CENTER);
115 m.add_at_edge (Y_AXIS, UP, n, 0.0, 0);
116 m.add_at_edge (Y_AXIS, DOWN, d, 0.0,0);
121 m.align_to (Y_AXIS, CENTER);
124 m.align_to (X_AXIS, LEFT);
129 ADD_INTERFACE (Time_signature, "time-signature-interface",
130 "A time signature, in different styles.\n"
131 " The following values for 'style are are recognized:\n"
135 " 4/4 and 2/2 are typeset as C and struck C, respectively. All\n"
136 " other time signatures are written with two digits.\n"
138 " @item @code{neomensural}\n"
139 " 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are\n"
140 " typeset with neo-mensural style mensuration marks. All other time\n"
141 " signatures are written with two digits.\n"
143 " @item @code{mensural}\n"
144 " 2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are\n"
145 " typeset with mensural style mensuration marks. All other time\n"
146 " signatures are written with two digits.\n"
148 " @item @code{single-digit}\n"
149 " All time signatures are typeset with a single\n"
150 " digit, e.g. 3/2 is written as 3.\n"
153 "See also the test-file @file{input/test/time.ly}.\n",