2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "staff-symbol-referencer.hh"
11 #include "line-interface.hh"
13 #include "font-interface.hh"
14 #include "dimensions.hh"
15 #include "output-def.hh"
17 #include "paper-column.hh"
19 #include "text-interface.hh"
20 #include "pointer-group-interface.hh"
22 MAKE_SCHEME_CALLBACK (Hairpin, after_line_breaking, 1);
24 Hairpin::after_line_breaking (SCM smob)
26 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
28 Drul_array<bool> broken;
29 Drul_array<Item *> bounds;
33 bounds[d] = me->get_bound (d);
34 broken[d] = bounds[d]->break_status_dir () != CENTER;
36 while (flip (&d) != LEFT);
39 && ly_is_equal (bounds[RIGHT]->get_column ()->get_property ("when"),
40 bounds[LEFT]->get_property ("when")))
42 return SCM_UNSPECIFIED;
45 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
48 Hairpin::print (SCM smob)
50 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
52 SCM s = me->get_property ("grow-direction");
53 if (!is_direction (s))
59 Direction grow_dir = to_dir (s);
60 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
62 Drul_array<bool> broken;
63 Drul_array<Item *> bounds;
67 bounds[d] = me->get_bound (d);
68 broken[d] = bounds[d]->break_status_dir () != CENTER;
70 while (flip (&d) != LEFT);
72 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
73 Drul_array<Real> x_points;
78 x_points[d] = b->relative_coordinate (common, X_AXIS);
82 x_points[d] = b->extent (common, X_AXIS)[RIGHT];
86 if (Text_interface::has_interface (b))
88 Interval e = b->extent (common, X_AXIS);
90 x_points[d] = e[-d] - d * padding;
94 bool neighbor_found = false;
95 extract_grob_set (me, "adjacent-hairpins", pins);
96 for (int i = 0; i < pins.size (); i++)
99 FIXME: this will fuck up in case of polyphonic
100 notes in other voices. Need to look at note-columns
101 in the current staff/voice.
104 Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
106 && (pin->get_bound (LEFT)->get_column () == b->get_column ()
107 || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
108 neighbor_found = true;
112 If we're hung on a paper column, that means we're not
113 adjacent to a text-dynamic, and we may move closer. We
114 make the padding a little smaller, here.
116 Interval e = robust_relative_extent (b, common, X_AXIS);
118 = neighbor_found ? e.center () - d * padding / 3 : e[d];
122 while (flip (&d) != LEFT);
124 Real width = x_points[RIGHT] - x_points[LEFT];
127 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
128 : "crescendo too small"));
132 bool continued = broken[Direction (-grow_dir)];
133 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
134 Staff_symbol_referencer::staff_space (me);
140 endh = continued ? height / 2 : 0.0;
144 starth = continued ? height / 2 : 0.0;
149 should do relative to staff-symbol staff-space?
153 mol = Line_interface::line (me, Offset (0, starth), Offset (width, endh));
154 mol.add_stencil (Line_interface::line (me,
156 Offset (width, -endh)));
158 mol.translate_axis (x_points[LEFT]
159 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
161 return mol.smobbed_copy ();
164 ADD_INTERFACE (Hairpin, "hairpin-interface",
165 "A hairpin crescendo/decrescendo.",