]> git.donarmstrong.com Git - lilypond.git/blob - lily/measure-grouping-spanner.cc
* lily/lily-guile.cc (robust_scm2double): new function. Use throughout.
[lilypond.git] / lily / measure-grouping-spanner.cc
1 /*   
2 measure-grouping-spanner.cc --  implement Measure_grouping
3
4 source file of the GNU LilyPond music typesetter
5
6 (c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8  */
9 #include "paper-def.hh"
10 #include "spanner.hh"
11 #include "measure-grouping-spanner.hh"
12 #include "lookup.hh" 
13 #include "item.hh"
14
15 MAKE_SCHEME_CALLBACK (Measure_grouping, brew_molecule, 1);
16 SCM 
17 Measure_grouping::brew_molecule (SCM grob)
18 {
19   Spanner * me = dynamic_cast<Spanner*> (unsmob_grob (grob));
20
21   /*
22     TODO: robustify.
23    */
24   SCM which = me->get_grob_property ("style");
25   SCM thick = me->get_grob_property ("thickness");
26   SCM height = me->get_grob_property ("height");
27
28   Real t = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")) * gh_scm2double (thick); 
29   Grob *common = me->get_bound(LEFT)->common_refpoint (me->get_bound (RIGHT),
30                                                        X_AXIS);
31
32   Interval rext = me->get_bound (RIGHT)->extent (common, X_AXIS);
33   
34   
35   Real w =(rext.is_empty ()
36            ? me->get_bound (RIGHT)->relative_coordinate (common, X_AXIS)
37            : rext[RIGHT])
38     - me->get_bound (LEFT)->relative_coordinate (common, X_AXIS);
39
40   Interval iv (0,w);
41
42   Molecule m;
43
44   /*
45     TODO: use line interface
46    */
47   if (which == ly_symbol2scm ("bracket"))
48     {
49       m = Lookup::bracket (X_AXIS, iv, t,-gh_scm2double (height), t);
50     }
51   else if (which == ly_symbol2scm ("triangle"))
52     {
53       m = Lookup::triangle (iv, t, gh_scm2double (height));
54     }
55
56   m.align_to (Y_AXIS, DOWN);
57   return m.smobbed_copy();
58 }
59
60 ADD_INTERFACE (Measure_grouping,"measure-grouping-interface",
61                "indicate groups of beats. Valid choices for 'type are 'bracket and 'triangle.",
62                "thickness style height");
63
64