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