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);
47 return ly_interval2scm (Interval (-height/2, height/2));
51 Hairpin::consider_suicide (Spanner*me)
53 Drul_array<bool> broken;
54 Drul_array<Item *> bounds;
58 bounds[d] = me->get_bound (d);
59 broken[d] = bounds[d]->break_status_dir () != CENTER;
61 while (flip (&d) != LEFT);
64 && ly_is_equal (bounds[RIGHT]->get_column ()->get_property ("when"),
65 bounds[LEFT]->get_property ("when")))
69 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
72 Hairpin::print (SCM smob)
74 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
76 if (Spanner *orig = dynamic_cast<Spanner*> (me->original ()))
78 for (vsize i = 0; i < orig->broken_intos_.size (); i++)
79 Hairpin::consider_suicide (orig->broken_intos_[i]);
82 SCM s = me->get_property ("grow-direction");
83 if (!is_direction (s))
89 Direction grow_dir = to_dir (s);
90 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
92 Drul_array<bool> broken;
93 Drul_array<Item *> bounds;
97 bounds[d] = me->get_bound (d);
98 broken[d] = bounds[d]->break_status_dir () != CENTER;
100 while (flip (&d) != LEFT);
102 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT);
103 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT)->is_live ();
107 Spanner *next = me->broken_neighbor (RIGHT);
108 Stencil *s = next->get_stencil ();
109 if (!s || s->is_empty ())
110 broken[RIGHT] = false;
113 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
114 Drul_array<Real> x_points;
117 Use the height and thickness of the hairpin when making a circled tip
119 bool circled_tip = ly_scm2bool (me->get_property ("circled-tip"));
120 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
121 Staff_symbol_referencer::staff_space (me);
123 FIXME: 0.525 is still just a guess...
125 Real rad = height * 0.525;
128 thick = robust_scm2double (me->get_property ("thickness"), 1.0)
129 * Staff_symbol_referencer::line_thickness (me);
134 x_points[d] = b->relative_coordinate (common, X_AXIS);
138 x_points[d] = b->extent (common, X_AXIS)[RIGHT];
142 if (Text_interface::has_interface (b))
144 Interval e = b->extent (common, X_AXIS);
146 x_points[d] = e[-d] - d * padding;
150 bool neighbor_found = false;
151 extract_grob_set (me, "adjacent-hairpins", pins);
152 for (vsize i = 0; i < pins.size (); i++)
155 FIXME: this will fuck up in case of polyphonic
156 notes in other voices. Need to look at note-columns
157 in the current staff/voice.
160 Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
162 && (pin->get_bound (LEFT)->get_column () == b->get_column ()
163 || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
164 neighbor_found = true;
167 Interval e = robust_relative_extent (b, common, X_AXIS);
171 Handle back-to-back hairpins with a circle in the middle
173 if (circled_tip && (grow_dir != d))
174 x_points[d] = e.center () + d * (rad - thick / 2.0);
176 If we're hung on a paper column, that means we're not
177 adjacent to a text-dynamic, and we may move closer. We
178 make the padding a little smaller, here.
181 x_points[d] = e.center () - d * padding / 3;
185 if (Note_column::has_interface (b)
186 && Note_column::has_rests (b))
191 Item *bound = me->get_bound (d);
192 if (bound->is_non_musical (bound))
193 x_points[d] -= d * padding;
198 while (flip (&d) != LEFT);
200 Real width = x_points[RIGHT] - x_points[LEFT];
203 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
204 : "crescendo too small"));
208 bool continued = broken[Direction (-grow_dir)];
215 endh = continued ? height / 2 : 0.0;
219 starth = continued ? height / 2 : 0.0;
224 should do relative to staff-symbol staff-space?
230 Compensate for size of circle
232 Direction tip_dir = -grow_dir;
233 if (circled_tip && !broken[tip_dir])
237 else if (grow_dir < 0)
240 mol = Line_interface::line (me, Offset (x, starth), Offset (width, endh));
241 mol.add_stencil (Line_interface::line (me,
243 Offset (width, -endh)));
246 Support al/del niente notation by putting a circle at the
247 tip of the (de)crescendo.
251 Box extent (Interval (-rad, rad), Interval (-rad, rad));
253 /* Hmmm, perhaps we should have a Lookup::circle () method? */
254 Stencil circle (extent,
255 scm_list_4 (ly_symbol2scm ("circle"),
256 scm_from_double (rad),
257 scm_from_double (thick),
261 don't add another circle the hairpin is broken
263 if (!broken[tip_dir])
264 mol.add_at_edge (X_AXIS, tip_dir, Stencil (circle), 0);
267 mol.translate_axis (x_points[LEFT]
268 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
270 return mol.smobbed_copy ();
273 ADD_INTERFACE (Hairpin,
274 "A hairpin crescendo or decrescendo.",