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