]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
patch::: 1.3.96.jcn7
[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 "text-item.hh"
13 #include "time-signature.hh"
14 #include "paper-def.hh"
15 #include "lookup.hh"
16
17 MAKE_SCHEME_CALLBACK(Time_signature,brew_molecule,1);
18
19 SCM
20 Time_signature::brew_molecule (SCM smob) 
21 {
22   Score_element * me = unsmob_element (smob);
23   SCM st = me->get_elt_property ("style");
24   SCM frac = me->get_elt_property ("fraction");
25   int n = 4;
26   int d = 4;
27   if (gh_pair_p (frac))
28     {
29       n = gh_scm2int (gh_car (frac));
30       d = gh_scm2int (gh_cdr (frac));
31     }
32
33   
34   if (gh_string_p (st))
35     {
36       String style (ly_scm2string (st));
37       if (style[0]=='1')
38         {
39           return time_signature (me, n, 0).create_scheme();
40         }
41       else
42         {
43           return special_time_signature (me, style, n, d).create_scheme();
44         }
45     }
46   else
47     return time_signature (me, n,d).create_scheme();
48 }
49
50 Molecule
51 Time_signature::special_time_signature (Score_element*me, String s, int n, int d)
52 {
53   // First guess: s contains only the signature style
54   String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
55   
56   Molecule m = me->lookup_l ()->afm_find (symbolname, false);
57   if (!m.empty_b()) 
58     return m;
59
60   // Second guess: s contains the full signature name
61   m = me->lookup_l ()->afm_find ("timesig-"+s, false);
62   if (!m.empty_b ()) 
63     return m;
64
65   // Resort to default layout with numbers
66   return time_signature (me, n,d);
67 }
68
69
70 Molecule
71 Time_signature::time_signature (Score_element*me,int num, int den)
72 {
73   /*
74     UGH: need to look at fontsize.
75     TODO: specify using scm markup.
76    */
77   SCM properties = gh_append2 (me->immutable_property_alist_,
78                                me->mutable_property_alist_);
79   Molecule n = Text_item::text2molecule (me,
80                                          ly_str02scm (to_str (num).ch_C ()),
81                                          properties);
82   Molecule d = Text_item::text2molecule (me,
83                                          ly_str02scm (to_str (den).ch_C ()),
84                                          properties);
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