*** empty log message ***
[lilypond.git] / lily / hairpin.cc
blobba4427a6eec58666c33dc81e7d49a7485a9cd3ec
1 /*
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>
7 */
9 #include "molecule.hh"
10 #include "hairpin.hh"
11 #include "spanner.hh"
12 #include "font-interface.hh"
13 #include "dimensions.hh"
14 #include "paper-def.hh"
15 #include "warn.hh"
16 #include "paper-column.hh"
17 #include "lookup.hh"
19 MAKE_SCHEME_CALLBACK (Hairpin, brew_molecule, 1);
21 SCM
22 Hairpin::brew_molecule (SCM smob)
24 Grob *me= unsmob_grob (smob);
25 Spanner *spanner = dynamic_cast<Spanner*> (me);
27 Real line = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
29 SCM s = me->get_grob_property ("grow-direction");
30 if (!ly_dir_p (s))
32 me->suicide ();
33 return SCM_EOL;
36 Direction grow_dir = to_dir (s);
39 /* Ugh, must be same as Text_spanner::brew_molecule. */
42 Ugh. property name is not general.
44 Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
46 Drul_array<bool> broken;
47 Drul_array<Item*> bounds ;
48 Direction d = LEFT;
51 bounds[d] =spanner->get_bound (d);
52 broken[d] = bounds[d]->break_status_dir () != CENTER;
54 while (flip (&d) != LEFT);
56 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
57 Drul_array<Real> x_points ;
61 Item *b = bounds[d];
62 x_points[d] = b->relative_coordinate (common, X_AXIS);
63 if (broken [d])
65 if (d == LEFT)
66 x_points[d] = b->extent (common,X_AXIS)[RIGHT] ;
68 else
70 if (dynamic_cast<Paper_column*> (b))
73 If we're hung on a paper column, that means we're not
74 adjacent to a text-dynamic, and we may move closer. We
75 make the padding a little smaller, here.
77 Interval e =b->extent (common, X_AXIS);
78 if (e.empty_b ())
79 e = Interval (0,0) + b->relative_coordinate (common, X_AXIS);
81 x_points[d] = e.center () - d * padding /3; // ugh.
83 else
85 Interval e =b->extent (common, X_AXIS);
86 if (!e.empty_b ())
87 x_points[d] = e[-d] - d*padding;
91 while (flip (&d) != LEFT);
94 Real width = x_points[RIGHT] - x_points[LEFT];
96 if (width < 0)
98 me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
99 : "crescendo too small"));
100 width = 0;
103 bool continued = broken[Direction (-grow_dir)];
104 Real height = gh_scm2double (me->get_grob_property ("height"));
105 Real thick = line * gh_scm2double (me->get_grob_property ("thickness"));
107 Real starth, endh;
108 if (grow_dir < 0)
110 starth = height;
111 endh = continued ? height/2 : 0.0;
113 else
115 starth = continued ? height/2 : 0.0;
116 endh = height;
120 should do relative to staff-symbol staff-space?
123 Real period = 1.0;
124 s = me->get_grob_property ("dash-period");
125 if (gh_number_p (s))
126 period = gh_scm2double (s);
128 Real fraction = 1.0;
129 s = me->get_grob_property ("dash-fraction");
130 if (gh_number_p (s))
131 fraction = gh_scm2double (s);
134 TODO: set line style.
136 Molecule mol;
137 if (fraction < 1.0)
139 mol = Lookup::dashed_line (thick,
140 Offset (0, starth),
141 Offset (width, endh),
142 period, fraction);
143 mol.add_molecule (Lookup::dashed_line (thick,
144 Offset (0, -starth),
145 Offset (width, -endh),
146 period, fraction));
148 else
150 mol = Lookup::line (thick,
151 Offset (0, starth),
152 Offset (width, endh));
153 mol.add_molecule (Lookup::line (thick,
154 Offset (0, -starth),
155 Offset (width, -endh)
158 mol.translate_axis (x_points[LEFT]
159 - bounds[LEFT]->relative_coordinate (common, X_AXIS),
160 X_AXIS);
161 return mol.smobbed_copy ();
166 ADD_INTERFACE (Hairpin, "hairpin-interface",
167 "hairpin crescendo.",
168 "dash-period dash-fraction grow-direction thickness height if-text-padding");