2 cluster.cc -- implement Cluster
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2004 Juergen Reuter <reuter@ipd.uka.de>
8 Han-Wen Nienhuys <hanwen@cs.uu.nl>
19 #include "staff-symbol-referencer.hh"
21 #include "output-def.hh"
26 TODO: Add support for cubic spline segments.
30 brew_cluster_piece (Grob *me, Array<Offset> bottom_points, Array<Offset> top_points)
32 Real blotdiameter = Staff_symbol_referencer::staff_space (me)/2;
34 Real padding =robust_scm2double ( me->get_property ("padding"), 0.0);
36 Offset vpadding = Offset (0, padding);
37 Offset hpadding = Offset (0.5 * blotdiameter, 0);
38 Offset hvpadding = 0.5 * hpadding + vpadding;
40 SCM shape_scm = me->get_property ("style");
43 if (scm_is_symbol (shape_scm))
45 shape = ly_symbol2string (shape_scm);
49 programming_error ("#'style should be symbol.");
58 int size = bottom_points.size ();
59 if (String::compare (shape, "leftsided-stairs") == 0)
61 for (int i = 0; i < size - 1; i++)
64 box.add_point (bottom_points[i] - hvpadding);
65 box.add_point (Offset (top_points[i + 1][X_AXIS],
66 top_points[i][Y_AXIS]) + hvpadding);
67 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
70 else if (String::compare (shape, "rightsided-stairs") == 0)
72 for (int i = 0; i < size - 1; i++)
75 box.add_point (Offset (bottom_points[i][X_AXIS],
76 bottom_points[i + 1][Y_AXIS]) - hvpadding);
77 box.add_point (top_points[i + 1] + hvpadding);
78 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
81 else if (String::compare (shape, "centered-stairs") == 0)
83 Real left_xmid = bottom_points[0][X_AXIS];
84 for (int i = 0; i < size - 1; i++)
87 0.5 * (bottom_points[i][X_AXIS] + bottom_points[i + 1][X_AXIS]);
89 box.add_point (Offset (left_xmid, bottom_points[i][Y_AXIS]) -
91 box.add_point (Offset (right_xmid, top_points[i][Y_AXIS]) +
93 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
94 left_xmid = right_xmid;
96 Real right_xmid = bottom_points[size - 1][X_AXIS];
98 box.add_point (Offset (left_xmid, bottom_points[size - 1][Y_AXIS]) -
100 box.add_point (Offset (right_xmid, top_points[size - 1][Y_AXIS]) +
102 out.add_stencil (Lookup::round_filled_box (box, blotdiameter));
104 else if (String::compare (shape, "ramp") == 0)
106 points.push (bottom_points[0] - vpadding + hpadding);
107 for (int i = 1; i < size - 1; i++)
109 points.push (bottom_points[i] - vpadding);
111 points.push (bottom_points[size - 1] - vpadding - hpadding);
112 points.push (top_points[size - 1] + vpadding - hpadding);
113 for (int i = size - 2; i > 0; i--)
115 points.push (top_points[i] + vpadding);
117 points.push (top_points[0] + vpadding + hpadding);
118 out.add_stencil (Lookup::round_filled_polygon (points, blotdiameter));
122 me->warning (_f ("unknown cluster style `%s'", shape.to_str0 ()));
127 MAKE_SCHEME_CALLBACK (Cluster,print,1);
129 Cluster::print (SCM smob)
131 Grob *me = unsmob_grob (smob);
133 Spanner *spanner = dynamic_cast<Spanner*> (me);
136 me->programming_error ("Cluster::print (): not a spanner");
140 Item *left_bound = spanner->get_bound (LEFT);
141 Item *right_bound = spanner->get_bound (RIGHT);
143 Grob *commonx = left_bound->common_refpoint (right_bound, X_AXIS);
144 SCM cols =me->get_property ("columns");
146 if (!scm_is_pair (cols))
148 me->warning ("junking empty cluster");
154 commonx = common_refpoint_of_list (cols, commonx, X_AXIS);
155 Grob * commony = common_refpoint_of_list (cols, me, Y_AXIS);
156 Array<Offset> bottom_points;
157 Array<Offset> top_points;
160 Real left_coord = left_bound->relative_coordinate (commonx, X_AXIS);
163 TODO: should we move the cluster a little to the right to be in
164 line with the center of the note heads?
167 for (SCM s = cols; scm_is_pair (s); s = scm_cdr (s))
169 Grob * col = unsmob_grob (scm_car (s));
170 Interval yext = col->extent (commony, Y_AXIS);
172 Real x = col->relative_coordinate (commonx, X_AXIS) - left_coord;
173 bottom_points.push (Offset (x, yext[DOWN]));
174 top_points.push (Offset (x, yext[UP]));
178 Across a line break we anticipate on the next pitches.
180 if (spanner->original_)
182 Spanner *orig = dynamic_cast<Spanner*> (spanner->original_);
184 if (spanner->get_break_index () < orig->broken_intos_.size ()-1)
186 Spanner * next = orig->broken_intos_[spanner->get_break_index () + 1];
187 SCM cols = next->get_property ("columns");
188 if (scm_is_pair (cols))
190 Grob *next_commony = common_refpoint_of_list (cols, next, Y_AXIS);
191 Grob * col = unsmob_grob (scm_car (scm_last_pair (cols)));
193 Interval v = col->extent (next_commony, Y_AXIS);
194 Real x = right_bound->relative_coordinate (commonx, X_AXIS) - left_coord;
196 bottom_points.insert (Offset (x, v[DOWN]),0);
197 top_points.insert (Offset (x, v[UP]),0);
202 bottom_points.reverse ();
203 top_points.reverse ();
205 Stencil out = brew_cluster_piece (me, bottom_points, top_points);
206 out.translate_axis (- me->relative_coordinate (commony, Y_AXIS), Y_AXIS);
207 return out.smobbed_copy ();
210 ADD_INTERFACE (Cluster,"cluster-interface",
211 "A graphically drawn musical cluster. "
213 "@code{padding} adds to the vertical extent of the shape (top and "
215 "The property @code{style} controls the shape of cluster segments. Valid values "
216 "include @code{leftsided-stairs}, @code{rightsided-stairs}, @code{centered-stairs}, "
219 "style padding columns");
223 struct Cluster_beacon
226 DECLARE_SCHEME_CALLBACK (height, (SCM, SCM));
227 static bool has_interface (Grob *);
230 MAKE_SCHEME_CALLBACK (Cluster_beacon,height,2);
232 Cluster_beacon::height (SCM g, SCM)
234 Grob *me = unsmob_grob (g);
235 Interval v = robust_scm2interval (me->get_property ("positions"),
237 return ly_interval2scm (Staff_symbol_referencer::staff_space (me) * 0.5 * v);
242 ADD_INTERFACE(Cluster_beacon,
243 "cluster-beacon-interface",
244 "A place holder for the cluster spanner to determine the vertical "
245 "extents of a cluster spanner at this X position.",