]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
release: 1.3.24
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10
11 #include "molecule.hh"
12 #include "time-signature.hh"
13 #include "paper-def.hh"
14 #include "lookup.hh"
15
16 Time_signature::Time_signature ()
17 {
18   set_elt_property ("breakable", SCM_BOOL_T);
19 }
20
21 // ugh.!
22 Molecule*
23 Time_signature::do_brew_molecule_p () const
24 {
25   SCM st = get_elt_property ("style");
26
27   SCM frac = get_elt_property ("fraction");
28   int n = 4;
29   int d = 4;
30   if (gh_pair_p (frac))
31     {
32       n = gh_scm2int (gh_car (frac));
33       d = gh_scm2int (gh_cdr (frac));
34     }
35
36   
37   if (gh_string_p (st))
38     {
39       String style (ly_scm2string (st));
40       if (style[0]=='1')
41         {
42           return new Molecule (time_signature (n, 0));
43         }
44       else
45         {
46           return new Molecule (special_time_signature (style, n, d));
47         }
48     }
49   else
50     return new Molecule (time_signature (n,d));
51 }
52
53 Molecule
54 Time_signature::special_time_signature (String s, int n, int d) const
55 {
56   // First guess: s contains only the signature style
57   String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
58   
59   Molecule m = lookup_l ()->afm_find (symbolname, false);
60   if (!m.empty_b()) 
61     return m;
62
63   // Second guess: s contains the full signature name
64   m = lookup_l ()->afm_find ("timesig-"+s, false);
65   if (!m.empty_b ()) 
66     return m;
67
68   // Resort to default layout with numbers
69   return time_signature (n,d);
70 }
71
72
73 Molecule
74 Time_signature::time_signature (int num, int den) const
75 {
76   String sty = "number";
77
78   /*
79     UGH: need to look at fontsize.
80    */
81   Molecule n (lookup_l ()->text (sty, to_str (num), paper_l ()));
82   Molecule d (lookup_l ()->text (sty, to_str (den), paper_l ()));
83   n.align_to (X_AXIS, CENTER);
84   d.align_to (X_AXIS, CENTER);
85   Molecule m;
86   if (den)
87     {
88       m.add_at_edge (Y_AXIS, UP, n, 0.0);
89       m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
90     }
91   else
92     {
93       m = n;
94       m.align_to (Y_AXIS, CENTER);
95     }
96   return m;
97 }
98