2 slur.cc -- implement Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998, 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"
39 Slur::add_column (Note_column*n)
41 if (!n->head_l_arr_.size ())
42 warning (_ ("Putting slur over rest."));
43 encompass_arr_.push (n);
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;
103 Real notewidth_f = paper ()->note_width ();
104 Real slur_min = paper ()->get_var ("slur_x_minimum");
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 ();
130 if (extrema[d] != spanned_drul_[d])
132 // ugh -- check if needed
134 *(spanned_drul_[d]->width ().length () - 0.5 * notewidth_f);
139 dx_f_drul_[LEFT] = spanned_drul_[LEFT]->width ().length ();
141 // urg -- check if needed
142 if (encompass_arr_.size () > 1)
143 dx_f_drul_[RIGHT] += notewidth_f;
149 else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_
150 && extrema[d]->head_l_arr_.size ())
152 Real notewidth_f = extrema[d]->width ().length ();
153 dy_f_drul_[d] = (int)rint (extrema[d]->stem_l_->height ()[dir_]);
154 dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
155 if (dir_ == extrema[d]->stem_l_->dir_)
158 dx_f_drul_[d] += 0.5 * (dir_ * d) * d * notewidth_f;
160 dx_f_drul_[d] += 0.25 * (dir_ * d) * d * notewidth_f;
165 Real notewidth_f = extrema[d]->width ().length ();
166 dy_f_drul_[d] = (int)rint (extrema[d]->head_positions_interval ()
167 [dir_]) * internote_f;
168 dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
170 dy_f_drul_[d] += dir_ * interline_f;
171 if (extrema[d]->stem_l_ && (dir_ == extrema[d]->stem_l_->dir_))
172 dy_f_drul_[d] -= dir_ * internote_f;
174 while (flip(&d) != LEFT);
176 // now that both are set, do dependent
182 if (extrema[d] != spanned_drul_[d])
189 dy_f_drul_[u] += dir_ * internote_f;
191 dy_f_drul_[d] = dy_f_drul_[(Direction)-d];
194 if (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT] < slur_min)
196 dx_f_drul_[d] -= d * slur_min
197 - (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]);
198 dx_f_drul_[d] = dx_f_drul_[(Direction)-d] + d * slur_min;
202 while (flip(&d) != LEFT);
205 Avoid too steep slurs.
206 * slur from notehead to stemend: c''()b''
208 Real damp_f = paper ()->get_var ("slur_slope_damping");
209 Offset d_off = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
210 dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
211 d_off.x () += width ().length ();
213 Real ratio_f = abs (d_off.y () / d_off.x ());
214 if (ratio_f > damp_f)
215 dy_f_drul_[(Direction)(- dir_ * sign (d_off.y ()))] -=
216 dir_ * (damp_f - ratio_f) * d_off.x ();
220 Slur::get_encompass_offset_arr () const
222 Offset left = Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]);
223 left.x () += encompass_arr_[0]->stem_l_->hpos_f ();
225 Offset d = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
226 dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
227 d.x () += width ().length ();
230 int last = encompass_arr_.size () - 1;
233 if (encompass_arr_[0] != spanned_drul_[LEFT])
237 if (encompass_arr_.top () != spanned_drul_[RIGHT])
244 notes.push (Offset (0,0));
245 // notes.push (left);
247 for (int i = first; i < last; i++)
249 Encompass_info info (encompass_arr_[i], dir_);
250 notes.push (info.o_ - left);
251 // notes.push (info.o_ - left);
257 int n = last - first + 2;
258 Array<Offset> notes (n);
259 notes[0] = Offset (0,0);
262 for (int i = first; i < last; i++)
264 Encompass_info info (encompass_arr_[i], dir_);
265 notes[i - first + 1] = info.o_ - left;
266 // notes[i - first + 1] = info.o_;
268 notes[n - 1] = Offset (d);