]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
small 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--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
18 MAKE_SCHEME_CALLBACK (Time_signature,brew_molecule,1);
19 /*
20   TODO: make different functions for special and normal timesigs.
21  */
22 SCM
23 Time_signature::brew_molecule (SCM smob) 
24 {
25   Grob * me = unsmob_grob (smob);
26   SCM st = me->get_grob_property ("style");
27   SCM frac = me->get_grob_property ("fraction");
28   int n = 4;
29   int d = 4;
30   if (gh_pair_p (frac))
31     {
32       n = gh_scm2int (ly_car (frac));
33       d = gh_scm2int (ly_cdr (frac));
34     }
35
36   
37   if (gh_symbol_p (st))
38     {
39       String style (ly_scm2string (scm_symbol_to_string (st)));
40       if (style[0]=='1')
41         {
42           return time_signature (me, n, 0).smobbed_copy ();
43         }
44       else
45         {
46           return special_time_signature (me, style, n, d).smobbed_copy ();
47         }
48     }
49   else
50     return time_signature (me, n,d).smobbed_copy ();
51 }
52
53 Molecule
54 Time_signature::special_time_signature (Grob*me, String s, int n, int d)
55 {
56   /*
57     Randomly probing the font sucks?
58   */
59   
60   SCM alist_chain = Font_interface::font_alist_chain (me);
61   
62   SCM style_chain =
63     Font_interface::add_style (me, ly_symbol2scm ("timesig-symbol"),
64                                alist_chain);
65
66   Font_metric *feta = Font_interface::get_font (me, style_chain);
67
68   /*
69     First guess: s contains only the signature style, append fraction.
70   */
71   String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
72   
73   Molecule m = feta->find_by_name (symbolname);
74   if (!m.empty_b ())
75     return m;
76
77   /*
78     Second guess: s contains the full signature name
79   */
80   m = feta->find_by_name ("timesig-" + s);
81   m.align_to (X_AXIS, LEFT);
82   if (!m.empty_b ()) 
83     return m;
84
85   /*
86     If there is no such symbol, we default without warning to the
87     numbered style.
88    */
89   return time_signature (me, n, d);
90 }
91
92
93 Molecule
94 Time_signature::time_signature (Grob*me,int num, int den)
95 {
96   SCM chain = Font_interface::font_alist_chain (me);
97
98   Molecule n = Text_item::text2molecule (me,
99                                          ly_str02scm (to_str (num).ch_C ()),
100                                          chain);
101   Molecule d = Text_item::text2molecule (me,
102                                          ly_str02scm (to_str (den).ch_C ()),
103                                          chain);
104   n.align_to (X_AXIS, CENTER);
105   d.align_to (X_AXIS, CENTER);
106   Molecule m;
107   if (den)
108     {
109       m.add_at_edge (Y_AXIS, UP, n, 0.0);
110       m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
111     }
112   else
113     {
114       m = n;
115       m.align_to (Y_AXIS, CENTER);
116     }
117
118   m.align_to (X_AXIS, LEFT);
119   
120   return m;
121 }
122
123
124
125 ADD_INTERFACE (Time_signature,"time-signature-interface",
126   "A time signature, in different styles.
127   The following values for 'style are are recognized:
128
129     @table @samp
130       @item @code{C}
131         4/4 and 2/2 are typeset as C and struck C, respectively.  All
132         other time signatures are written with two digits.
133
134       @item @code{old}
135         2/2, 3/2, 2/4, 3/4, 4/4, 6/4, 9/4, 4/8, 6/8 and 9/8 are
136         typeset with old-style mensuration marks.  All other time
137         signatures are written with two digits.
138
139       @item @code{1xxx}
140         All time signatures are typeset with a single
141         digit, e.g. 3/2 is written as 3. (Any symbol starting
142         with the digit @code{1} will do.)
143
144       @item @code{C}@var{M}@code{/}@var{N}, 
145 @code{old}@var{M}@code{/}@var{N} or
146       @code{old6/8alt}
147         Tells LilyPond to use a specific symbol as time signature, 
148         regardless of the actual time signature.
149     @end table
150
151 See also the test-file @file{input/test/time.ly}.
152 ",
153   "fraction style");