]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur-scoring.cc
* lily/slur.cc: add 'positions to interface
[lilypond.git] / lily / slur-scoring.cc
1 /*
2   slur-scoring.cc -- Score based slur formatting
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include <math.h>
11
12 #include "libc-extension.hh"
13 #include "slur-configuration.hh"
14 #include "slur-scoring.hh"
15 #include "beam.hh"
16 #include "directional-element-interface.hh"
17 #include "group-interface.hh"
18 #include "lily-guile.hh"
19 #include "slur.hh"
20 #include "note-column.hh"
21 #include "output-def.hh"
22 #include "pitch.hh"
23 #include "bezier.hh"
24 #include "spanner.hh"
25 #include "staff-symbol-referencer.hh"
26 #include "staff-symbol.hh"
27 #include "stem.hh"
28 #include "warn.hh"
29 #include "paper-column.hh"
30 #include "accidental-interface.hh"
31
32 /*
33   TODO:
34
35   - curve around flag for y coordinate
36
37   - this file is a mess, clean it up
38
39   - short-cut: try a smaller region first.
40
41   - handle non-visible stems better.
42
43   - try to prune number of scoring criteria
44
45   - take encompass-objects more into account when determining
46   slur shape
47
48   - calculate encompass scoring directly after determining slur shape.
49
50   - optimize.
51
52 */
53 struct Slur_score_state;
54
55 Slur_score_state::Slur_score_state()
56 {
57   musical_dy_ = 0.0;
58   valid_ = false;
59   edge_has_beams_ = false;
60   has_same_beam_ = false;
61   is_broken_ = false;
62   dir_ = CENTER;
63   slur_ = 0;
64   common_[X_AXIS] = 0;
65   common_[Y_AXIS] = 0;
66 }
67
68 Slur_score_state::~Slur_score_state ()
69 {
70   junk_pointers (configurations_);
71 }
72
73 Real
74 get_detail (SCM alist, SCM sym)
75 {
76   SCM entry = scm_assq (sym, alist);
77   return robust_scm2double (scm_is_pair (entry)
78                             ? scm_cdr (entry)
79                             : SCM_EOL,
80                             0.0);
81 }
82
83 void
84 Slur_score_parameters::fill (Grob *me)
85 {
86   SCM details = me->get_property ("slur-details");
87
88   region_size_
89     = (int) get_detail (details, ly_symbol2scm ("region-size"));
90   head_encompass_penalty_
91     = get_detail (details, ly_symbol2scm ("head-encompass-penalty"));
92   stem_encompass_penalty_
93     = get_detail (details, ly_symbol2scm ("stem-encompass-penalty"));
94   closeness_factor_
95     = get_detail (details, ly_symbol2scm ("closeness-factor"));
96   edge_attraction_factor_
97     = get_detail (details, ly_symbol2scm ("edge-attraction-factor"));
98   same_slope_penalty_
99     = get_detail (details, ly_symbol2scm ("same-slope-penalty"));
100   steeper_slope_factor_
101     = get_detail (details, ly_symbol2scm ("steeper-slope-factor"));
102   non_horizontal_penalty_
103     = get_detail (details, ly_symbol2scm ("non-horizontal-penalty"));
104   max_slope_
105     = get_detail (details, ly_symbol2scm ("max-slope"));
106   max_slope_factor_
107     = get_detail (details, ly_symbol2scm ("max-slope-factor"));
108   free_head_distance_
109     = get_detail (details, ly_symbol2scm ("free-head-distance"));
110   absolute_closeness_measure_
111     = get_detail (details, ly_symbol2scm ("absolute-closeness-measure"));
112   extra_object_collision_
113     = get_detail (details, ly_symbol2scm ("extra-object-collision"));
114   accidental_collision_
115     = get_detail (details, ly_symbol2scm ("accidental-collision"));
116   extra_encompass_free_distance_
117     = get_detail (details, ly_symbol2scm ("extra-encompass-free-distance"));
118   head_slur_distance_factor_
119     = get_detail (details, ly_symbol2scm ("head-slur-distance-factor"));
120   head_slur_distance_max_ratio_
121     = get_detail (details, ly_symbol2scm ("head-slur-distance-max-ratio"));
122   free_slur_distance_
123     = get_detail (details, ly_symbol2scm ("free-slur-distance"));
124   edge_slope_exponent_
125     = get_detail (details, ly_symbol2scm ("edge-slope-exponent"));
126 }
127
128 Real
129 broken_trend_y (Slur_score_state const &state, Direction hdir)
130 {
131   /* A broken slur should maintain the same vertical trend
132      the unbroken slur would have had.  */
133   Real by = 0.0;
134   if (Spanner *mother = dynamic_cast<Spanner*> (state.slur_->original_))
135     {
136       int k = broken_spanner_index (state.slur_);
137       int j = k + hdir;
138       if (j < 0 || j >= mother->broken_intos_.size ())
139         return by;
140
141       Grob *neighbor = mother->broken_intos_[j];
142       Spanner *common_mother
143         = dynamic_cast<Spanner*> (state.common_[Y_AXIS]->original_);
144       int common_k
145         = broken_spanner_index (dynamic_cast<Spanner*> (state.common_[Y_AXIS]));
146       int common_j = common_k + hdir;
147
148       if (common_j < 0 || common_j >= common_mother->broken_intos_.size ())
149         return by;
150
151       Grob *common_next_system = common_mother->broken_intos_[common_j];
152       
153       SCM last_point =  scm_car (scm_last_pair (neighbor->get_property ("control-points")));
154       
155       return scm_to_double (scm_cdr (last_point))
156         + neighbor->relative_coordinate (common_next_system, Y_AXIS);
157     }
158   return by;
159 }
160
161
162 /*
163   copy slur dir forwards across line break.
164 */
165 void
166 Slur_score_state::set_next_direction () 
167 {
168   if (extremes_[RIGHT].note_column_)
169     return;
170   
171   if (Spanner *mother = dynamic_cast<Spanner*> (slur_->original_))
172     {
173       int k = broken_spanner_index (slur_);
174       int j = k + 1;
175       if (j < 0 || j >= mother->broken_intos_.size ())
176         return;
177
178       Grob *neighbor = mother->broken_intos_[j];
179       set_grob_direction (neighbor, dir_);
180     }
181 }
182
183 Encompass_info
184 Slur_score_state::get_encompass_info (Grob *col) const
185 {
186   Grob *stem = unsmob_grob (col->get_property ("stem"));
187   Encompass_info ei;
188
189   if (!stem)
190     {
191       programming_error ("No stem for note column?");
192       ei.x_ = col->relative_coordinate (common_[X_AXIS], X_AXIS);
193       ei.head_ = ei.stem_ = col->extent (common_[Y_AXIS],
194                                          Y_AXIS)[dir_];
195       return ei;
196     }
197   Direction stem_dir = get_grob_direction (stem);
198
199   if (Grob *head = Note_column::first_head (col))
200     ei.x_ = head->extent (common_[X_AXIS], X_AXIS).center ();
201   else
202     ei.x_ = col->extent (common_[X_AXIS], X_AXIS).center ();
203
204   Grob *h = Stem::extremal_heads (stem)[Direction (dir_)];
205   if (!h)
206     {
207       ei.head_ = ei.stem_ = col->extent (common_[Y_AXIS], Y_AXIS)[dir_];
208       return ei;
209     }
210
211   ei.head_ = h->extent (common_[Y_AXIS], Y_AXIS)[dir_];
212
213   if ((stem_dir == dir_)
214       && !stem->extent (stem, Y_AXIS).is_empty ())
215     {
216       ei.stem_ = stem->extent (common_[Y_AXIS], Y_AXIS)[dir_];
217       if (Grob *b = Stem::get_beam (stem))
218         ei.stem_ += stem_dir * 0.5 * Beam::get_thickness (b);
219
220       Interval x = stem->extent (common_[X_AXIS], X_AXIS);
221       ei.x_ = x.is_empty ()
222         ? stem->relative_coordinate (common_[X_AXIS], X_AXIS)
223         : x.center ();
224     }
225   else
226     ei.stem_ = ei.head_;
227
228   return ei;
229 }
230
231
232
233
234 Drul_array<Bound_info>
235 Slur_score_state::get_bound_info () const
236 {
237   Drul_array<Bound_info> extremes;
238
239   Direction d = LEFT;
240   Direction dir = dir_;
241
242   do
243     {
244       extremes[d].bound_ = slur_->get_bound (d);
245       if (Note_column::has_interface (extremes[d].bound_))
246         {
247           extremes[d].note_column_ = extremes[d].bound_;
248           extremes[d].stem_ = Note_column::get_stem (extremes[d].note_column_);
249           extremes[d].stem_dir_ = get_grob_direction (extremes[d].stem_);
250           extremes[d].stem_extent_[X_AXIS]
251             = extremes[d].stem_->extent (common_[X_AXIS], X_AXIS);
252           extremes[d].stem_extent_[Y_AXIS]
253             = extremes[d].stem_->extent (common_[Y_AXIS], Y_AXIS);
254           extremes[d].slur_head_
255             = Stem::extremal_heads (extremes[d].stem_)[dir];
256           if (!extremes[d].slur_head_
257               && Note_column::has_rests (extremes[d].bound_))
258             {
259               extremes[d].slur_head_ = Note_column::get_rest (extremes[d].bound_);
260             }
261
262           if (extremes[d].slur_head_)
263             extremes[d].slur_head_extent_
264               = extremes[d].slur_head_->extent (common_[X_AXIS], X_AXIS);
265
266           extremes[d].staff_ = Staff_symbol_referencer
267             ::get_staff_symbol (extremes[d].stem_);
268           extremes[d].staff_space_ = Staff_symbol_referencer
269             ::staff_space (extremes[d].stem_);
270         }
271     }
272   while (flip (&d) != LEFT);
273   return extremes;
274 }
275
276 void
277 Slur_score_state::fill (Grob *me)
278 {
279   slur_ = dynamic_cast<Spanner*> (me);
280   columns_ 
281     = Pointer_group_interface__extract_grobs (me, (Grob *) 0, "note-columns");
282   
283   if (columns_.is_empty ())
284     {
285       me->suicide ();
286       return ;
287     }
288
289   staff_space_ = Staff_symbol_referencer::staff_space (me);
290   Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
291   thickness_ = robust_scm2double (me->get_property ("thickness"), 1.0) *  lt;
292   
293   dir_ = get_grob_direction (me);
294   parameters_.fill (me);
295   
296   SCM eltlist = me->get_property ("note-columns");
297   SCM extra_list = me->get_property ("encompass-objects");
298   Spanner *sp = dynamic_cast<Spanner*> (me);
299
300   for (int i = X_AXIS; i < NO_AXES; i++)
301     {
302       Axis a = (Axis)i;
303       common_[a] = common_refpoint_of_list (eltlist, me, a);
304       common_[a] = common_refpoint_of_list (extra_list, common_[a], a);
305
306       Direction d = LEFT;
307       do {
308         /*
309           If bound is not in note-columns, we don't want to know about
310           its Y-position
311          */
312         if (a != Y_AXIS) 
313           common_[a] = common_[a]->common_refpoint (sp->get_bound (d), a);
314       }
315       while (flip (&d) != LEFT);
316     }
317
318   extremes_ = get_bound_info ();
319   is_broken_ = (!extremes_[LEFT].note_column_
320                 || !extremes_[RIGHT].note_column_); 
321
322   has_same_beam_ =
323     (extremes_[LEFT].stem_ && extremes_[RIGHT].stem_
324      && Stem::get_beam (extremes_[LEFT].stem_) == Stem::get_beam (extremes_[RIGHT].stem_));
325   
326   base_attachments_ = get_base_attachments ();
327
328   Drul_array<Real> end_ys
329     = get_y_attachment_range ();
330
331   configurations_ = enumerate_attachments ( end_ys);
332   for (int i = 0; i < columns_.size (); i++)
333     encompass_infos_.push (get_encompass_info ( columns_[i]));
334
335   extra_encompass_infos_ = get_extra_encompass_infos ();
336   valid_ = true;
337
338
339   musical_dy_ = 0.0;
340   Direction d = LEFT;
341   do
342     {
343       if (!is_broken_)
344         musical_dy_ += d
345           * extremes_[d].slur_head_->relative_coordinate (common_[Y_AXIS], Y_AXIS);
346     }
347   while (flip (&d) != LEFT);
348   
349   edge_has_beams_
350     = (extremes_[LEFT].stem_ && Stem::get_beam (extremes_[LEFT].stem_))
351     || (extremes_[RIGHT].stem_ && Stem::get_beam (extremes_[RIGHT].stem_));
352
353
354   
355   set_next_direction ();
356
357   if (is_broken_)
358     musical_dy_ = 0.0;
359 }
360
361 void
362 set_slur_control_points (Grob *me)
363 {
364   Slur_score_state state;
365   state.fill (me);
366
367   if (!state.valid_)
368     return;
369   
370   state.generate_curves ();
371
372   SCM end_ys = me->get_property ("positions");
373   Bezier best;
374
375   if (is_number_pair (end_ys))
376     {
377       best = state.configurations_[state.get_closest_index (end_ys)]->curve_;
378     }
379   else
380     {
381       best = state.get_best_curve();
382     }
383
384   SCM controls = SCM_EOL;
385   for (int i = 4; i--;)
386     {
387       Offset o = best.control_[i]
388         - Offset (me->relative_coordinate (state.common_[X_AXIS], X_AXIS),
389                   me->relative_coordinate (state.common_[Y_AXIS], Y_AXIS));
390       controls = scm_cons (ly_offset2scm (o), controls);
391     }
392   me->set_property ("control-points", controls);
393 }
394
395
396 Bezier
397 Slur_score_state::get_best_curve ()
398 {
399   for (int i = 0; i < configurations_.size (); i++)
400     {
401       configurations_[i]->score (*this);
402     }
403   
404   Real opt = 1e6;
405   int opt_idx = -1;
406   for (int i = 0; i < configurations_.size (); i++)
407     {
408       if (configurations_[i]->score_ < opt)
409         {
410           opt = configurations_[i]->score_;
411           opt_idx = i;
412         }
413     }
414
415 #if DEBUG_SLUR_SCORING
416   SCM inspect_quants = slur_->get_property ("inspect-quants");
417   if (to_boolean (slur_->get_layout ()
418                   ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
419       && scm_is_pair (inspect_quants))
420     opt_idx = get_closest_index (inspect_quants);
421
422   configurations_[opt_idx]->score_card_ += to_string ("=%.2f", opt);  
423   configurations_[opt_idx]->score_card_ += to_string ("i%d", opt_idx);
424
425   // debug quanting
426   slur_->set_property ("quant-score",
427                        scm_makfrom0str (configurations_[opt_idx]->score_card_.to_str0 ()));
428
429 #endif
430
431   return configurations_[opt_idx]->curve_;
432 }
433
434 int
435 Slur_score_state::get_closest_index (SCM inspect_quants) const
436 {
437   Drul_array<Real> ins = ly_scm2interval (inspect_quants);
438
439   int opt_idx = -1;
440   Real mindist = 1e6;
441   for (int i = 0; i < configurations_.size (); i ++)
442     {
443       Real d =fabs (configurations_[i]->attachment_[LEFT][Y_AXIS] - ins[LEFT])
444         + fabs (configurations_[i]->attachment_[RIGHT][Y_AXIS] - ins[RIGHT]);
445       if (d < mindist)
446         {
447           opt_idx = i;
448           mindist= d;
449         }
450     }
451   if (mindist > 1e5)
452     programming_error ("Could not find quant.");
453   return opt_idx;
454 }
455
456 /*
457   TODO: should analyse encompasses to determine sensible region, and
458   should limit slopes available.
459  */
460
461 Drul_array<Real>
462 Slur_score_state::get_y_attachment_range () const
463 {
464   Drul_array<Real> end_ys;
465   Direction d = LEFT;
466   do
467     {
468       if (extremes_[d].note_column_)
469         {
470           end_ys[d] = dir_
471             * ((dir_ * (base_attachments_[d][Y_AXIS] +  parameters_.region_size_* dir_))
472                >? (dir_ * (dir_ + extremes_[d].note_column_->extent (common_[Y_AXIS],
473                                                                  Y_AXIS)[dir_]))
474                >? (dir_ * base_attachments_[-d][Y_AXIS]));
475         }
476       else
477         end_ys[d] = base_attachments_[d][Y_AXIS] + parameters_.region_size_ * dir_;
478     }
479   while (flip (&d) != LEFT);
480
481   return end_ys;
482 }
483
484 bool
485 spanner_less (Spanner *s1, Spanner* s2)
486 {
487   Slice b1, b2;
488   Direction d  = LEFT;
489   do
490     {
491       b1[d] = s1->get_bound (d)->get_column ()->rank_;
492       b2[d] = s2->get_bound (d)->get_column ()->rank_;
493     } while (flip (&d) != LEFT);
494
495   return b2[LEFT] <= b1[LEFT] && b2[RIGHT] >= b1[RIGHT]
496     && (b2[LEFT] != b1[LEFT] || b2[RIGHT] != b1[RIGHT]);
497 }
498
499
500 Drul_array<Offset>
501 Slur_score_state::get_base_attachments () const
502 {
503   Drul_array<Offset> base_attachment;
504   Direction d = LEFT;
505   do
506     {
507       Grob *stem = extremes_[d].stem_;
508       Grob *head = extremes_[d].slur_head_;
509
510       Real x = 0.0;
511       Real y = 0.0;
512       if (extremes_[d].note_column_)
513         {
514          
515           /*
516             fixme: X coord should also be set in this case.
517            */
518           if (stem
519               && extremes_[d].stem_dir_ == dir_
520               && Stem::get_beaming (stem, -d)
521               && (!spanner_less (slur_, Stem::get_beam (stem))
522                   || has_same_beam_))
523             y = extremes_[d].stem_extent_[Y_AXIS][dir_];
524           else if (head)
525             y = head->extent (common_[Y_AXIS], Y_AXIS)[dir_];
526           y += dir_ * 0.5 * staff_space_;
527
528
529           y = move_away_from_staffline (y, head); 
530
531           Grob * fh = Note_column::first_head (extremes_[d].note_column_);
532           x =
533          (fh ? fh->extent (common_[X_AXIS], X_AXIS)
534              : extremes_[d].bound_->extent (common_[X_AXIS], X_AXIS))
535             .linear_combination (CENTER);
536         }
537       base_attachment[d] = Offset (x, y);
538
539     } while (flip (&d) != LEFT);
540
541   do
542     {
543       if (!extremes_[d].note_column_)
544         {
545           Real x, y;
546           if (d == RIGHT)
547             {
548               x = extremes_[d].bound_->extent (common_[X_AXIS], X_AXIS)[d];
549             }
550           else
551             {
552               x = slur_->get_broken_left_end_align ();
553             }
554           Grob * col = (d == LEFT) ? columns_[0] : columns_.top();
555               
556           if (extremes_[-d].bound_ != col)
557             {
558               y = robust_relative_extent (col, common_[Y_AXIS], Y_AXIS)[dir_];
559               y += dir_ * 0.5 * staff_space_;
560               
561               if (get_grob_direction (col) == dir_
562                   && Note_column::get_stem (col)
563                   && !Stem::is_invisible (Note_column::get_stem (col)))
564                 y -= dir_ * 1.5 * staff_space_;
565             }
566           else
567             y = base_attachment[-d][Y_AXIS];
568
569           
570           y = move_away_from_staffline (y, col);
571             
572           base_attachment[d] = Offset (x, y);  
573         }
574     }
575   while (flip (&d) != LEFT);
576
577   return base_attachment;
578 }
579
580 Real
581 Slur_score_state::move_away_from_staffline (Real y,
582                                             Grob *on_staff) const
583 {
584   Real pos
585     = (y - Staff_symbol_referencer::get_staff_symbol (on_staff)->relative_coordinate (common_[Y_AXIS],
586                                                                                Y_AXIS))
587     * 2.0 / staff_space_;
588   
589   if (fabs (pos - my_round (pos)) < 0.2
590       && Staff_symbol_referencer::on_staffline (on_staff, (int) rint (pos))
591       && Staff_symbol_referencer::line_count (on_staff) - 1 >= rint (pos)
592       )
593     y += 1.5 * staff_space_ * dir_ / 10;
594
595   return y;
596 }
597
598 void
599 Slur_score_state::generate_curves () const
600 {
601   Real r_0 = robust_scm2double (slur_->get_property ("ratio"), 0.33);
602   Real h_inf = staff_space_ *scm_to_double (slur_->get_property ("height-limit"));
603   for (int i = 0; i < configurations_.size (); i++)
604     configurations_[i]->generate_curve (*this, r_0, h_inf);
605 }
606
607
608
609
610 Link_array<Slur_configuration> 
611 Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
612 {
613   /*ugh.   */
614   Link_array<Slur_configuration> scores;
615
616
617   Drul_array<Offset> os;
618   os[LEFT] = base_attachments_[LEFT];
619   Real minimum_length = staff_space_
620     * robust_scm2double (slur_->get_property ("minimum-length"), 2.0);
621
622   for (int i = 0; dir_ * os[LEFT][Y_AXIS] <= dir_ * end_ys[LEFT]; i++)
623     {
624       os[RIGHT] = base_attachments_[RIGHT];
625       for (int j = 0; dir_ * os[RIGHT][Y_AXIS] <= dir_ * end_ys[RIGHT]; j++)
626         {
627           Slur_configuration s;
628           Direction d = LEFT;
629           Drul_array<bool> attach_to_stem (false, false);
630           do
631             {
632               os[d][X_AXIS] = base_attachments_[d][X_AXIS];
633               if (extremes_[d].stem_
634                   && !Stem::is_invisible (extremes_[d].stem_)
635                   && extremes_[d].stem_dir_ == dir_)
636                 {
637                   Interval stem_y = extremes_[d].stem_extent_[Y_AXIS];
638                   stem_y.widen (0.25 * staff_space_);
639                   if (stem_y.contains (os[d][Y_AXIS]))
640                     {
641                       os[d][X_AXIS] = extremes_[d].stem_extent_[X_AXIS][-d]
642                         - d * 0.3;
643                       attach_to_stem[d] = true;
644                     }
645                   else if (dir_ * extremes_[d].stem_extent_[Y_AXIS][dir_]
646                            < dir_ * os[d][Y_AXIS]
647                            && !extremes_[d].stem_extent_[X_AXIS].is_empty ()
648                            )
649                 
650                     os[d][X_AXIS] = extremes_[d].stem_extent_[X_AXIS].center ();
651                 }
652             }
653           while (flip (&d) != LEFT);
654
655           Offset dz;    
656           dz = os[RIGHT] - os[LEFT];
657           if (dz[X_AXIS] < minimum_length
658               || fabs (dz[Y_AXIS] / dz[X_AXIS]) > parameters_.max_slope_
659               )
660             {
661               do
662                 {
663                   if (extremes_[d].slur_head_)
664                     {
665                       os[d][X_AXIS] = extremes_[d].slur_head_extent_.center ();
666                       attach_to_stem[d] = false;
667                     }
668                 }
669               while (flip (&d) != LEFT);
670             }
671
672           dz = os[RIGHT] - os[LEFT];
673           do
674             {
675               if (extremes_[d].slur_head_
676                   && !attach_to_stem[d])
677                 {
678                   /* Horizontally move tilted slurs a little.  Move
679                      more for bigger tilts.
680                 
681                      TODO: parameter */
682                   os[d][X_AXIS]
683                     -= dir_ * extremes_[d].slur_head_extent_.length ()
684                     * sin (dz.arg ()) / 3;
685                 }
686             }
687           while (flip (&d) != LEFT);
688         
689           s.attachment_ = os;
690           s.index_ = scores.size ();
691
692           scores.push (new Slur_configuration (s));
693           
694           os[RIGHT][Y_AXIS] += dir_ * staff_space_ / 2;
695         }
696
697       os[LEFT][Y_AXIS] += dir_ * staff_space_ / 2;
698     }
699
700   assert (scores.size () > 0);
701   return scores;
702 }
703
704
705 Array<Extra_collision_info>
706 Slur_score_state::get_extra_encompass_infos () const
707 {
708   Link_array<Grob> encompasses
709     = Pointer_group_interface__extract_grobs (slur_, (Grob *)0,
710                                               "encompass-objects");
711   Array<Extra_collision_info> collision_infos;
712   for (int i = encompasses.size (); i--; )
713     {
714       if (Slur::has_interface (encompasses[i]))
715         {
716           Spanner * small_slur = dynamic_cast<Spanner*> (encompasses[i]);
717           Bezier b = Slur::get_curve (small_slur);
718
719           Offset relative (small_slur->relative_coordinate (common_[X_AXIS], X_AXIS),
720                            small_slur->relative_coordinate (common_[Y_AXIS], Y_AXIS));
721
722           for (int k = 0; k < 3; k++)
723             {
724               Direction hdir =  Direction (k /2 - 1);
725
726               /*
727                 Only take bound into account if small slur starts
728                 together with big slur.
729               */
730               if (hdir && small_slur->get_bound (hdir) != slur_->get_bound (hdir))
731                 continue;
732         
733               Offset z = b.curve_point (k / 2.0);
734               z += relative;
735
736               Interval yext;
737               yext.set_full ();
738               yext[dir_] = z[Y_AXIS] + dir_ * thickness_ * 1.0;
739
740               Interval xext (-1, 1);
741               xext = xext * (thickness_*2) + z[X_AXIS];
742               Extra_collision_info info (small_slur,
743                                          k - 1.0,
744                                          xext,
745                                          yext,
746                                          parameters_.extra_object_collision_);
747               collision_infos.push (info);
748             }
749         }
750       else
751         {
752           Grob *g = encompasses [i];
753           Interval xe = g->extent (common_[X_AXIS], X_AXIS);
754           Interval ye = g->extent (common_[Y_AXIS], Y_AXIS);
755
756           Real xp = 0.0;
757           Real penalty = parameters_.extra_object_collision_;
758           if (Accidental_interface::has_interface (g))
759             {
760               penalty = parameters_.accidental_collision_;
761               /* Begin copy accidental.cc */
762               bool parens = false;
763               if (to_boolean (g->get_property ("cautionary")))
764                 {
765                   SCM cstyle = g->get_property ("cautionary-style");
766                   parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
767                 }
768         
769               SCM accs = g->get_property ("accidentals");
770               SCM scm_style = g->get_property ("style");
771               if (!scm_is_symbol (scm_style)
772                   && !parens
773                   && scm_ilength (accs) == 1)
774                 {
775                   /* End copy accidental.cc */
776                   switch (scm_to_int (scm_car (accs)))
777                     {
778                     case FLAT:
779                     case DOUBLE_FLAT:
780                       xp = LEFT;
781                       break ;
782                     case SHARP:
783                       xp = 0.5 * dir_;
784                       break ;
785                     case NATURAL:
786                       xp = -dir_;
787                       break;
788                     }
789                 }
790             }
791
792           ye.widen (thickness_ * 0.5);
793           xe.widen (thickness_ * 1.0);
794           Extra_collision_info info (g, xp, xe, ye,  penalty);
795           collision_infos.push (info);
796         }
797     }
798
799   return collision_infos;
800 }
801