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