]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
input/test fixes
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10
11 #include "stencil.hh"
12 #include "text-item.hh"
13 #include "time-signature.hh"
14 #include "output-def.hh"
15 #include "font-interface.hh"
16 #include "warn.hh"
17 #include "staff-symbol-referencer.hh"
18
19
20 /*
21   TODO:
22
23   this file should go ; The formatting can completely be done with
24   markups.
25   
26  */
27
28 MAKE_SCHEME_CALLBACK (Time_signature, print, 1);
29 SCM
30 Time_signature::print (SCM smob) 
31 {
32   Grob * me = unsmob_grob (smob);
33   SCM st = me->get_property ("style");
34   SCM frac = me->get_property ("fraction");
35   int n = 4;
36   int d = 4;
37   if (ly_c_pair_p (frac))
38     {
39       n = ly_scm2int (ly_car (frac));
40       d = ly_scm2int (ly_cdr (frac));
41     }
42
43   Stencil m;
44   if (st == ly_symbol2scm ("single-digit"))
45     {
46       m = numbered_time_signature (me, n, 0);
47     }
48   else if (ly_c_symbol_p (st))
49     {
50       m = special_time_signature (me, st, n, d);
51     }
52   else
53     m = numbered_time_signature (me, n,d);
54
55   if (Staff_symbol_referencer::line_count (me) % 2 == 0)
56     m.translate_axis (Staff_symbol_referencer::staff_space (me)/2 , Y_AXIS);
57
58   return m.smobbed_copy ();
59 }
60
61 Stencil
62 Time_signature::special_time_signature (Grob *me, SCM scm_style, int n, int d)
63 {
64   String style = ly_scm2string (scm_symbol_to_string (scm_style));
65
66   if (style == "numbered")
67     return numbered_time_signature (me, n, d);
68
69   if ((style == "default") || (style == ""))
70     style = to_string ("C");
71
72   if (style == "C")
73     {
74       if /* neither C2/2 nor C4/4 */
75         (((n != 2) || (d != 2)) && 
76          ((n != 4) || (d != 4)))
77         {
78           return numbered_time_signature (me, n, d);
79         }
80     }
81
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);
86   if (!out.is_empty ())
87     return out;
88
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);
94 }
95
96 Stencil
97 Time_signature::numbered_time_signature (Grob*me,int num, int den)
98 {
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"))),
102                     chain);
103                                 
104   SCM sn = Text_item::interpret_markup (me->get_paper ()->self_scm (), chain,
105                                         scm_makfrom0str (to_string (num).to_str0 ()));
106   SCM sd = Text_item::interpret_markup (me->get_paper ()->self_scm (), chain,
107                                         scm_makfrom0str (to_string (den).to_str0 ()));
108
109   Stencil n = *unsmob_stencil (sn);
110   Stencil d = *unsmob_stencil (sd);
111                               
112   n.align_to (X_AXIS, CENTER);
113   d.align_to (X_AXIS, CENTER);
114   Stencil m;
115   if (den)
116     {
117       m.add_at_edge (Y_AXIS, UP, n, 0.0, 0);
118       m.add_at_edge (Y_AXIS, DOWN, d, 0.0,0);
119     }
120   else
121     {
122       m = n;
123       m.align_to (Y_AXIS, CENTER);
124     }
125
126   m.align_to (X_AXIS, LEFT);
127   
128   return m;
129 }
130
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"
134 "\n"
135 "    @table @samp\n"
136 "      @item @code{C}\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"
139 "\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"
144 "\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"
149 "\n"
150 "      @item @code{single-digit"
151 "        All time signatures are typeset with a single\n"
152 "        digit, e.g. 3/2 is written as 3.\n"
153 "    @end table\n"
154 "\n"
155 "See also the test-file @file{input/test/time.ly}.\n",
156   "fraction style");