lilypond-1.3.74
[lilypond.git] / lily / time-signature.cc
blob5cc5118cdb7dca1ae28c8a0a77feb4b528f22b76
1 /*
2 time-signature.cc -- implement Time_signature
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
11 #include "molecule.hh"
12 #include "time-signature.hh"
13 #include "paper-def.hh"
14 #include "lookup.hh"
16 MAKE_SCHEME_CALLBACK(Time_signature,brew_molecule);
18 SCM
19 Time_signature::brew_molecule (SCM smob)
21 Score_element * me = unsmob_element (smob);
22 SCM st = me->get_elt_property ("style");
23 SCM frac = me->get_elt_property ("fraction");
24 int n = 4;
25 int d = 4;
26 if (gh_pair_p (frac))
28 n = gh_scm2int (gh_car (frac));
29 d = gh_scm2int (gh_cdr (frac));
33 if (gh_string_p (st))
35 String style (ly_scm2string (st));
36 if (style[0]=='1')
38 return time_signature (me, n, 0).create_scheme();
40 else
42 return special_time_signature (me, style, n, d).create_scheme();
45 else
46 return time_signature (me, n,d).create_scheme();
49 Molecule
50 Time_signature::special_time_signature (Score_element*me, String s, int n, int d)
52 // First guess: s contains only the signature style
53 String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
55 Molecule m = me->lookup_l ()->afm_find (symbolname, false);
56 if (!m.empty_b())
57 return m;
59 // Second guess: s contains the full signature name
60 m = me->lookup_l ()->afm_find ("timesig-"+s, false);
61 if (!m.empty_b ())
62 return m;
64 // Resort to default layout with numbers
65 return time_signature (me, n,d);
69 Molecule
70 Time_signature::time_signature (Score_element*me,int num, int den)
72 String sty = "timesig";
75 UGH: need to look at fontsize.
77 Molecule n (me->lookup_l ()->text (sty, to_str (num), me->paper_l ()));
78 Molecule d (me->lookup_l ()->text (sty, to_str (den), me->paper_l ()));
79 n.align_to (X_AXIS, CENTER);
80 d.align_to (X_AXIS, CENTER);
81 Molecule m;
82 if (den)
84 m.add_at_edge (Y_AXIS, UP, n, 0.0);
85 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
87 else
89 m = n;
90 m.align_to (Y_AXIS, CENTER);
92 return m;