]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
release: 1.3.100
[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 "font-interface.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 = Font_interface::get_default_font (me)->find_by_name (symbolname);
57   if (!m.empty_b()) 
58     return m;
59
60   // Second guess: s contains the full signature name
61   m = Font_interface::get_default_font (me)->find_by_name ("timesig-"+s);
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   SCM chain = gh_list (me->mutable_property_alist_, me->immutable_property_alist_, SCM_UNDEFINED);
74
75   Molecule n = Text_item::text2molecule (me,
76                                          ly_str02scm (to_str (num).ch_C ()),
77                                          chain);
78   Molecule d = Text_item::text2molecule (me,
79                                          ly_str02scm (to_str (den).ch_C ()),
80                                          chain);
81   n.align_to (X_AXIS, CENTER);
82   d.align_to (X_AXIS, CENTER);
83   Molecule m;
84   if (den)
85     {
86       m.add_at_edge (Y_AXIS, UP, n, 0.0);
87       m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
88     }
89   else
90     {
91       m = n;
92       m.align_to (Y_AXIS, CENTER);
93     }
94   return m;
95 }
96