2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 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;
34 Hairpin::consider_suicide (Spanner*me)
36 Drul_array<bool> broken;
37 Drul_array<Item *> bounds;
41 bounds[d] = me->get_bound (d);
42 broken[d] = bounds[d]->break_status_dir () != CENTER;
44 while (flip (&d) != LEFT);
47 && ly_is_equal (bounds[RIGHT]->get_column ()->get_property ("when"),
48 bounds[LEFT]->get_property ("when")))
53 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
56 Hairpin::print (SCM smob)
58 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
60 if (Spanner *orig = dynamic_cast<Spanner*> (me->original ()))
62 for (vsize i = 0; i < orig->broken_intos_.size (); i++)
63 Hairpin::consider_suicide (orig->broken_intos_[i]);
66 SCM s = me->get_property ("grow-direction");
67 if (!is_direction (s))
73 Direction grow_dir = to_dir (s);
74 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
76 Drul_array<bool> broken;
77 Drul_array<Item *> bounds;
81 bounds[d] = me->get_bound (d);
82 broken[d] = bounds[d]->break_status_dir () != CENTER;
84 while (flip (&d) != LEFT);
86 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT);
87 broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT)->is_live ();
91 Spanner *next = me->broken_neighbor (RIGHT);
92 Stencil *s = next->get_stencil ();
93 if (!s || s->is_empty ())
94 broken[RIGHT] = false;
97 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
98 Drul_array<Real> x_points;
101 Use the height and thickness of the hairpin when making a circled tip
103 bool circled_tip = ly_scm2bool (me->get_property ("circled-tip"));
104 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
105 Staff_symbol_referencer::staff_space (me);
107 FIXME: 0.525 is still just a guess...
109 Real rad = height * 0.525;
112 thick = robust_scm2double (me->get_property ("thickness"), 1.0)
113 * Staff_symbol_referencer::line_thickness (me);
118 x_points[d] = b->relative_coordinate (common, X_AXIS);
122 x_points[d] = b->extent (common, X_AXIS)[RIGHT];
126 if (Text_interface::has_interface (b))
128 Interval e = b->extent (common, X_AXIS);
130 x_points[d] = e[-d] - d * padding;
134 bool neighbor_found = false;
135 extract_grob_set (me, "adjacent-hairpins", pins);
136 for (vsize i = 0; i < pins.size (); i++)
139 FIXME: this will fuck up in case of polyphonic
140 notes in other voices. Need to look at note-columns
141 in the current staff/voice.
144 Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
146 && (pin->get_bound (LEFT)->get_column () == b->get_column ()
147 || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
148 neighbor_found = true;
151 Interval e = robust_relative_extent (b, common, X_AXIS);
155 Handle back-to-back hairpins with a circle in the middle
157 if (circled_tip && (grow_dir != d))
158 x_points[d] = e.center () + d * (rad - thick / 2.0);
160 If we're hung on a paper column, that means we're not
161 adjacent to a text-dynamic, and we may move closer. We
162 make the padding a little smaller, here.
165 x_points[d] = e.center () - d * padding / 3;
169 if (Note_column::has_interface (b)
170 && Note_column::has_rests (b))
175 Item *bound = me->get_bound (d);
176 if (bound->is_non_musical (bound))
177 x_points[d] -= d * padding;
182 while (flip (&d) != LEFT);
184 Real width = x_points[RIGHT] - x_points[LEFT];
187 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
188 : "crescendo too small"));
192 bool continued = broken[Direction (-grow_dir)];
199 endh = continued ? height / 2 : 0.0;
203 starth = continued ? height / 2 : 0.0;
208 should do relative to staff-symbol staff-space?
215 Compensate for size of circle
217 Direction tip_dir = -grow_dir;
218 if (circled_tip && !broken[tip_dir])
222 else if (grow_dir < 0)
225 mol = Line_interface::line (me, Offset (x, starth), Offset (width, endh));
226 mol.add_stencil (Line_interface::line (me,
228 Offset (width, -endh)));
231 Support al/del niente notation by putting a circle at the
232 tip of the (de)crescendo.
236 Box extent (Interval (-rad, rad), Interval (-rad, rad));
238 /* Hmmm, perhaps we should have a Lookup::circle () method? */
239 Stencil circle (extent,
240 scm_list_4 (ly_symbol2scm ("circle"),
241 scm_from_double (rad),
242 scm_from_double (thick),
246 don't add another circle the hairpin is broken
248 if (!broken[tip_dir])
249 mol.add_at_edge (X_AXIS, tip_dir, Stencil (circle), 0);
252 mol.translate_axis (x_points[LEFT]
253 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
255 return mol.smobbed_copy ();
258 ADD_INTERFACE (Hairpin,
259 "A hairpin crescendo or decrescendo.",