2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "line-interface.hh"
13 #include "font-interface.hh"
14 #include "dimensions.hh"
15 #include "paper-def.hh"
17 #include "paper-column.hh"
20 MAKE_SCHEME_CALLBACK (Hairpin, brew_molecule, 1);
23 Hairpin::brew_molecule (SCM smob)
25 Grob *me= unsmob_grob (smob);
26 Spanner *spanner = dynamic_cast<Spanner*> (me);
28 Real line = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
30 SCM s = me->get_grob_property ("grow-direction");
31 if (!is_direction (s))
37 Direction grow_dir = to_dir (s);
40 /* Ugh, must be same as Text_spanner::brew_molecule. */
43 Ugh. property name is not general.
45 Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
47 Drul_array<bool> broken;
48 Drul_array<Item*> bounds ;
52 bounds[d] =spanner->get_bound (d);
53 broken[d] = bounds[d]->break_status_dir () != CENTER;
55 while (flip (&d) != LEFT);
57 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
58 Drul_array<Real> x_points ;
63 x_points[d] = b->relative_coordinate (common, X_AXIS);
67 x_points[d] = b->extent (common,X_AXIS)[RIGHT] ;
71 if (dynamic_cast<Paper_column*> (b))
74 If we're hung on a paper column, that means we're not
75 adjacent to a text-dynamic, and we may move closer. We
76 make the padding a little smaller, here.
78 Interval e =b->extent (common, X_AXIS);
80 e = Interval (0,0) + b->relative_coordinate (common, X_AXIS);
82 x_points[d] = e.center () - d * padding /3; // ugh.
86 Interval e =b->extent (common, X_AXIS);
88 x_points[d] = e[-d] - d*padding;
92 while (flip (&d) != LEFT);
95 Real width = x_points[RIGHT] - x_points[LEFT];
99 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
100 : "crescendo too small"));
104 bool continued = broken[Direction (-grow_dir)];
105 Real height = gh_scm2double (me->get_grob_property ("height"));
106 Real thick = line * gh_scm2double (me->get_grob_property ("thickness"));
112 endh = continued ? height/2 : 0.0;
116 starth = continued ? height/2 : 0.0;
121 should do relative to staff-symbol staff-space?
125 mol = Line_interface::dashed_line (me,
128 Offset (width, endh));
129 mol.add_molecule (Line_interface::dashed_line (me,
132 Offset (width, -endh)));
134 mol.translate_axis (x_points[LEFT]
135 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
137 return mol.smobbed_copy ();
142 ADD_INTERFACE (Hairpin, "hairpin-interface",
143 "hairpin crescendo.",
144 "grow-direction height if-text-padding");