]> git.donarmstrong.com Git - lilypond.git/blob - lily/ambitus.cc
* lily/include/group-interface.hh (extract_grob_array): rename
[lilypond.git] / lily / ambitus.cc
1 /*
2   ambitus.cc -- implement Ambitus
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2005 Juergen Reuter <reuter@ipd.uka.de>
7 */
8
9 #include "ambitus.hh"
10
11 #include "staff-symbol-referencer.hh"
12 #include "pitch.hh"
13 #include "note-head.hh"
14 #include "item.hh"
15 #include "font-interface.hh"
16 #include "output-def.hh"
17 #include "lookup.hh"
18 #include "group-interface.hh"
19
20 MAKE_SCHEME_CALLBACK (Ambitus, print, 1);
21 SCM
22 Ambitus::print (SCM smob)
23 {
24   Item *me = (Item*) unsmob_grob (smob);
25   Stencil stencil;
26
27   // join heads
28   Link_array<Grob> heads (extract_grob_array (me, ly_symbol2scm ("note-heads")));
29   if (to_boolean (me->get_property ("join-heads"))
30       && heads.size() > 1)
31     {
32       Grob *common
33         = common_refpoint_of_array (heads.slice (0, 2), me, Y_AXIS);
34
35       Grob *minh = heads[0];
36       Grob *maxh = heads[1];
37       
38       if (minh->relative_coordinate (common, Y_AXIS) >
39           maxh->relative_coordinate (common, Y_AXIS))
40         {
41           Grob *t = maxh;
42           maxh = minh;
43           minh = t;
44         }
45
46       Real pad = 0.35;
47       Real pmax = maxh->extent (common, Y_AXIS)[DOWN] - pad;
48       Real pmin = minh->extent (common, Y_AXIS)[UP] + pad;
49       
50       if (pmin < pmax)
51         {
52           Real linethickness = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"))
53             * robust_scm2double (me->get_property ("thickness"), 1.0); 
54           Real blotdiameter = me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"));
55           Interval x_extent = 0.5 * linethickness *Interval (-1, 1);
56           Interval y_extent = Interval (pmin, pmax);
57           Box line_box (x_extent, y_extent);
58
59           Stencil line = Lookup::round_filled_box (line_box, blotdiameter);
60           line.translate_axis (- me-> relative_coordinate (common, Y_AXIS),
61                                    Y_AXIS);
62           return line.smobbed_copy ();
63         }
64     }
65
66   return SCM_EOL;
67 }
68
69 ADD_INTERFACE (Ambitus, "ambitus-interface",
70   "The line between note heads for a pitch range.",
71   "thickness note-heads join-heads");