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