2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "dimensions.hh"
12 #include "international.hh"
13 #include "line-interface.hh"
14 #include "output-def.hh"
15 #include "paper-column.hh"
16 #include "pointer-group-interface.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "text-interface.hh"
20 #include "note-column.hh"
23 MAKE_SCHEME_CALLBACK (Hairpin, after_line_breaking, 1);
25 Hairpin::after_line_breaking (SCM smob)
27 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
28 consider_suicide (me);
30 return SCM_UNSPECIFIED;
33 MAKE_SCHEME_CALLBACK (Hairpin, height, 1);
35 Hairpin::height (SCM smob)
37 return Grob::stencil_height (smob);
40 MAKE_SCHEME_CALLBACK (Hairpin, pure_height, 3);
42 Hairpin::pure_height (SCM smob, SCM, SCM)
44 Grob *me = unsmob_grob (smob);
45 Real height = robust_scm2double (me->get_property ("height"), 0.0)
46 * Staff_symbol_referencer::staff_space (me);
48 Real thickness = robust_scm2double (me->get_property ("thickness"), 1)
49 * Staff_symbol_referencer::line_thickness (me);
51 height += thickness / 2;
52 return ly_interval2scm (Interval (-height, height));
56 Hairpin::consider_suicide (Spanner*me)
58 Drul_array<bool> broken;
59 Drul_array<Item *> bounds;
63 bounds[d] = me->get_bound (d);
64 broken[d] = bounds[d]->break_status_dir () != CENTER;
66 while (flip (&d) != LEFT);
69 && ly_is_equal (bounds[RIGHT]->get_column ()->get_property ("when"),
70 bounds[LEFT]->get_property ("when")))
74 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
77 Hairpin::print (SCM smob)
79 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
81 if (Spanner *orig = dynamic_cast<Spanner*> (me->original ()))
83 for (vsize i = 0; i < orig->broken_intos_.size (); i++)
84 Hairpin::consider_suicide (orig->broken_intos_[i]);
87 SCM s = me->get_property ("grow-direction");
88 if (!is_direction (s))
94 Direction grow_dir = to_dir (s);
95 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
97 Drul_array<bool> broken;
98 Drul_array<Item *> bounds;
102 bounds[d] = me->get_bound (d);
103 broken[d] = bounds[d]->break_status_dir () != CENTER;
105 while (flip (&d) != LEFT);
107 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT);
108 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT)->is_live ();
112 Spanner *next = me->broken_neighbor (RIGHT);
113 Stencil *s = next->get_stencil ();
114 if (!s || s->is_empty ())
115 broken[RIGHT] = false;
118 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
119 Drul_array<Real> x_points;
122 Use the height and thickness of the hairpin when making a circled tip
124 bool circled_tip = ly_scm2bool (me->get_property ("circled-tip"));
125 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
126 Staff_symbol_referencer::staff_space (me);
128 FIXME: 0.525 is still just a guess...
130 Real rad = height * 0.525;
133 thick = robust_scm2double (me->get_property ("thickness"), 1.0)
134 * Staff_symbol_referencer::line_thickness (me);
139 x_points[d] = b->relative_coordinate (common, X_AXIS);
143 x_points[d] = b->extent (common, X_AXIS)[RIGHT];
147 if (Text_interface::has_interface (b))
149 Interval e = b->extent (common, X_AXIS);
151 x_points[d] = e[-d] - d * padding;
155 bool neighbor_found = false;
156 extract_grob_set (me, "adjacent-hairpins", pins);
157 for (vsize i = 0; i < pins.size (); i++)
160 FIXME: this will fuck up in case of polyphonic
161 notes in other voices. Need to look at note-columns
162 in the current staff/voice.
165 Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
167 && (pin->get_bound (LEFT)->get_column () == b->get_column ()
168 || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
169 neighbor_found = true;
172 Interval e = robust_relative_extent (b, common, X_AXIS);
176 Handle back-to-back hairpins with a circle in the middle
178 if (circled_tip && (grow_dir != d))
179 x_points[d] = e.center () + d * (rad - thick / 2.0);
181 If we're hung on a paper column, that means we're not
182 adjacent to a text-dynamic, and we may move closer. We
183 make the padding a little smaller, here.
186 x_points[d] = e.center () - d * padding / 3;
190 if (Note_column::has_interface (b)
191 && Note_column::has_rests (b))
196 Item *bound = me->get_bound (d);
197 if (bound->is_non_musical (bound))
198 x_points[d] -= d * padding;
203 while (flip (&d) != LEFT);
205 Real width = x_points[RIGHT] - x_points[LEFT];
208 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
209 : "crescendo too small"));
213 bool continued = broken[Direction (-grow_dir)];
220 endh = continued ? height / 2 : 0.0;
224 starth = continued ? height / 2 : 0.0;
229 should do relative to staff-symbol staff-space?
235 Compensate for size of circle
237 Direction tip_dir = -grow_dir;
238 if (circled_tip && !broken[tip_dir])
242 else if (grow_dir < 0)
245 mol = Line_interface::line (me, Offset (x, starth), Offset (width, endh));
246 mol.add_stencil (Line_interface::line (me,
248 Offset (width, -endh)));
251 Support al/del niente notation by putting a circle at the
252 tip of the (de)crescendo.
256 Box extent (Interval (-rad, rad), Interval (-rad, rad));
258 /* Hmmm, perhaps we should have a Lookup::circle () method? */
259 Stencil circle (extent,
260 scm_list_4 (ly_symbol2scm ("circle"),
261 scm_from_double (rad),
262 scm_from_double (thick),
266 don't add another circle the hairpin is broken
268 if (!broken[tip_dir])
269 mol.add_at_edge (X_AXIS, tip_dir, Stencil (circle), 0);
272 mol.translate_axis (x_points[LEFT]
273 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
275 return mol.smobbed_copy ();
278 ADD_INTERFACE (Hairpin,
279 "A hairpin crescendo or decrescendo.",