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