2 slur.cc -- implement Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1999, 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 * URG: share code with tie
13 * begin and end should be treated as a Script.
15 * slur from notehead to stemend: c''()b''
21 #include "paper-def.hh"
22 #include "note-column.hh"
25 #include "molecule.hh"
29 #include "encompass-info.hh"
38 Slur::add_column (Note_column*n)
40 if (!n->head_l_arr_.size ())
41 warning (_ ("Putting slur over rest."));
42 encompass_arr_.push (n);
43 n->stem_l_->slur_l_ = this;
48 Slur::set_default_dir ()
51 for (int i=0; i < encompass_arr_.size (); i ++)
53 if (encompass_arr_[i]->dir_ < 0)
62 Slur::do_add_processing ()
64 set_bounds (LEFT, encompass_arr_[0]);
65 if (encompass_arr_.size () > 1)
66 set_bounds (RIGHT, encompass_arr_.top ());
70 Slur::do_pre_processing ()
72 // don't set directions
76 Slur::do_substitute_element_pointer (Score_element*o, Score_element*n)
79 while ((i = encompass_arr_.find_i (dynamic_cast<Note_column *> (o))) >=0)
82 encompass_arr_[i] = dynamic_cast<Note_column *> (n);
84 encompass_arr_.del (i);
89 Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
91 return Item::left_right_compare (n1, n2);
95 broken_edge_b (Slur*s, Drul_array<Note_column*>& extrema, Direction dir)
97 return extrema[dir] != s->spanned_drul_[dir];
101 normal_edge_b (Slur*s, Drul_array<Note_column*>& extrema, Direction dir)
103 return !broken_edge_b (s, extrema, dir)
104 && extrema[dir]->stem_l_
105 && !extrema[dir]->stem_l_->transparent_b_
106 && extrema[dir]->head_l_arr_.size ();
110 Slur::do_post_processing ()
112 encompass_arr_.sort (Note_column_compare);
116 Real interline_f = paper ()->interline_f ();
117 Real internote_f = interline_f / 2;
119 Real notewidth_f = paper ()->note_width () * 0.8;
122 [OSU]: slur and tie placement
125 * x = centre of head (upside-down: inner raakpunt stem) - d * gap
127 * y = length < 5ss : horizontal raakpunt + d * 0.25 ss
128 y = length >= 5ss : y next interline - d * 0.25 ss
129 --> height <= 5 length ?? we use <= 3 length, now...
132 Real gap_f = paper ()->get_var ("slur_x_gap");
134 Drul_array<Note_column*> extrema;
135 extrema[LEFT] = encompass_arr_[0];
136 extrema[RIGHT] = encompass_arr_.top ();
142 if (broken_edge_b (this, extrema, d))
144 // ugh -- check if needed
146 *(spanned_drul_[d]->extent (X_AXIS).length () - 0.5 * notewidth_f);
151 dx_f_drul_[LEFT] = spanned_drul_[LEFT]->extent (X_AXIS).length ();
153 // urg -- check if needed
154 if (encompass_arr_.size () > 1)
155 dx_f_drul_[RIGHT] += notewidth_f;
161 else if (normal_edge_b (this, extrema, d))
163 Real notewidth_f = extrema[d]->extent (X_AXIS).length ();
164 dy_f_drul_[d] = (int)rint (extrema[d]->stem_l_-> extent (Y_AXIS)[dir_]);
165 dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
166 if (dir_ == extrema[d]->stem_l_->dir_)
169 dx_f_drul_[d] += 0.5 * (dir_ * d) * d * notewidth_f;
171 dx_f_drul_[d] += 0.25 * (dir_ * d) * d * notewidth_f;
176 Real notewidth_f = extrema[d]->extent (X_AXIS).length ();
177 dy_f_drul_[d] = (int)rint (extrema[d]->head_positions_interval ()
178 [dir_]) * internote_f;
179 dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
181 dy_f_drul_[d] += dir_ * interline_f;
182 if (extrema[d]->stem_l_ && (dir_ == extrema[d]->stem_l_->dir_))
183 dy_f_drul_[d] -= dir_ * internote_f;
185 while (flip(&d) != LEFT);
187 // now that both are set, do dependent
190 if (broken_edge_b (this, extrema, d))
197 dy_f_drul_[u] += dir_ * internote_f;
199 dy_f_drul_[d] = dy_f_drul_[u];
202 while (flip(&d) != LEFT);
205 Slur should follow line of music
207 if (normal_edge_b (this, extrema, LEFT)
208 && normal_edge_b (this, extrema, RIGHT)
209 && (extrema[LEFT]->stem_l_ != extrema[RIGHT]->stem_l_))
211 Real note_dy = extrema[RIGHT]->stem_l_->head_positions ()[dir_]
212 - extrema[LEFT]->stem_l_->head_positions ()[dir_];
213 Real dy = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
215 Should we always follow note-heads, (like a tie)?
216 For now, only if the note_dy != slur_dy, we'll do
217 slur_dy := note_dy * factor.
219 if (sign (dy) != sign (note_dy))
221 Real damp_f = paper ()->get_var ("slur_slope_follow_music_factor");
222 Real realdy = note_dy * damp_f;
223 Direction adjust_dir = (Direction)(- dir_ * sign (realdy));
227 adjust only if no beam gets in the way
229 if (!extrema[adjust_dir]->stem_l_->beam_l_
230 || (adjust_dir == extrema[adjust_dir]->stem_l_->dir_)
231 || (extrema[adjust_dir]->stem_l_->beams_i_drul_[-adjust_dir] < 1))
233 dy_f_drul_[adjust_dir] = dy_f_drul_[-adjust_dir]
234 + 2 * adjust_dir * realdy;
235 Real dx = notewidth_f / 2;
236 if (adjust_dir != extrema[adjust_dir]->stem_l_->dir_)
238 dx_f_drul_[adjust_dir] -= adjust_dir * dx;
244 Avoid too steep slurs.
246 Real damp_f = paper ()->get_var ("slur_slope_damping");
247 Offset d_off = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
248 dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
249 d_off[X_AXIS] += extent (X_AXIS).length ();
251 Real ratio_f = abs (d_off[Y_AXIS] / d_off[X_AXIS]);
252 if (ratio_f > damp_f)
253 dy_f_drul_[(Direction)(- dir_ * sign (d_off[Y_AXIS]))] +=
254 dir_ * (ratio_f - damp_f) * d_off[X_AXIS];
258 Slur::get_encompass_offset_arr () const
260 Real notewidth = paper ()->note_width () * 0.8;
261 Real gap = paper ()->get_var ("slur_x_gap");
262 Real internote = paper ()->internote_f ();
264 Offset left = Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]);
265 left[X_AXIS] += encompass_arr_[0]->stem_l_->hpos_f ();
269 i don't understand these two, but *must* for symmetry
270 look at encompass array:
271 lilypond -D input/test/slur-symmetry*.ly
272 lilypond -D input/test/sleur.ly
274 do_post_processing should have calculated these into
279 if (dir_ != encompass_arr_[0]->stem_l_->dir_)
280 left[X_AXIS] += - 0.5 * notewidth * encompass_arr_[0]->stem_l_->dir_
282 else if (encompass_arr_[0]->stem_l_->dir_ == UP)
283 left[X_AXIS] -= notewidth;
285 if ((dir_ == encompass_arr_[0]->stem_l_->dir_)
286 && (encompass_arr_[0]->stem_l_->dir_ == DOWN))
287 left[Y_AXIS] -= internote * encompass_arr_[0]->stem_l_->dir_;
290 Offset d = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
291 dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
292 d[X_AXIS] += extent (X_AXIS).length ();
295 int last = encompass_arr_.size () - 1;
298 if (encompass_arr_.top () != spanned_drul_[RIGHT])
302 if (encompass_arr_[0] != spanned_drul_[LEFT])
306 notes.push (Offset (0,0));
308 for (int i = first; i < last; i++)
310 Encompass_info info (encompass_arr_[i], dir_);
311 notes.push (info.o_ - left);
313 Encompass_info info (encompass_arr_.top (), dir_);
314 // [encompass_arr_.size () - 1]
317 Slur* urg = (Slur*)this;
318 urg->interstaff_f_ = info.interstaff_f_;
320 d[Y_AXIS] += interstaff_f_;
323 if (interstaff_f_ && (encompass_arr_.top () != spanned_drul_[RIGHT]))
325 Encompass_info info (encompass_arr_[encompass_arr_.size () - 1], dir_);
326 d[Y_AXIS] -= info.o_[Y_AXIS] - interstaff_f_;
336 Slur::get_rods () const
340 r.item_l_drul_ = spanned_drul_;
341 r.distance_f_ = paper ()->get_var ("slur_x_minimum");