]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur-scoring.cc
release commit
[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 Real
128 broken_trend_y (Slur_score_state const &state, Direction hdir)
129 {
130   /* A broken slur should maintain the same vertical trend
131      the unbroken slur would have had.  */
132   Real by = 0.0;
133   if (Spanner *mother = dynamic_cast<Spanner*> (state.slur_->original_))
134     {
135       int k = broken_spanner_index (state.slur_);
136       int j = k + hdir;
137       if (j < 0 || j >= mother->broken_intos_.size ())
138         return by;
139
140       Grob *neighbor = mother->broken_intos_[j];
141       Spanner *common_mother
142         = dynamic_cast<Spanner*> (state.common_[Y_AXIS]->original_);
143       int common_k
144         = broken_spanner_index (dynamic_cast<Spanner*> (state.common_[Y_AXIS]));
145       int common_j = common_k + hdir;
146
147       if (common_j < 0 || common_j >= common_mother->broken_intos_.size ())
148         return by;
149
150       Grob *common_next_system = common_mother->broken_intos_[common_j];
151       
152       SCM last_point =  scm_car (scm_last_pair (neighbor->get_property ("control-points")));
153       
154       return scm_to_double (scm_cdr (last_point))
155         + neighbor->relative_coordinate (common_next_system, Y_AXIS);
156     }
157   return by;
158 }
159
160
161 /*
162   copy slur dir forwards across line break.
163 */
164 void
165 Slur_score_state::set_next_direction () 
166 {
167   if (extremes_[RIGHT].note_column_)
168     return;
169   
170   if (Spanner *mother = dynamic_cast<Spanner*> (slur_->original_))
171     {
172       int k = broken_spanner_index (slur_);
173       int j = k + 1;
174       if (j < 0 || j >= mother->broken_intos_.size ())
175         return;
176
177       Grob *neighbor = mother->broken_intos_[j];
178       set_grob_direction (neighbor, dir_);
179     }
180 }
181
182 Encompass_info
183 Slur_score_state::get_encompass_info (Grob *col) const
184 {
185   Grob *stem = unsmob_grob (col->get_property ("stem"));
186   Encompass_info ei;
187
188   if (!stem)
189     {
190       programming_error ("No stem for note column?");
191       ei.x_ = col->relative_coordinate (common_[X_AXIS], X_AXIS);
192       ei.head_ = ei.stem_ = col->extent (common_[Y_AXIS],
193                                          Y_AXIS)[dir_];
194       return ei;
195     }
196   Direction stem_dir = get_grob_direction (stem);
197
198   if (Grob *head = Note_column::first_head (col))
199     ei.x_ = head->extent (common_[X_AXIS], X_AXIS).center ();
200   else
201     ei.x_ = col->extent (common_[X_AXIS], X_AXIS).center ();
202
203   Grob *h = Stem::extremal_heads (stem)[Direction (dir_)];
204   if (!h)
205     {
206       ei.head_ = ei.stem_ = col->extent (common_[Y_AXIS], Y_AXIS)[dir_];
207       return ei;
208     }
209
210   ei.head_ = h->extent (common_[Y_AXIS], Y_AXIS)[dir_];
211
212   if ((stem_dir == dir_)
213       && !stem->extent (stem, Y_AXIS).is_empty ())
214     {
215       ei.stem_ = stem->extent (common_[Y_AXIS], Y_AXIS)[dir_];
216       if (Grob *b = Stem::get_beam (stem))
217         ei.stem_ += stem_dir * 0.5 * Beam::get_thickness (b);
218
219       Interval x = stem->extent (common_[X_AXIS], X_AXIS);
220       ei.x_ = x.is_empty ()
221         ? stem->relative_coordinate (common_[X_AXIS], X_AXIS)
222         : x.center ();
223     }
224   else
225     ei.stem_ = ei.head_;
226
227   return ei;
228 }
229
230
231
232
233 Drul_array<Bound_info>
234 Slur_score_state::get_bound_info () const
235 {
236   Drul_array<Bound_info> extremes;
237
238   Direction d = LEFT;
239   Direction dir = dir_;
240
241   do
242     {
243       extremes[d].bound_ = slur_->get_bound (d);
244       if (Note_column::has_interface (extremes[d].bound_))
245         {
246           extremes[d].note_column_ = extremes[d].bound_;
247           extremes[d].stem_ = Note_column::get_stem (extremes[d].note_column_);
248           extremes[d].stem_dir_ = get_grob_direction (extremes[d].stem_);
249           extremes[d].stem_extent_[X_AXIS]
250             = extremes[d].stem_->extent (common_[X_AXIS], X_AXIS);
251           extremes[d].stem_extent_[Y_AXIS]
252             = extremes[d].stem_->extent (common_[Y_AXIS], Y_AXIS);
253           extremes[d].slur_head_
254             = Stem::extremal_heads (extremes[d].stem_)[dir];
255           if (!extremes[d].slur_head_
256               && Note_column::has_rests (extremes[d].bound_))
257             {
258               extremes[d].slur_head_ = Note_column::get_rest (extremes[d].bound_);
259             }
260
261           if (extremes[d].slur_head_)
262             extremes[d].slur_head_extent_
263               = extremes[d].slur_head_->extent (common_[X_AXIS], X_AXIS);
264
265           extremes[d].staff_ = Staff_symbol_referencer
266             ::get_staff_symbol (extremes[d].stem_);
267           extremes[d].staff_space_ = Staff_symbol_referencer
268             ::staff_space (extremes[d].stem_);
269         }
270     }
271   while (flip (&d) != LEFT);
272   return extremes;
273 }
274
275 void
276 Slur_score_state::fill (Grob *me)
277 {
278   slur_ = dynamic_cast<Spanner*> (me);
279   columns_ 
280     = Pointer_group_interface__extract_grobs (me, (Grob *) 0, "note-columns");
281   
282   if (columns_.is_empty ())
283     {
284       me->suicide ();
285       return ;
286     }
287
288   staff_space_ = Staff_symbol_referencer::staff_space (me);
289   Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
290   thickness_ = robust_scm2double (me->get_property ("thickness"), 1.0) *  lt;
291   
292   dir_ = get_grob_direction (me);
293   parameters_.fill (me);
294   
295   SCM eltlist = me->get_property ("note-columns");
296   SCM extra_list = me->get_property ("encompass-objects");
297   Spanner *sp = dynamic_cast<Spanner*> (me);
298
299   for (int i = X_AXIS; i < NO_AXES; i++)
300     {
301       Axis a = (Axis)i;
302       common_[a] = common_refpoint_of_list (eltlist, me, a);
303       common_[a] = common_refpoint_of_list (extra_list, common_[a], a);
304
305       Direction d = LEFT;
306       do {
307         common_[a] = common_[a]->common_refpoint (sp->get_bound (d), a);
308       }
309       while (flip (&d) != LEFT);
310     }
311
312   extremes_ = get_bound_info ();
313   is_broken_ = (!extremes_[LEFT].note_column_
314                 || !extremes_[RIGHT].note_column_); 
315
316   
317   base_attachments_ = get_base_attachments ();
318
319   Drul_array<Real> end_ys
320     = get_y_attachment_range ();
321
322   configurations_ = enumerate_attachments ( end_ys);
323   for (int i = 0; i < columns_.size (); i++)
324     encompass_infos_.push (get_encompass_info ( columns_[i]));
325
326   extra_encompass_infos_ = get_extra_encompass_infos ();
327   valid_ = true;
328
329
330   musical_dy_ = 0.0;
331   Direction d = LEFT;
332   do
333     {
334       if (!is_broken_)
335         musical_dy_ += d
336           * extremes_[d].slur_head_->relative_coordinate (common_[Y_AXIS], Y_AXIS);
337     }
338   while (flip (&d) != LEFT);
339   
340   edge_has_beams_
341     = (extremes_[LEFT].stem_ && Stem::get_beam (extremes_[LEFT].stem_))
342     || (extremes_[RIGHT].stem_ && Stem::get_beam (extremes_[RIGHT].stem_));
343
344   has_same_beam_ =
345     (extremes_[LEFT].stem_ && extremes_[RIGHT].stem_
346      && Stem::get_beam (extremes_[LEFT].stem_) == Stem::get_beam (extremes_[RIGHT].stem_));
347
348   
349   set_next_direction ();
350
351   if (is_broken_)
352     musical_dy_ = 0.0;
353 }
354
355 void
356 set_slur_control_points (Grob *me)
357 {
358   Slur_score_state state;
359   state.fill (me);
360
361   if (!state.valid_)
362     return;
363   
364   state.generate_curves ();
365   Bezier best (state.get_best_curve());
366
367
368   SCM controls = SCM_EOL;
369   for (int i = 4; i--;)
370     {
371       Offset o = best.control_[i]
372         - Offset (me->relative_coordinate (state.common_[X_AXIS], X_AXIS),
373                   me->relative_coordinate (state.common_[Y_AXIS], Y_AXIS));
374       controls = scm_cons (ly_offset2scm (o), controls);
375     }
376   me->set_property ("control-points", controls);
377 }
378
379
380 Bezier
381 Slur_score_state::get_best_curve ()
382 {
383   for (int i = 0; i < configurations_.size (); i++)
384     {
385       configurations_[i]->score (*this);
386     }
387   
388   Real opt = 1e6;
389   int opt_idx = -1;
390   for (int i = 0; i < configurations_.size (); i++)
391     {
392       if (configurations_[i]->score_ < opt)
393         {
394           opt = configurations_[i]->score_;
395           opt_idx = i;
396         }
397     }
398
399 #if DEBUG_SLUR_SCORING
400   SCM inspect_quants = slur_->get_property ("inspect-quants");
401   if (to_boolean (slur_->get_paper ()
402                   ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
403       && scm_is_pair (inspect_quants))
404     {
405       Drul_array<Real> ins = ly_scm2interval (inspect_quants);
406       Real mindist = 1e6;
407       for (int i = 0; i < configurations_.size (); i ++)
408         {
409           Real d =fabs (configurations_[i]->attachment_[LEFT][Y_AXIS] - ins[LEFT])
410             + fabs (configurations_[i]->attachment_[RIGHT][Y_AXIS] - ins[RIGHT]);
411           if (d < mindist)
412             {
413               opt_idx = i;
414               mindist= d;
415             }
416         }
417       if (mindist > 1e5)
418         programming_error ("Could not find quant.");
419     }
420
421   configurations_[opt_idx]->score_card_ += to_string ("=%.2f", opt);  
422   configurations_[opt_idx]->score_card_ += to_string ("i%d", opt_idx);
423
424   // debug quanting
425   slur_->set_property ("quant-score",
426                     scm_makfrom0str (configurations_[opt_idx]->score_card_.to_str0 ()));
427
428 #endif
429
430   return configurations_[opt_idx]->curve_;
431 }
432
433 /*
434   TODO: should analyse encompasses to determine sensible region, and
435   should limit slopes available.
436  */
437
438 Drul_array<Real>
439 Slur_score_state::get_y_attachment_range () const
440 {
441   Drul_array<Real> end_ys;
442   Direction d = LEFT;
443   do
444     {
445       if (extremes_[d].note_column_)
446         {
447           end_ys[d] = dir_
448             * ((dir_ * (base_attachments_[d][Y_AXIS] +  parameters_.region_size_* dir_))
449                >? (dir_ * (dir_ + extremes_[d].note_column_->extent (common_[Y_AXIS],
450                                                                  Y_AXIS)[dir_]))
451                >? (dir_ * base_attachments_[-d][Y_AXIS]));
452         }
453       else
454         end_ys[d] = base_attachments_[d][Y_AXIS] + parameters_.region_size_ * dir_;
455     }
456   while (flip (&d) != LEFT);
457
458   return end_ys;
459 }
460
461 bool
462 spanner_less (Spanner *s1, Spanner* s2)
463 {
464   Slice b1, b2;
465   Direction d  = LEFT;
466   do
467     {
468       b1[d] = s1->get_bound (d)->get_column ()->rank_;
469       b2[d] = s2->get_bound (d)->get_column ()->rank_;
470     } while (flip (&d) != LEFT);
471
472   return b2[LEFT] <= b1[LEFT] && b2[RIGHT] >= b1[RIGHT]
473     && (b2[LEFT] != b1[LEFT] || b2[RIGHT] != b1[RIGHT]);
474 }
475
476
477 Drul_array<Offset>
478 Slur_score_state::get_base_attachments () const
479 {
480   Drul_array<Offset> base_attachment;
481   Direction d = LEFT;
482   do
483     {
484       Grob *stem = extremes_[d].stem_;
485       Grob *head = extremes_[d].slur_head_;
486
487       Real x = 0.0;
488       Real y = 0.0;
489       if (extremes_[d].note_column_)
490         {
491          
492           /*
493             fixme: X coord should also be set in this case.
494            */
495           if (stem
496               && extremes_[d].stem_dir_ == dir_
497               && Stem::get_beaming (stem, -d)
498               && (!spanner_less (slur_, Stem::get_beam (stem))
499                   || has_same_beam_))
500             y = extremes_[d].stem_extent_[Y_AXIS][dir_];
501           else if (head)
502             y = head->extent (common_[Y_AXIS], Y_AXIS)[dir_];
503           y += dir_ * 0.5 * staff_space_;
504
505           Real pos
506             = (y - extremes_[d].staff_->relative_coordinate (common_[Y_AXIS],
507                                                             Y_AXIS))
508             * 2.0 / staff_space_;
509
510           /* start off staffline. */
511           if (fabs (pos - my_round (pos)) < 0.2
512               && Staff_symbol_referencer::on_staffline (head, (int) rint (pos))
513               && Staff_symbol_referencer::line_count (head) - 1 >= rint (pos)
514               )
515             // TODO: calc from slur thick & line thick, parameter.      
516             y += 1.5 * staff_space_ * dir_ / 10;
517
518           Grob * fh = Note_column::first_head (extremes_[d].note_column_);
519           x =
520          (fh ? fh->extent (common_[X_AXIS], X_AXIS)
521              : extremes_[d].bound_->extent (common_[X_AXIS], X_AXIS))
522             .linear_combination (CENTER);
523         }
524       base_attachment[d] = Offset (x, y);
525
526     } while (flip (&d) != LEFT);
527
528   do
529     {
530       if (!extremes_[d].note_column_)
531         {
532           Real x, y;
533           if (d == RIGHT)
534             {
535               x = extremes_[d].bound_->extent (common_[X_AXIS], X_AXIS)[d];
536             }
537           else
538             {
539               x = slur_->get_broken_left_end_align ();
540             }
541           Grob * col = (d == LEFT) ? columns_[0] : columns_.top();
542               
543           if (extremes_[-d].bound_ != col)
544             {
545               y = robust_relative_extent (col, common_[Y_AXIS], Y_AXIS)[dir_];
546               if (get_grob_direction (col) == dir_)
547                 y -= dir_ ;
548             }
549           else
550             y = base_attachment[-d][Y_AXIS];
551
552           base_attachment[d] = Offset (x, y);  
553         }
554     }
555   while (flip (&d) != LEFT);
556
557   return base_attachment;
558 }
559
560 void
561 Slur_score_state::generate_curves () const
562 {
563   Real r_0 = robust_scm2double (slur_->get_property ("ratio"), 0.33);
564   Real h_inf = staff_space_ *scm_to_double (slur_->get_property ("height-limit"));
565   for (int i = 0; i < configurations_.size (); i++)
566     configurations_[i]->generate_curve (*this, r_0, h_inf);
567 }
568
569
570
571
572 Link_array<Slur_configuration> 
573 Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
574 {
575   /*ugh.   */
576   Link_array<Slur_configuration> scores;
577
578
579   Drul_array<Offset> os;
580   os[LEFT] = base_attachments_[LEFT];
581   Real minimum_length = staff_space_
582     * robust_scm2double (slur_->get_property ("minimum-length"), 2.0);
583
584   for (int i = 0; dir_ * os[LEFT][Y_AXIS] <= dir_ * end_ys[LEFT]; i++)
585     {
586       os[RIGHT] = base_attachments_[RIGHT];
587       for (int j = 0; dir_ * os[RIGHT][Y_AXIS] <= dir_ * end_ys[RIGHT]; j++)
588         {
589           Slur_configuration s;
590           Direction d = LEFT;
591           Drul_array<bool> attach_to_stem (false, false);
592           do
593             {
594               os[d][X_AXIS] = base_attachments_[d][X_AXIS];
595               if (extremes_[d].stem_
596                   && !Stem::is_invisible (extremes_[d].stem_)
597                   && extremes_[d].stem_dir_ == dir_)
598                 {
599                   Interval stem_y = extremes_[d].stem_extent_[Y_AXIS];
600                   stem_y.widen (0.25 * staff_space_);
601                   if (dir_ == -d
602                       && stem_y.contains (os[d][Y_AXIS]))
603                     {
604                       os[d][X_AXIS] =  extremes_[d].slur_head_extent_[-d]
605                         - d * 0.3;
606                       attach_to_stem[d] = true;
607                     }
608                   else if (dir_ *extremes_[d].stem_extent_[Y_AXIS][dir_]
609                              < dir_ * os[d][Y_AXIS]
610                            && !extremes_[d].stem_extent_[X_AXIS].is_empty ()
611                            )
612                 
613                     os[d][X_AXIS] = extremes_[d].stem_extent_[X_AXIS].center ();
614                 }
615             }
616           while (flip (&d) != LEFT);
617
618           Offset dz;    
619           dz = os[RIGHT] - os[LEFT];
620           if (dz[X_AXIS] < minimum_length
621               || fabs (dz[Y_AXIS] / dz[X_AXIS]) > parameters_.max_slope_
622               )
623             {
624               do
625                 {
626                   if (extremes_[d].slur_head_)
627                     {
628                       os[d][X_AXIS] = extremes_[d].slur_head_extent_.center ();
629                       attach_to_stem[d] = false;
630                     }
631                 }
632               while (flip (&d) != LEFT);
633             }
634
635           dz = os[RIGHT] - os[LEFT];
636           do
637             {
638               if (extremes_[d].slur_head_
639                   && !attach_to_stem[d])
640                 {
641                   /* Horizontally move tilted slurs a little.  Move
642                      more for bigger tilts.
643                 
644                      TODO: parameter */
645                   os[d][X_AXIS]
646                     -= dir_ * extremes_[d].slur_head_extent_.length ()
647                     * sin (dz.arg ()) / 3;
648                 }
649             }
650           while (flip (&d) != LEFT);
651         
652           s.attachment_ = os;
653           s.index_ = scores.size ();
654
655           scores.push (new Slur_configuration (s));
656           
657           os[RIGHT][Y_AXIS] += dir_ * staff_space_ / 2;
658         }
659
660       os[LEFT][Y_AXIS] += dir_ * staff_space_ / 2;
661     }
662
663   assert (scores.size () > 0);
664   return scores;
665 }
666
667
668 Array<Extra_collision_info>
669 Slur_score_state::get_extra_encompass_infos () const
670 {
671   Link_array<Grob> encompasses
672     = Pointer_group_interface__extract_grobs (slur_, (Grob *)0,
673                                               "encompass-objects");
674   Array<Extra_collision_info> collision_infos;
675   for (int i = encompasses.size (); i--; )
676     {
677       if (Slur::has_interface (encompasses[i]))
678         {
679           Spanner * small_slur = dynamic_cast<Spanner*> (encompasses[i]);
680           Bezier b = Slur::get_curve (small_slur);
681
682           Offset relative (small_slur->relative_coordinate (common_[X_AXIS], X_AXIS),
683                            small_slur->relative_coordinate (common_[Y_AXIS], Y_AXIS));
684
685           for (int k = 0; k < 3; k++)
686             {
687               Direction hdir =  Direction (k /2 - 1);
688
689               /*
690                 Only take bound into account if small slur starts
691                 together with big slur.
692               */
693               if (hdir && small_slur->get_bound (hdir) != slur_->get_bound (hdir))
694                 continue;
695         
696               Offset z = b.curve_point (k / 2.0);
697               z += relative;
698
699               Interval yext;
700               yext.set_full ();
701               yext[dir_] = z[Y_AXIS] + dir_ * thickness_ * 1.0;
702
703               Interval xext (-1, 1);
704               xext = xext * (thickness_*2) + z[X_AXIS];
705               Extra_collision_info info (small_slur,
706                                          k - 1.0,
707                                          xext,
708                                          yext,
709                                          parameters_.extra_object_collision_);
710               collision_infos.push (info);
711             }
712         }
713       else
714         {
715           Grob *g = encompasses [i];
716           Interval xe = g->extent (common_[X_AXIS], X_AXIS);
717           Interval ye = g->extent (common_[Y_AXIS], Y_AXIS);
718
719           Real xp = 0.0;
720           Real penalty = parameters_.extra_object_collision_;
721           if (Accidental_interface::has_interface (g))
722             {
723               penalty = parameters_.accidental_collision_;
724               /* Begin copy accidental.cc */
725               bool parens = false;
726               if (to_boolean (g->get_property ("cautionary")))
727                 {
728                   SCM cstyle = g->get_property ("cautionary-style");
729                   parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
730                 }
731         
732               SCM accs = g->get_property ("accidentals");
733               SCM scm_style = g->get_property ("style");
734               if (!scm_is_symbol (scm_style)
735                   && !parens
736                   && scm_ilength (accs) == 1)
737                 {
738                   /* End copy accidental.cc */
739                   switch (scm_to_int (scm_car (accs)))
740                     {
741                     case FLAT:
742                     case DOUBLE_FLAT:
743                       xp = LEFT;
744                       break ;
745                     case SHARP:
746                       xp = 0.5 * dir_;
747                       break ;
748                     case NATURAL:
749                       xp = -dir_;
750                       break;
751                     }
752                 }
753             }
754
755           ye.widen (thickness_ * 0.5);
756           xe.widen (thickness_ * 1.0);
757           Extra_collision_info info (g, xp, xe, ye,  penalty);
758           collision_infos.push (info);
759         }
760     }
761
762   return collision_infos;
763 }
764