2 slur.cc -- implement Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 * begin and end should be treated as a/acknowledge Scripts.
13 * broken slur should have uniform trend
19 #include "paper-def.hh"
20 #include "note-column.hh"
23 #include "molecule.hh"
27 #include "encompass-info.hh"
36 Slur::add_column (Note_column*n)
38 if (!n->head_l_arr_.size ())
39 warning (_ ("Putting slur over rest. Ignoring"));
42 encompass_arr_.push (n);
48 Slur::get_default_dir () const
51 for (int i=0; i < encompass_arr_.size (); i ++)
53 if (encompass_arr_[i]->dir () < 0)
63 Slur::do_add_processing ()
65 set_bounds (LEFT, encompass_arr_[0]);
66 if (encompass_arr_.size () > 1)
67 set_bounds (RIGHT, encompass_arr_.top ());
71 Slur::do_pre_processing ()
73 // don't set directions
77 Slur::do_substitute_element_pointer (Score_element*o, Score_element*n)
80 while ((i = encompass_arr_.find_i (dynamic_cast<Note_column *> (o))) >=0)
83 encompass_arr_[i] = dynamic_cast<Note_column *> (n);
85 encompass_arr_.del (i);
90 Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
92 return Item::left_right_compare (n1, n2);
96 Slur::do_post_processing ()
98 encompass_arr_.sort (Note_column_compare);
100 dir_ = get_default_dir ();
103 Slur and tie placement [OSU]
106 * x = centre of head - d * x_gap_f
109 * y = length < 5ss : horizontal tangent + d * 0.25 ss
110 y = length >= 5ss : y next interline - d * 0.25 ss
113 Real interline_f = paper_l ()->get_realvar (interline_scm_sym);
114 Real internote_f = interline_f / 2;
116 Real x_gap_f = paper_l ()->get_var ("slur_x_gap");
117 Real y_gap_f = paper_l ()->get_var ("slur_y_gap");
119 Drul_array<Note_column*> note_column_drul;
120 note_column_drul[LEFT] = encompass_arr_[0];
121 note_column_drul[RIGHT] = encompass_arr_.top ();
123 bool fix_broken_b = false;
127 dx_f_drul_[d] = dy_f_drul_[d] = 0;
128 if ((note_column_drul[d] == spanned_drul_[d])
129 && note_column_drul[d]->head_l_arr_.size ()
130 && (note_column_drul[d]->stem_l_))
132 Stem* stem_l = note_column_drul[d]->stem_l_;
134 side directly attached to note head;
135 no beam getting in the way
137 if (((stem_l->get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
138 || !((stem_l->dir_ == dir_) && (dir_ != d)))
139 && !((dir_ == stem_l->dir_)
140 && stem_l->beam_l_ && (stem_l->beams_i_drul_[-d] >= 1)))
142 dx_f_drul_[d] = spanned_drul_[d]->extent (X_AXIS).length () / 2;
143 dx_f_drul_[d] -= d * x_gap_f;
145 if (stem_l->dir_ != dir_)
147 dy_f_drul_[d] = note_column_drul[d]->extent (Y_AXIS)[dir_];
151 dy_f_drul_[d] = stem_l->chord_start_f ()
152 + dir_ * internote_f;
154 dy_f_drul_[d] += dir_ * y_gap_f;
157 side attached to (visible) stem
161 dx_f_drul_[d] = stem_l->hpos_f ()
162 - spanned_drul_[d]->absolute_coordinate (X_AXIS);
164 side attached to beamed stem
166 if (stem_l->beam_l_ && (stem_l->beams_i_drul_[-d] >= 1))
168 dy_f_drul_[d] = stem_l->extent (Y_AXIS)[dir_];
169 dy_f_drul_[d] += dir_ * 2 * y_gap_f;
172 side attached to notehead, with stem getting in the way
176 dx_f_drul_[d] -= d * x_gap_f;
178 dy_f_drul_[d] = stem_l->chord_start_f ()
179 + dir_ * internote_f;
180 dy_f_drul_[d] += dir_ * y_gap_f;
189 dx_f_drul_[d] -= d * x_gap_f;
191 broken: should get y from other piece, so that slur
192 continues up/down trend
194 for now: be horizontal..
199 while (flip (&d) != LEFT);
204 dy_f_drul_[-d] = dy_f_drul_[d];
206 while (flip (&d) != LEFT);
210 Now we've got a fine slur
211 Catch and correct some ugly cases
214 Real dx_f = do_width ().length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT];
215 Real dy_f = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
216 Real height_f = do_height ().length ();
218 Real height_damp_f = paper_l ()->get_var ("slur_height_damping");
219 Real slope_damp_f = paper_l ()->get_var ("slur_slope_damping");
224 Avoid too steep slurs.
226 ratio_f = abs (dy_f / dx_f);
227 if (ratio_f > slope_damp_f)
229 Direction d = (Direction)(- dir_ * (sign (dy_f)));
232 dy_f_drul_[d] += dir_ * (ratio_f - slope_damp_f) * dx_f;
238 ratio_f = abs (height_f / dx_f);
239 if (ratio_f > height_damp_f)
241 Direction d = (Direction)(- dir_ * (sign (dy_f)));
244 dy_f_drul_[d] += dir_ * height_f * height_damp_f;
246 if y positions at same height, correct both ends
248 if (abs (dy_f / dx_f ) < slope_damp_f)
250 dy_f_drul_[-d] += dir_ * height_f * height_damp_f;
255 If, after correcting, we're close to stem-end...
257 Real snap_f = paper_l ()->get_var ("slur_snap_to_stem");
260 if ((note_column_drul[d] == spanned_drul_[d])
261 && (note_column_drul[d]->stem_l_)
262 && (note_column_drul[d]->stem_l_->dir_ == dir_)
263 && (abs (note_column_drul[d]->stem_l_->extent (Y_AXIS)[dir_]
264 - dy_f_drul_[d]) <= snap_f))
269 Stem* stem_l = note_column_drul[d]->stem_l_;
270 dx_f_drul_[d] = stem_l->hpos_f ()
271 - spanned_drul_[d]->absolute_coordinate (X_AXIS);
272 dy_f_drul_[d] = stem_l->extent (Y_AXIS)[dir_];
273 dy_f_drul_[d] += dir_ * 2 * y_gap_f;
276 while (flip (&d) != LEFT);
280 Slur::get_encompass_offset_arr () const
282 Array<Offset> offset_arr;
283 Offset origin (absolute_coordinate (X_AXIS), 0);
286 int last = encompass_arr_.size () - 2;
291 if (encompass_arr_[0] != spanned_drul_[LEFT])
295 Encompass_info left_info (encompass_arr_[0], dir_, this);
296 offset_arr.push (Offset (0, left_info.interstaff_f_));
301 if (encompass_arr_.top () != spanned_drul_[RIGHT])
306 for (int i = first; i <= last; i++)
308 Encompass_info info (encompass_arr_[i], dir_, this);
309 offset_arr.push (info.o_ - origin);
312 offset_arr.push (Offset (do_width ().length (), 0));
315 offset_arr[0] += Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]);
316 offset_arr.top () += Offset (dx_f_drul_[RIGHT], dy_f_drul_[RIGHT]);
319 check non-disturbed slur
320 FIXME: ends off by a tiny bit!!
322 offset_arr[0] += Offset (0, dy_f_drul_[LEFT]);
323 offset_arr.top () += Offset (0, dy_f_drul_[RIGHT]);
331 Slur::get_rods () const
335 r.item_l_drul_ = spanned_drul_;
336 r.distance_f_ = paper_l ()->get_var ("slur_x_minimum");