2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "font-interface.hh"
13 #include "dimensions.hh"
14 #include "paper-def.hh"
16 #include "paper-column.hh"
18 MAKE_SCHEME_CALLBACK (Hairpin, brew_molecule, 1);
21 Hairpin::brew_molecule (SCM smob)
23 Grob *me= unsmob_grob (smob);
24 Spanner *spanner = dynamic_cast<Spanner*> (me);
26 Real line = me->paper_l ()->get_var ("stafflinethickness");
28 SCM s = me->get_grob_property ("grow-direction");
35 Direction grow_dir = to_dir (s);
38 /* Ugh, must be same as Text_spanner::brew_molecule. */
39 Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
41 Drul_array<bool> broken;
42 Drul_array<Item*> bounds ;
46 bounds[d] =spanner->get_bound (d);
47 broken[d] = bounds[d]->break_status_dir () != CENTER;
49 while (flip (&d) != LEFT);
51 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
52 Drul_array<Real> x_points ;
57 x_points[d] = b->relative_coordinate (common, X_AXIS);
61 x_points[d] = b->extent (common,X_AXIS)[RIGHT] ;
65 if (dynamic_cast<Paper_column*> (b))
68 If we're hung on a paper column, that means we're not
69 adjacent to a text-dynamic, and we may move closer. We
70 make the padding a little smaller, here.
72 Interval e =b->extent (common, X_AXIS);
73 x_points[d] = e.center () - d * padding /3; // ugh.
77 Interval e =b->extent (common, X_AXIS);
79 x_points[d] = e[-d] - d*padding;
83 while (flip (&d) != LEFT);
86 Real width = x_points[RIGHT] - x_points[LEFT];
90 warning (_ ((grow_dir < 0) ? "decrescendo too small"
91 : "crescendo too small"));
95 bool continued = broken[Direction (-grow_dir)];
96 Real height = gh_scm2double (me->get_grob_property ("height"));
97 Real thick = line * gh_scm2double (me->get_grob_property ("thickness"));
103 endh = continued ? height/2 : 0.0;
107 starth = continued ? height/2 : 0.0;
112 TODO: junk this and, make a general
114 Lookup::line (XY1, XY2).
116 SCM hairpin = gh_list (ly_symbol2scm ("hairpin"),
117 gh_double2scm (thick),
118 gh_double2scm (width),
119 gh_double2scm (starth),
120 gh_double2scm (endh),
124 We make the hairpin too large in Y direction, so it stays at
125 proper distance from the staff.
127 Interval yext = 2* height * Interval (-1,1);
128 Box b (Interval (0, width), yext);
129 Molecule mol (b, hairpin);
131 mol.translate_axis (x_points[LEFT]
132 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
135 return mol.smobbed_copy ();