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 if (Spanner *orig = dynamic_cast<Spanner*> (me->original ()))
63 for (vsize i = 0; i < orig->broken_intos_.size (); i++)
64 Hairpin::consider_suicide (orig->broken_intos_[i]);
67 SCM s = me->get_property ("grow-direction");
68 if (!is_direction (s))
74 Direction grow_dir = to_dir (s);
75 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
77 Drul_array<bool> broken;
78 Drul_array<Item *> bounds;
82 bounds[d] = me->get_bound (d);
83 broken[d] = bounds[d]->break_status_dir () != CENTER;
85 while (flip (&d) != LEFT);
87 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT);
88 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT)->is_live ();
92 Spanner *next = me->broken_neighbor (RIGHT);
93 Stencil *s = next->get_stencil ();
94 if (!s || s->is_empty ())
95 broken[RIGHT] = false;
98 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
99 Drul_array<Real> x_points;
102 Use the height and thickness of the hairpin when making a circled tip
104 bool circled_tip = ly_scm2bool (me->get_property ("circled-tip"));
105 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
106 Staff_symbol_referencer::staff_space (me);
108 FIXME: 0.525 is still just a guess...
110 Real rad = height * 0.525;
113 thick = robust_scm2double (me->get_property ("thickness"), 1.0)
114 * Staff_symbol_referencer::line_thickness (me);
119 x_points[d] = b->relative_coordinate (common, X_AXIS);
123 x_points[d] = b->extent (common, X_AXIS)[RIGHT];
127 if (Text_interface::has_interface (b))
129 Interval e = b->extent (common, X_AXIS);
131 x_points[d] = e[-d] - d * padding;
135 bool neighbor_found = false;
136 extract_grob_set (me, "adjacent-hairpins", pins);
137 for (vsize i = 0; i < pins.size (); i++)
140 FIXME: this will fuck up in case of polyphonic
141 notes in other voices. Need to look at note-columns
142 in the current staff/voice.
145 Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
147 && (pin->get_bound (LEFT)->get_column () == b->get_column ()
148 || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
149 neighbor_found = true;
152 Interval e = robust_relative_extent (b, common, X_AXIS);
156 Handle back-to-back hairpins with a circle in the middle
158 if (circled_tip && (grow_dir != d))
159 x_points[d] = e.center () + d * (rad - thick / 2.0);
161 If we're hung on a paper column, that means we're not
162 adjacent to a text-dynamic, and we may move closer. We
163 make the padding a little smaller, here.
166 x_points[d] = e.center () - d * padding / 3;
171 Item *bound = me->get_bound (d);
172 if (bound->is_non_musical (bound))
173 x_points[d] -= d * padding;
178 while (flip (&d) != LEFT);
180 Real width = x_points[RIGHT] - x_points[LEFT];
183 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
184 : "crescendo too small"));
188 bool continued = broken[Direction (-grow_dir)];
195 endh = continued ? height / 2 : 0.0;
199 starth = continued ? height / 2 : 0.0;
204 should do relative to staff-symbol staff-space?
211 Compensate for size of circle
213 Direction tip_dir = -grow_dir;
214 if (circled_tip && !broken[tip_dir])
218 else if (grow_dir < 0)
221 mol = Line_interface::line (me, Offset (x, starth), Offset (width, endh));
222 mol.add_stencil (Line_interface::line (me,
224 Offset (width, -endh)));
227 Support al/del niente notation by putting a circle at the
228 tip of the (de)crescendo.
232 Box extent (Interval (-rad, rad), Interval (-rad, rad));
234 /* Hmmm, perhaps we should have a Lookup::circle () method? */
235 Stencil circle(extent,
236 scm_list_4 (ly_symbol2scm ("circle"),
237 scm_from_double (rad),
238 scm_from_double (thick),
242 don't add another circle the hairpin is broken
244 if (!broken[tip_dir])
245 mol.add_at_edge (X_AXIS, tip_dir, Stencil (circle), 0, 0);
248 mol.translate_axis (x_points[LEFT]
249 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
251 return mol.smobbed_copy ();
254 ADD_INTERFACE (Hairpin,
255 "A hairpin crescendo/decrescendo.",