lilypond-1.3.65
[lilypond.git] / lily / time-signature.cc
blob50c45abd4c4dc0e812ee73779bd0de4a49bfbd6a
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 Time_signature::Time_signature (SCM s)
17 : Item (s)
22 // ugh.!
24 GLUE_SCORE_ELEMENT(Time_signature,brew_molecule);
25 SCM
26 Time_signature::member_brew_molecule () const
28 SCM st = get_elt_property ("style");
30 SCM frac = get_elt_property ("fraction");
31 int n = 4;
32 int d = 4;
33 if (gh_pair_p (frac))
35 n = gh_scm2int (gh_car (frac));
36 d = gh_scm2int (gh_cdr (frac));
40 if (gh_string_p (st))
42 String style (ly_scm2string (st));
43 if (style[0]=='1')
45 return time_signature (n, 0).create_scheme();
47 else
49 return special_time_signature (style, n, d).create_scheme();
52 else
53 return time_signature (n,d).create_scheme();
56 Molecule
57 Time_signature::special_time_signature (String s, int n, int d) const
59 // First guess: s contains only the signature style
60 String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
62 Molecule m = lookup_l ()->afm_find (symbolname, false);
63 if (!m.empty_b())
64 return m;
66 // Second guess: s contains the full signature name
67 m = lookup_l ()->afm_find ("timesig-"+s, false);
68 if (!m.empty_b ())
69 return m;
71 // Resort to default layout with numbers
72 return time_signature (n,d);
76 Molecule
77 Time_signature::time_signature (int num, int den) const
79 String sty = "timesig";
82 UGH: need to look at fontsize.
84 Molecule n (lookup_l ()->text (sty, to_str (num), paper_l ()));
85 Molecule d (lookup_l ()->text (sty, to_str (den), paper_l ()));
86 n.align_to (X_AXIS, CENTER);
87 d.align_to (X_AXIS, CENTER);
88 Molecule m;
89 if (den)
91 m.add_at_edge (Y_AXIS, UP, n, 0.0);
92 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
94 else
96 m = n;
97 m.align_to (Y_AXIS, CENTER);
99 return m;