]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
patch::: 1.3.103.jcn3: Re: LilyPond 1.3.103
[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   /*
54     Randomly probing the font sucks?
55   */
56   
57   SCM alist_chain = Font_interface::font_alist_chain (me);
58   
59   SCM style_chain =
60     Font_interface::add_style (me, ly_symbol2scm ("timesig-symbol"),
61                                alist_chain);
62
63   Font_metric *feta = Font_interface::get_font (me, style_chain);
64
65   /*
66     First guess: s contains only the signature style, append fraction.
67   */
68   String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
69   
70   Molecule m = feta->find_by_name (symbolname);
71   if (!m.empty_b()) 
72     return m;
73
74   /*
75     Second guess: s contains the full signature name
76   */
77   m = feta->find_by_name ("timesig-" + s);
78   if (!m.empty_b ()) 
79     return m;
80
81   // Resort to default layout with numbers
82   return time_signature (me, n, d);
83 }
84
85
86 Molecule
87 Time_signature::time_signature (Score_element*me,int num, int den)
88 {
89   SCM chain = Font_interface::font_alist_chain (me);
90
91   Molecule n = Text_item::text2molecule (me,
92                                          ly_str02scm (to_str (num).ch_C ()),
93                                          chain);
94   Molecule d = Text_item::text2molecule (me,
95                                          ly_str02scm (to_str (den).ch_C ()),
96                                          chain);
97   n.align_to (X_AXIS, CENTER);
98   d.align_to (X_AXIS, CENTER);
99   Molecule m;
100   if (den)
101     {
102       m.add_at_edge (Y_AXIS, UP, n, 0.0);
103       m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
104     }
105   else
106     {
107       m = n;
108       m.align_to (Y_AXIS, CENTER);
109     }
110   return m;
111 }
112