2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2015 Juergen Reuter <reuter@ipd.uka.de>
5 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 #include "international.hh"
25 #include "output-def.hh"
27 #include "pointer-group-interface.hh"
29 #include "staff-symbol-referencer.hh"
36 TODO: Add support for cubic spline segments.
39 brew_cluster_piece (Grob *me, vector<Offset> bottom_points, vector<Offset> top_points)
41 Real blotdiameter = Staff_symbol_referencer::staff_space (me) / 2;
43 Real padding = robust_scm2double (me->get_property ("padding"), 0.0);
45 Offset vpadding = Offset (0, padding);
46 Offset hpadding = Offset (0.5 * blotdiameter, 0);
47 Offset hvpadding = 0.5 * hpadding + vpadding;
49 SCM shape_scm = me->get_property ("style");
52 if (scm_is_symbol (shape_scm))
53 shape = ly_symbol2string (shape_scm);
56 programming_error ("#'style should be symbol.");
62 vector<Offset> points;
64 int size = bottom_points.size ();
65 if (shape == "leftsided-stairs")
67 for (int i = 0; i < size - 1; i++)
70 box.add_point (bottom_points[i] - hvpadding);
71 box.add_point (Offset (top_points[i + 1][X_AXIS],
72 top_points[i][Y_AXIS]) + hvpadding);
73 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
76 else if (shape == "rightsided-stairs")
78 for (int i = 0; i < size - 1; i++)
81 box.add_point (Offset (bottom_points[i][X_AXIS],
82 bottom_points[i + 1][Y_AXIS]) - hvpadding);
83 box.add_point (top_points[i + 1] + hvpadding);
84 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
87 else if (shape == "centered-stairs")
89 Real left_xmid = bottom_points[0][X_AXIS];
90 for (int i = 0; i < size - 1; i++)
93 = 0.5 * (bottom_points[i][X_AXIS] + bottom_points[i + 1][X_AXIS]);
95 box.add_point (Offset (left_xmid, bottom_points[i][Y_AXIS])
97 box.add_point (Offset (right_xmid, top_points[i][Y_AXIS])
99 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
100 left_xmid = right_xmid;
102 Real right_xmid = bottom_points[size - 1][X_AXIS];
104 box.add_point (Offset (left_xmid, bottom_points[size - 1][Y_AXIS])
106 box.add_point (Offset (right_xmid, top_points[size - 1][Y_AXIS])
108 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
110 else if (shape == "ramp")
112 points.push_back (bottom_points[0] - vpadding + hpadding);
113 for (int i = 1; i < size - 1; i++)
114 points.push_back (bottom_points[i] - vpadding);
115 points.push_back (bottom_points[size - 1] - vpadding - hpadding);
116 points.push_back (top_points[size - 1] + vpadding - hpadding);
117 for (int i = size - 2; i > 0; i--)
118 points.push_back (top_points[i] + vpadding);
119 points.push_back (top_points[0] + vpadding + hpadding);
120 out.add_stencil (Lookup::round_filled_polygon (points, blotdiameter));
123 me->warning (_f ("unknown cluster style `%s'", shape.c_str ()));
127 MAKE_SCHEME_CALLBACK (Cluster, calc_cross_staff, 1);
129 Cluster::calc_cross_staff (SCM smob)
131 Grob *me = unsmob<Grob> (smob);
133 extract_grob_set (me, "columns", cols);
134 Grob *commony = common_refpoint_of_array (cols, me, Y_AXIS);
136 return scm_from_bool (commony != me->get_parent (Y_AXIS));
139 MAKE_SCHEME_CALLBACK (Cluster, print, 1);
141 Cluster::print (SCM smob)
143 Grob *me = unsmob<Grob> (smob);
145 Spanner *spanner = dynamic_cast<Spanner *> (me);
148 me->programming_error ("Cluster::print (): not a spanner");
152 Item *left_bound = spanner->get_bound (LEFT);
153 Item *right_bound = spanner->get_bound (RIGHT);
155 Grob *commonx = left_bound->common_refpoint (right_bound, X_AXIS);
157 vector<Grob *> const &cols = extract_grob_array (me, "columns");
160 me->warning (_ ("junking empty cluster"));
166 commonx = common_refpoint_of_array (cols, commonx, X_AXIS);
167 Grob *commony = common_refpoint_of_array (cols, me, Y_AXIS);
168 vector<Offset> bottom_points;
169 vector<Offset> top_points;
171 Real left_coord = left_bound->relative_coordinate (commonx, X_AXIS);
174 TODO: should we move the cluster a little to the right to be in
175 line with the center of the note heads?
178 for (vsize i = 0; i < cols.size (); i++)
182 Interval yext = col->extent (commony, Y_AXIS);
184 Real x = col->relative_coordinate (commonx, X_AXIS) - left_coord;
185 bottom_points.push_back (Offset (x, yext[DOWN]));
186 top_points.push_back (Offset (x, yext[UP]));
190 Across a line break we anticipate on the next pitches.
192 if (Spanner *next = spanner->broken_neighbor (RIGHT))
194 extract_grob_set (next, "columns", next_cols);
195 if (next_cols.size () > 0)
197 Grob *next_commony = common_refpoint_of_array (next_cols, next, Y_AXIS);
198 Grob *col = next_cols[0];
200 Interval v = col->extent (next_commony, Y_AXIS);
201 Real x = right_bound->relative_coordinate (commonx, X_AXIS) - left_coord;
203 bottom_points.push_back (Offset (x, v[DOWN]));
204 top_points.push_back (Offset (x, v[UP]));
208 Stencil out = brew_cluster_piece (me, bottom_points, top_points);
209 out.translate_axis (- me->relative_coordinate (commony, Y_AXIS), Y_AXIS);
210 return out.smobbed_copy ();
213 ADD_INTERFACE (Cluster,
214 "A graphically drawn musical cluster.\n"
216 "@code{padding} adds to the vertical extent of the shape (top"
219 "The property @code{style} controls the shape of cluster"
220 " segments. Valid values include @code{leftsided-stairs},"
221 " @code{rightsided-stairs}, @code{centered-stairs}, and"
230 struct Cluster_beacon
233 DECLARE_SCHEME_CALLBACK (height, (SCM));
236 MAKE_SCHEME_CALLBACK (Cluster_beacon, height, 1);
238 Cluster_beacon::height (SCM g)
240 Grob *me = unsmob<Grob> (g);
241 Interval v = robust_scm2interval (me->get_property ("positions"),
243 return ly_interval2scm (Staff_symbol_referencer::staff_space (me) * 0.5 * v);
246 ADD_INTERFACE (Cluster_beacon,
247 "A place holder for the cluster spanner to determine the"
248 " vertical extents of a cluster spanner at this"