2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "dimensions.hh"
12 #include "font-interface.hh"
13 #include "international.hh"
14 #include "line-interface.hh"
16 #include "output-def.hh"
17 #include "paper-column.hh"
18 #include "pointer-group-interface.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "text-interface.hh"
24 MAKE_SCHEME_CALLBACK (Hairpin, after_line_breaking, 1);
26 Hairpin::after_line_breaking (SCM smob)
28 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
29 consider_suicide (me);
31 return SCM_UNSPECIFIED;
35 Hairpin::consider_suicide (Spanner*me)
37 Drul_array<bool> broken;
38 Drul_array<Item *> bounds;
42 bounds[d] = me->get_bound (d);
43 broken[d] = bounds[d]->break_status_dir () != CENTER;
45 while (flip (&d) != LEFT);
48 && ly_is_equal (bounds[RIGHT]->get_column ()->get_property ("when"),
49 bounds[LEFT]->get_property ("when")))
54 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
57 Hairpin::print (SCM smob)
59 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
61 consider_suicide (me);
62 SCM s = me->get_property ("grow-direction");
63 if (!is_direction (s))
69 Direction grow_dir = to_dir (s);
70 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
72 Drul_array<bool> broken;
73 Drul_array<Item *> bounds;
77 bounds[d] = me->get_bound (d);
78 broken[d] = bounds[d]->break_status_dir () != CENTER;
80 while (flip (&d) != LEFT);
83 Spanner *orig = dynamic_cast<Spanner*> (me->original ());
84 if (me->get_break_index ()
85 < orig->broken_intos_.size () - 1)
87 Spanner *next = orig->broken_intos_[me->get_break_index () + 1];
88 Stencil *s = next->get_stencil ();
89 if (!s || s->is_empty ())
90 broken[RIGHT] = false;
94 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
95 Drul_array<Real> x_points;
98 Use the height and thickness of the hairpin when making a circled tip
100 bool circled_tip = ly_scm2bool (me->get_property ("circled-tip"));
101 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
102 Staff_symbol_referencer::staff_space (me);
104 FIXME: 0.525 is still just a guess...
106 Real rad = height * 0.525;
109 thick = robust_scm2double (me->get_property ("thickness"), 1.0)
110 * Staff_symbol_referencer::line_thickness (me);
115 x_points[d] = b->relative_coordinate (common, X_AXIS);
119 x_points[d] = b->extent (common, X_AXIS)[RIGHT];
123 if (Text_interface::has_interface (b))
125 Interval e = b->extent (common, X_AXIS);
127 x_points[d] = e[-d] - d * padding;
131 bool neighbor_found = false;
132 extract_grob_set (me, "adjacent-hairpins", pins);
133 for (vsize i = 0; i < pins.size (); i++)
136 FIXME: this will fuck up in case of polyphonic
137 notes in other voices. Need to look at note-columns
138 in the current staff/voice.
141 Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
143 && (pin->get_bound (LEFT)->get_column () == b->get_column ()
144 || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
145 neighbor_found = true;
148 Interval e = robust_relative_extent (b, common, X_AXIS);
152 Handle back-to-back hairpins with a circle in the middle
154 if (circled_tip && (grow_dir != d))
155 x_points[d] = e.center () + d * (rad - thick / 2.0);
157 If we're hung on a paper column, that means we're not
158 adjacent to a text-dynamic, and we may move closer. We
159 make the padding a little smaller, here.
162 x_points[d] = e.center () - d * padding / 3;
169 while (flip (&d) != LEFT);
171 Real width = x_points[RIGHT] - x_points[LEFT];
174 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
175 : "crescendo too small"));
179 bool continued = broken[Direction (-grow_dir)];
185 endh = continued ? height / 2 : 0.0;
189 starth = continued ? height / 2 : 0.0;
194 should do relative to staff-symbol staff-space?
201 Compensate for size of circle
203 Direction tip_dir = -grow_dir;
204 if (circled_tip && !broken[tip_dir])
208 else if (grow_dir < 0)
211 mol = Line_interface::line (me, Offset (x, starth), Offset (width, endh));
212 mol.add_stencil (Line_interface::line (me,
214 Offset (width, -endh)));
217 Support al/del niente notation by putting a circle at the
218 tip of the (de)crescendo.
222 Box extent (Interval (-rad, rad), Interval (-rad, rad));
224 /* Hmmm, perhaps we should have a Lookup::circle () method? */
225 Stencil circle(extent,
226 scm_list_4 (ly_symbol2scm ("circle"),
227 scm_from_double (rad),
228 scm_from_double (thick),
232 don't add another circle the hairpin is broken
234 if (!broken[tip_dir])
235 mol.add_at_edge (X_AXIS, tip_dir, Stencil (circle), 0, 0);
238 mol.translate_axis (x_points[LEFT]
239 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
241 return mol.smobbed_copy ();
244 ADD_INTERFACE (Hairpin, "hairpin-interface",
245 "A hairpin crescendo/decrescendo.",