lilypond-1.5.9
[lilypond.git] / lily / time-signature.cc
blob8e516e8ccdb49bff1de649e01cbb073f93ed7aa3
1 /*
2 time-signature.cc -- implement Time_signature
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
11 #include "molecule.hh"
12 #include "text-item.hh"
13 #include "time-signature.hh"
14 #include "paper-def.hh"
15 #include "font-interface.hh"
17 MAKE_SCHEME_CALLBACK (Time_signature,brew_molecule,1);
19 TODO: make different functions for special and normal timesigs.
21 SCM
22 Time_signature::brew_molecule (SCM smob)
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))
31 n = gh_scm2int (gh_car (frac));
32 d = gh_scm2int (gh_cdr (frac));
36 if (gh_symbol_p (st))
38 String style (ly_scm2string (scm_symbol_to_string (st)));
39 if (style[0]=='1')
41 return time_signature (me, n, 0).smobbed_copy ();
43 else
45 return special_time_signature (me, style, n, d).smobbed_copy ();
48 else
49 return time_signature (me, n,d).smobbed_copy ();
52 Molecule
53 Time_signature::special_time_signature (Grob*me, String s, int n, int d)
56 Randomly probing the font sucks?
59 SCM alist_chain = Font_interface::font_alist_chain (me);
61 SCM style_chain =
62 Font_interface::add_style (me, ly_symbol2scm ("timesig-symbol"),
63 alist_chain);
65 Font_metric *feta = Font_interface::get_font (me, style_chain);
68 First guess: s contains only the signature style, append fraction.
70 String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
72 Molecule m = feta->find_by_name (symbolname);
73 if (!m.empty_b ())
74 return m;
77 Second guess: s contains the full signature name
79 m = feta->find_by_name ("timesig-" + s);
80 if (!m.empty_b ())
81 return m;
83 // Resort to default layout with numbers
84 return time_signature (me, n, d);
88 Molecule
89 Time_signature::time_signature (Grob*me,int num, int den)
91 SCM chain = Font_interface::font_alist_chain (me);
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)
104 m.add_at_edge (Y_AXIS, UP, n, 0.0);
105 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
107 else
109 m = n;
110 m.align_to (Y_AXIS, CENTER);
112 return m;