2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "staff-symbol-referencer.hh"
11 #include "line-interface.hh"
14 #include "font-interface.hh"
15 #include "dimensions.hh"
16 #include "output-def.hh"
18 #include "paper-column.hh"
21 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
24 Hairpin::print (SCM smob)
26 Grob *me= unsmob_grob (smob);
27 Spanner *spanner = dynamic_cast<Spanner*> (me);
29 SCM s = me->get_property ("grow-direction");
30 if (!is_direction (s))
36 Direction grow_dir = to_dir (s);
38 Real padding = ly_scm2double (me->get_property ("bound-padding"));
40 Drul_array<bool> broken;
41 Drul_array<Item*> bounds ;
45 bounds[d] = spanner->get_bound (d);
46 broken[d] = bounds[d]->break_status_dir () != CENTER;
48 while (flip (&d) != LEFT);
50 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
51 Drul_array<Real> x_points ;
56 x_points[d] = b->relative_coordinate (common, X_AXIS);
60 x_points[d] = b->extent (common,X_AXIS)[RIGHT] ;
64 if (dynamic_cast<Paper_column*> (b))
67 If we're hung on a paper column, that means we're not
68 adjacent to a text-dynamic, and we may move closer. We
69 make the padding a little smaller, here.
71 Interval e = b->extent (common, X_AXIS);
73 e = Interval (0,0) + b->relative_coordinate (common, X_AXIS);
75 x_points[d] = e.center () - d * padding / 3; // ugh.
79 Interval e = b->extent (common, X_AXIS);
81 x_points[d] = e[-d] - d*padding;
85 while (flip (&d) != LEFT);
88 Real width = x_points[RIGHT] - x_points[LEFT];
92 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
93 : "crescendo too small"));
97 bool continued = broken[Direction (-grow_dir)];
98 Real height = robust_scm2double (me->get_property ("height"), 0.2) *
99 Staff_symbol_referencer::staff_space (me);
105 endh = continued ? height/2 : 0.0;
109 starth = continued ? height/2 : 0.0;
114 should do relative to staff-symbol staff-space?
118 mol = Line_interface::line (me, Offset (0, starth), Offset (width, endh));
119 mol.add_stencil (Line_interface::line (me,
121 Offset (width, -endh)));
123 mol.translate_axis (x_points[LEFT]
124 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
126 return mol.smobbed_copy ();
131 ADD_INTERFACE (Hairpin, "hairpin-interface",
132 "A hairpin (de)crescendo.",
133 "grow-direction height bound-padding");