]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10
11 #include "molecule.hh"
12 #include "text-item.hh"
13 #include "time-signature.hh"
14 #include "paper-def.hh"
15 #include "font-interface.hh"
16 #include "warn.hh"
17 #include "staff-symbol-referencer.hh"
18
19 MAKE_SCHEME_CALLBACK (Time_signature,brew_molecule,1);
20 /*
21   TODO: make different functions for special and normal timesigs.
22  */
23 SCM
24 Time_signature::brew_molecule (SCM smob) 
25 {
26   Grob * me = unsmob_grob (smob);
27   SCM st = me->get_grob_property ("style");
28   SCM frac = me->get_grob_property ("fraction");
29   int n = 4;
30   int d = 4;
31   if (gh_pair_p (frac))
32     {
33       n = gh_scm2int (ly_car (frac));
34       d = gh_scm2int (ly_cdr (frac));
35     }
36
37   Molecule m;
38   if (gh_symbol_p (st))
39     {
40       String style (ly_scm2string (scm_symbol_to_string (st)));
41       if (style[0]=='1')
42         {
43           m = numbered_time_signature (me, n, 0);
44         }
45       else
46         {
47           m = special_time_signature (me, st, n, d);
48         }
49     }
50   else
51     m = numbered_time_signature (me, n,d);
52
53   if (Staff_symbol_referencer::line_count (me) % 2 == 0)
54     m.translate_axis (Staff_symbol_referencer::staff_space (me)/2 , Y_AXIS);
55
56   return m.smobbed_copy ();
57 }
58
59 Molecule
60 Time_signature::special_time_signature (Grob *me, SCM scm_style, int n, int d)
61 {
62   String style = ly_scm2string (scm_symbol_to_string (scm_style));
63
64   if (style == "numbered")
65     return numbered_time_signature (me, n, d);
66
67   if ((style == "default") || (style == ""))
68     style = to_string ("C");
69
70   if (style == "C")
71     {
72       if /* neither C2/2 nor C4/4 */
73         (((n != 2) || (d != 2)) && 
74          ((n != 4) || (d != 4)))
75         {
76           return numbered_time_signature (me, n, d);
77         }
78     }
79
80   String char_name = style + to_string (n) + "/" + to_string (d);
81   me->set_grob_property ("font-family", ly_symbol2scm ("music"));
82   Molecule out =
83     Font_interface::get_default_font (me)->find_by_name ("timesig-" + char_name);
84   if (!out.empty_b ())
85     return out;
86
87   /*
88     If there is no such symbol, we default to the numbered style.
89     (Here really with a warning!)
90   */
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 Molecule
97 Time_signature::numbered_time_signature (Grob*me,int num, int den)
98 {
99   SCM chain = Font_interface::font_alist_chain (me);
100   me->set_grob_property("font-family", ly_symbol2scm ("number"));
101
102   Molecule n = Text_item::text2molecule (me,
103                                          scm_makfrom0str (to_string (num).to_str0 ()),
104                                          chain);
105   Molecule d = Text_item::text2molecule (me,
106                                          scm_makfrom0str (to_string (den).to_str0 ()),
107                                          chain);
108   n.align_to (X_AXIS, CENTER);
109   d.align_to (X_AXIS, CENTER);
110   Molecule m;
111   if (den)
112     {
113       m.add_at_edge (Y_AXIS, UP, n, 0.0);
114       m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
115     }
116   else
117     {
118       m = n;
119       m.align_to (Y_AXIS, CENTER);
120     }
121
122   m.align_to (X_AXIS, LEFT);
123   
124   return m;
125 }
126
127 ADD_INTERFACE (Time_signature,"time-signature-interface",
128   "A time signature, in different styles.
129   The following values for 'style are are recognized:
130
131     @table @samp
132       @item @code{C}
133         4/4 and 2/2 are typeset as C and struck C, respectively.  All
134         other time signatures are written with two digits.
135
136       @item @code{neo_mensural}
137         2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are
138         typeset with neo-mensural style mensuration marks.  All other time
139         signatures are written with two digits.
140
141       @item @code{mensural}
142         2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are
143         typeset with mensural style mensuration marks.  All other time
144         signatures are written with two digits.
145
146       @item @code{1xxx}
147         All time signatures are typeset with a single
148         digit, e.g. 3/2 is written as 3. (Any symbol starting
149         with the digit @code{1} will do.)
150     @end table
151
152 See also the test-file @file{input/test/time.ly}.
153 ",
154   "fraction style");