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