]> git.donarmstrong.com Git - lilypond.git/blob - lily/measure-grouping-spanner.cc
* scm/define-grob-properties.scm: remove 'type
[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_var ("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.empty_b()
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   if (which == ly_symbol2scm ("bracket"))
44     {
45       m = Lookup::bracket (X_AXIS, iv, t,-gh_scm2double (height));
46     }
47   else if (which == ly_symbol2scm ("triangle"))
48     {
49       m = Lookup::triangle (iv, t, gh_scm2double (height));
50     }
51
52   m.align_to (Y_AXIS, DOWN);
53   return m.smobbed_copy();
54 }
55
56 ADD_INTERFACE (Measure_grouping,"measure-grouping-interface",
57                "indicate groups of beats. Valid choices for 'type are 'bracket and 'triangle.",
58                "thickness style height");
59
60