2 slur.cc -- implement Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 Jan Nieuwenhuizen <jan@digicash.com>
12 * begin and end should be treated as a Script.
14 * slur from notehead to stemend: c''()b''
20 #include "paper-def.hh"
21 #include "note-column.hh"
24 #include "molecule.hh"
29 //IMPLEMENT_IS_TYPE_B1(Slur,Spanner);
30 IMPLEMENT_IS_TYPE_B1(Slur,Bow);
37 Slur::add (Note_column*n)
39 encompass_arr_.push (n);
44 Slur::set_default_dir ()
47 for (int i=0; i < encompass_arr_.size (); i ++)
49 if (encompass_arr_[i]->dir_ < 0)
58 Slur::do_add_processing ()
60 set_bounds (LEFT, encompass_arr_[0]);
61 if (encompass_arr_.size () > 1)
62 set_bounds (RIGHT, encompass_arr_.top ());
66 Slur::do_pre_processing ()
68 // don't set directions
72 Slur::do_substitute_dependency (Score_elem*o, Score_elem*n)
75 while ((i = encompass_arr_.find_i ((Note_column*)o->item ())) >=0)
78 encompass_arr_[i] = (Note_column*)n->item ();
80 encompass_arr_.del (i);
85 Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
87 return Item::left_right_compare (n1, n2);
91 Slur::do_post_processing ()
93 encompass_arr_.sort (Note_column_compare);
96 Real interline_f = paper ()->interline_f ();
97 Real inter_f = interline_f / 2;
100 [OSU]: slur and tie placement
103 * x = centre of head (upside-down: inner raakpunt stem) - d * gap
105 * y = length < 5ss : horizontal raakpunt + d * 0.25 ss
106 y = length >= 5ss : y next interline - d * 0.25 ss
107 --> height <= 5 length ?? we use <= 3 length, now...
109 * suggested gap = ss / 5;
111 // jcn: 1/5 seems so small?
112 Real gap_f = interline_f / 2; // 5;
114 Drul_array<Note_column*> extrema;
115 extrema[LEFT] = encompass_arr_[0];
116 extrema[RIGHT] = encompass_arr_.top ();
119 Real nw_f = paper ()->note_width ();
123 if (extrema[d] != spanned_drul_[d])
126 *(spanned_drul_[d]->width ().length () -0.5*nw_f);
129 if ((extrema[u] == spanned_drul_[u]) && extrema[u]->stem_l_)
131 dy_f_drul_[d] = extrema[u]->stem_l_->height ()[dir_];
132 dy_f_drul_[u] = extrema[u]->stem_l_->height ()[dir_];
135 else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_)
137 dy_f_drul_[d] = (int)rint (extrema[d]->stem_l_->height ()[dir_]);
138 dx_f_drul_[d] += 0.5 * nw_f - d * gap_f;
139 if (dir_ == extrema[d]->stem_l_->dir_)
142 dx_f_drul_[d] += 0.5 * (dir_ * d) * d * nw_f;
144 dx_f_drul_[d] += 0.25 * (dir_ * d) * d * nw_f;
149 dy_f_drul_[d] = (int)rint (extrema[d]->head_positions_interval ()
152 dy_f_drul_[d] += dir_ * interline_f;
154 while (flip(&d) != LEFT);
158 Slur::get_encompass_offset_arr () const
160 Real interline = paper ()->interline_f ();
161 Real notewidth = paper ()->note_width ();
162 Real internote = interline / 2;
164 Stem* left_stem = encompass_arr_[0]->stem_l_;
165 Real left_x = left_stem->hpos_f ();
166 left_x += dx_f_drul_[LEFT];
168 Real left_y = dy_f_drul_[LEFT];
170 Real dx = width ().length ();
171 dx += (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]);
173 dx = dx >? 2 * interline;
175 Real dy = (dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
177 dy = sign (dy) * 1000;
180 int last = encompass_arr_.size () - 1;
181 if (encompass_arr_[0] != spanned_drul_[LEFT])
184 left_x = spanned_drul_[LEFT]->width ().length ();
185 left_x -= 2 * notewidth;
187 Stem* stem = encompass_arr_[last]->stem_l_;
188 left_y = stem->dir_ == dir_ ? stem->stem_end_f ()
189 : stem->stem_begin_f () + 0.5 * dir_;
192 if (encompass_arr_.top () != spanned_drul_[RIGHT])
199 notes.push (Offset (0,0));
200 for (int i = first; i < last; i++)
202 Stem* stem = encompass_arr_[i]->stem_l_;
204 set x to middle of notehead or on exact x position of stem,
205 according to slur direction
207 Real x = stem->hpos_f ();
209 if (stem->dir_ != dir_)
210 x += 0.5 * notewidth;
211 else if (stem->dir_ == UP)
212 x += 1.0 * notewidth;
216 Real y = stem->dir_ == dir_ ? stem->stem_end_f ()
217 : stem->stem_begin_f () + 0.5 * dir_;
220 leave a gap: slur mustn't touch head/stem
231 notes.push (Offset (x, y));
234 notes.push (Offset (dx, dy));