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_dependency (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 Slur::do_post_processing ()
97 encompass_arr_.sort (Note_column_compare);
101 Real interline_f = paper ()->interline_f ();
102 Real internote_f = interline_f / 2;
104 Real notewidth_f = paper ()->note_width () * 0.8;
107 [OSU]: slur and tie placement
110 * x = centre of head (upside-down: inner raakpunt stem) - d * gap
112 * y = length < 5ss : horizontal raakpunt + d * 0.25 ss
113 y = length >= 5ss : y next interline - d * 0.25 ss
114 --> height <= 5 length ?? we use <= 3 length, now...
117 Real gap_f = paper ()->get_var ("slur_x_gap");
119 Drul_array<Note_column*> extrema;
120 extrema[LEFT] = encompass_arr_[0];
121 extrema[RIGHT] = encompass_arr_.top ();
125 #define NORMAL_SLUR_b(dir) \
126 (extrema[dir]->stem_l_ \
127 && !extrema[dir]->stem_l_->transparent_b_ \
128 && extrema[dir]->head_l_arr_.size ())
135 if (extrema[d] != spanned_drul_[d])
137 // ugh -- check if needed
139 *(spanned_drul_[d]->extent (X_AXIS).length () - 0.5 * notewidth_f);
144 dx_f_drul_[LEFT] = spanned_drul_[LEFT]->extent (X_AXIS).length ();
146 // urg -- check if needed
147 if (encompass_arr_.size () > 1)
148 dx_f_drul_[RIGHT] += notewidth_f;
154 else if (NORMAL_SLUR_b (d))
156 Real notewidth_f = extrema[d]->extent (X_AXIS).length ();
157 dy_f_drul_[d] = (int)rint (extrema[d]->stem_l_-> extent (Y_AXIS)[dir_]);
158 dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
159 if (dir_ == extrema[d]->stem_l_->dir_)
162 dx_f_drul_[d] += 0.5 * (dir_ * d) * d * notewidth_f;
164 dx_f_drul_[d] += 0.25 * (dir_ * d) * d * notewidth_f;
169 Real notewidth_f = extrema[d]->extent (X_AXIS).length ();
170 dy_f_drul_[d] = (int)rint (extrema[d]->head_positions_interval ()
171 [dir_]) * internote_f;
172 dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
174 dy_f_drul_[d] += dir_ * interline_f;
175 if (extrema[d]->stem_l_ && (dir_ == extrema[d]->stem_l_->dir_))
176 dy_f_drul_[d] -= dir_ * internote_f;
178 while (flip(&d) != LEFT);
180 // now that both are set, do dependent
186 if (extrema[d] != spanned_drul_[d])
193 dy_f_drul_[u] += dir_ * internote_f;
195 dy_f_drul_[d] = dy_f_drul_[(Direction)-d];
198 while (flip(&d) != LEFT);
201 Slur should follow line of music
203 if (NORMAL_SLUR_b (LEFT) && NORMAL_SLUR_b (RIGHT)
204 && (extrema[LEFT]->stem_l_ != extrema[RIGHT]->stem_l_))
206 Real note_dy = extrema[RIGHT]->stem_l_->head_positions ()[dir_]
207 - extrema[LEFT]->stem_l_->head_positions ()[dir_];
208 Real dy = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
210 Should we always follow note-heads, (like a tie)?
211 For now, only if the note_dy != slur_dy, we'll do
212 slur_dy := note_dy * factor.
214 if (sign (dy) != sign (note_dy))
216 Real damp_f = paper ()->get_var ("slur_slope_follow_music_factor");
217 Real dy = note_dy * damp_f;
218 Direction adjust_dir = (Direction)(- dir_ * sign (dy));
220 adjust only if no beam gets in the way
222 if (!extrema[adjust_dir]->stem_l_->beam_l_
223 || (adjust_dir == extrema[adjust_dir]->stem_l_->dir_)
224 || (extrema[adjust_dir]->stem_l_->beams_i_drul_[-adjust_dir] < 1))
226 dy_f_drul_[adjust_dir] = dy_f_drul_[-adjust_dir]
227 + 2 * adjust_dir * dy;
228 Real dx = notewidth_f / 2;
229 if (adjust_dir != extrema[adjust_dir]->stem_l_->dir_)
231 dx_f_drul_[adjust_dir] -= adjust_dir * dx;
237 Avoid too steep slurs.
239 Real damp_f = paper ()->get_var ("slur_slope_damping");
240 Offset d_off = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
241 dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
242 d_off.x () += extent (X_AXIS).length ();
244 Real ratio_f = abs (d_off.y () / d_off.x ());
245 if (ratio_f > damp_f)
246 dy_f_drul_[(Direction)(- dir_ * sign (d_off.y ()))] +=
247 dir_ * (ratio_f - damp_f) * d_off.x ();
251 Slur::get_encompass_offset_arr () const
253 Real notewidth = paper ()->note_width () * 0.8;
254 Real gap = paper ()->get_var ("slur_x_gap");
255 Real internote = paper ()->internote_f ();
257 Offset left = Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]);
258 left.x () += encompass_arr_[0]->stem_l_->hpos_f ();
262 i don't understand these two, but *must* for symmetry
263 look at encompass array:
264 lilypond -D input/test/slur-symmetry*.ly
265 lilypond -D input/test/sleur.ly
267 do_post_processing should have calculated these into
272 if (dir_ != encompass_arr_[0]->stem_l_->dir_)
273 left.x () += - 0.5 * notewidth * encompass_arr_[0]->stem_l_->dir_
275 else if (encompass_arr_[0]->stem_l_->dir_ == UP)
276 left.x () -= notewidth;
278 if ((dir_ == encompass_arr_[0]->stem_l_->dir_)
279 && (encompass_arr_[0]->stem_l_->dir_ == DOWN))
280 left.y () -= internote * encompass_arr_[0]->stem_l_->dir_;
283 Offset d = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
284 dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
285 d.x () += extent (X_AXIS).length ();
288 int last = encompass_arr_.size () - 1;
291 if (encompass_arr_.top () != spanned_drul_[RIGHT])
295 if (encompass_arr_[0] != spanned_drul_[LEFT])
299 notes.push (Offset (0,0));
301 for (int i = first; i < last; i++)
303 Encompass_info info (encompass_arr_[i], dir_);
304 notes.push (info.o_ - left);
306 Encompass_info info (encompass_arr_[encompass_arr_.size () - 1], dir_);
309 Slur* urg = (Slur*)this;
310 urg->interstaff_f_ = info.interstaff_f_;
312 d.y () += interstaff_f_;
315 if (interstaff_f_ && (encompass_arr_.top () != spanned_drul_[RIGHT]))
317 Encompass_info info (encompass_arr_[encompass_arr_.size () - 1], dir_);
318 d.y () -= info.o_.y () - interstaff_f_;
327 Slur::do_width () const
329 Real min_f = paper ()->get_var ("slur_x_minimum");
330 Interval width_int = Bow::do_width ();
331 return width_int.length () < min_f ? Interval (0, min_f) : width_int;
335 Slur::get_rods () const
339 r.item_l_drul_ = spanned_drul_;
340 r.distance_f_ = do_width ().length ();