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));
30 Drul_array<bool> broken;
31 Drul_array<Item *> bounds;
35 bounds[d] = me->get_bound (d);
36 broken[d] = bounds[d]->break_status_dir () != CENTER;
38 while (flip (&d) != LEFT);
41 && ly_is_equal (bounds[RIGHT]->get_column ()->get_property ("when"),
42 bounds[LEFT]->get_property ("when")))
44 return SCM_UNSPECIFIED;
47 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
50 Hairpin::print (SCM smob)
52 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
54 SCM s = me->get_property ("grow-direction");
55 if (!is_direction (s))
61 Direction grow_dir = to_dir (s);
62 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
64 Drul_array<bool> broken;
65 Drul_array<Item *> bounds;
69 bounds[d] = me->get_bound (d);
70 broken[d] = bounds[d]->break_status_dir () != CENTER;
72 while (flip (&d) != LEFT);
74 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
75 Drul_array<Real> x_points;
80 x_points[d] = b->relative_coordinate (common, X_AXIS);
84 x_points[d] = b->extent (common, X_AXIS)[RIGHT];
88 if (Text_interface::has_interface (b))
90 Interval e = b->extent (common, X_AXIS);
92 x_points[d] = e[-d] - d * padding;
96 bool neighbor_found = false;
97 extract_grob_set (me, "adjacent-hairpins", pins);
98 for (int i = 0; i < pins.size (); i++)
101 FIXME: this will fuck up in case of polyphonic
102 notes in other voices. Need to look at note-columns
103 in the current staff/voice.
106 Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
108 && (pin->get_bound (LEFT)->get_column () == b->get_column ()
109 || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
110 neighbor_found = true;
114 If we're hung on a paper column, that means we're not
115 adjacent to a text-dynamic, and we may move closer. We
116 make the padding a little smaller, here.
118 Interval e = robust_relative_extent (b, common, X_AXIS);
120 = neighbor_found ? e.center () - d * padding / 3 : e[d];
124 while (flip (&d) != LEFT);
126 Real width = x_points[RIGHT] - x_points[LEFT];
129 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
130 : "crescendo too small"));
134 bool continued = broken[Direction (-grow_dir)];
135 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
136 Staff_symbol_referencer::staff_space (me);
142 endh = continued ? height / 2 : 0.0;
146 starth = continued ? height / 2 : 0.0;
151 should do relative to staff-symbol staff-space?
155 mol = Line_interface::line (me, Offset (0, starth), Offset (width, endh));
156 mol.add_stencil (Line_interface::line (me,
158 Offset (width, -endh)));
160 mol.translate_axis (x_points[LEFT]
161 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
163 return mol.smobbed_copy ();
166 ADD_INTERFACE (Hairpin, "hairpin-interface",
167 "A hairpin crescendo/decrescendo.",