]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature.cc
patch::: 1.5.11.jcn2
[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--2001 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   TODO: make different functions for special and normal timesigs.
20  */
21 SCM
22 Time_signature::brew_molecule (SCM smob) 
23 {
24   Grob * me = unsmob_grob (smob);
25   SCM st = me->get_grob_property ("style");
26   SCM frac = me->get_grob_property ("fraction");
27   int n = 4;
28   int d = 4;
29   if (gh_pair_p (frac))
30     {
31       n = gh_scm2int (ly_car (frac));
32       d = gh_scm2int (ly_cdr (frac));
33     }
34
35   
36   if (gh_symbol_p (st))
37     {
38       String style (ly_scm2string (scm_symbol_to_string (st)));
39       if (style[0]=='1')
40         {
41           return time_signature (me, n, 0).smobbed_copy ();
42         }
43       else
44         {
45           return special_time_signature (me, style, n, d).smobbed_copy ();
46         }
47     }
48   else
49     return time_signature (me, n,d).smobbed_copy ();
50 }
51
52 Molecule
53 Time_signature::special_time_signature (Grob*me, String s, int n, int d)
54 {
55   /*
56     Randomly probing the font sucks?
57   */
58   
59   SCM alist_chain = Font_interface::font_alist_chain (me);
60   
61   SCM style_chain =
62     Font_interface::add_style (me, ly_symbol2scm ("timesig-symbol"),
63                                alist_chain);
64
65   Font_metric *feta = Font_interface::get_font (me, style_chain);
66
67   /*
68     First guess: s contains only the signature style, append fraction.
69   */
70   String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
71   
72   Molecule m = feta->find_by_name (symbolname);
73   if (!m.empty_b ()) 
74     return m;
75
76   /*
77     Second guess: s contains the full signature name
78   */
79   m = feta->find_by_name ("timesig-" + s);
80   if (!m.empty_b ()) 
81     return m;
82
83   // Resort to default layout with numbers
84   return time_signature (me, n, d);
85 }
86
87
88 Molecule
89 Time_signature::time_signature (Grob*me,int num, int den)
90 {
91   SCM chain = Font_interface::font_alist_chain (me);
92
93   Molecule n = Text_item::text2molecule (me,
94                                          ly_str02scm (to_str (num).ch_C ()),
95                                          chain);
96   Molecule d = Text_item::text2molecule (me,
97                                          ly_str02scm (to_str (den).ch_C ()),
98                                          chain);
99   n.align_to (X_AXIS, CENTER);
100   d.align_to (X_AXIS, CENTER);
101   Molecule m;
102   if (den)
103     {
104       m.add_at_edge (Y_AXIS, UP, n, 0.0);
105       m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
106     }
107   else
108     {
109       m = n;
110       m.align_to (Y_AXIS, CENTER);
111     }
112   return m;
113 }
114