2 slur-quanting.cc -- Score based slur formatting
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 #include "accidental-interface.hh"
14 #include "directional-element-interface.hh"
15 #include "group-interface.hh"
16 #include "lily-guile.hh"
17 #include "new-slur.hh"
18 #include "note-column.hh"
19 #include "output-def.hh"
21 #include "slur-bezier-bow.hh"
23 #include "staff-symbol-referencer.hh"
24 #include "staff-symbol.hh"
27 #include "paper-column.hh"
32 Drul_array<Offset> attachment_;
36 #if DEBUG_SLUR_QUANTING
47 TODO: put in details property.,
51 struct Slur_score_parameters
54 Real HEAD_ENCOMPASS_PENALTY;
55 Real STEM_ENCOMPASS_PENALTY;
56 Real CLOSENESS_FACTOR;
57 Real EDGE_ATTRACTION_FACTOR;
58 Real SAME_SLOPE_PENALTY;
59 Real STEEPER_SLOPE_FACTOR;
60 Real NON_HORIZONTAL_PENALTY;
61 Real HEAD_STRICT_FREE_SPACE;
63 Real MAX_SLOPE_FACTOR;
64 Real EXTRA_OBJECT_COLLISION;
65 Real ACCIDENTAL_COLLISION;
66 Real FREE_HEAD_DISTANCE;
67 Slur_score_parameters ();
73 - curve around flag for y coordinate
75 - short-cut: try a smaller region first.
76 - collisions with accidentals
77 - collisions with articulations (staccato, portato, sforzato, ...)
102 Interval slur_head_extent_;
121 score_extra_encompass (Grob *me, Grob *common[],
122 Slur_score_parameters *score_param,
123 Drul_array<Bound_info> ,
125 Array<Slur_score> * scores);
126 static void score_slopes (Grob *me, Grob *common[],
127 Slur_score_parameters *score_param,
128 Drul_array<Bound_info>,
129 Drul_array<Offset> base_attach,
130 Array<Slur_score> *scores);
132 static void score_edges (Grob *me, Grob *common[],
133 Slur_score_parameters *score_param,
134 Drul_array<Bound_info> extremes,
135 Drul_array<Offset> base_attach,
136 Array<Slur_score> *scores);
137 static void score_encompass (Grob *me, Grob *common[],
138 Slur_score_parameters*,
139 Drul_array<Bound_info>,
140 Drul_array<Offset>, Array<Slur_score> *scores);
141 static Bezier avoid_staff_line (Grob *me, Grob **common,
142 Drul_array<Bound_info> extremes,
145 static Encompass_info get_encompass_info (Grob *me,
148 static Bezier get_bezier (Grob *me, Drul_array<Offset>, Real, Real);
149 static Direction get_default_dir (Grob *me);
151 static void set_end_points (Grob *);
152 static Real broken_trend_y (Grob *me, Grob **, Direction dir);
153 static Drul_array<Bound_info> get_bound_info (Spanner *me, Grob **common);
155 static void generate_curves (Grob *me,
157 Drul_array<Bound_info> extremes,
158 Drul_array<Offset> base_attach,
159 Array<Slur_score> *scores);
160 static Array<Slur_score> enumerate_attachments
161 (Grob *me, Grob *common[], Slur_score_parameters *score_param,
162 Drul_array<Bound_info> extremes,
163 Drul_array<Offset> base_attachment, Drul_array<Real> end_ys);
164 static Drul_array<Offset> get_base_attachments
165 (Spanner *sp, Grob **common, Drul_array<Bound_info> extremes);
166 static Drul_array<Real> get_y_attachment_range
167 (Spanner *sp, Grob **common, Drul_array<Bound_info> extremes,
168 Drul_array<Offset> base_attachment);
171 init_score_param (Slur_score_parameters *score_param)
173 score_param->SLUR_REGION_SIZE = 5;
174 score_param->HEAD_ENCOMPASS_PENALTY = 1000.0;
175 score_param->STEM_ENCOMPASS_PENALTY = 30.0;
176 score_param->CLOSENESS_FACTOR = 10;
177 score_param->EDGE_ATTRACTION_FACTOR = 4;
178 score_param->SAME_SLOPE_PENALTY = 20;
179 score_param->STEEPER_SLOPE_FACTOR = 50;
180 score_param->NON_HORIZONTAL_PENALTY = 15;
181 score_param->HEAD_STRICT_FREE_SPACE = 0.2;
182 score_param->MAX_SLOPE = 1.1;
183 score_param->MAX_SLOPE_FACTOR = 10;
184 score_param->FREE_HEAD_DISTANCE = 0.3;
185 score_param->EXTRA_OBJECT_COLLISION = 50;
186 score_param->ACCIDENTAL_COLLISION = 3;
189 Slur_score_parameters::Slur_score_parameters()
191 init_score_param (this);
194 /* HDIR indicates the direction for the slur. */
196 broken_trend_y (Grob *me, Grob **common, Direction hdir)
198 /* A broken slur should maintain the same vertical trend
199 the unbroken slur would have had. */
201 if (Spanner *mother = dynamic_cast<Spanner*> (me->original_))
203 int k = broken_spanner_index (dynamic_cast<Spanner*> (me));
205 if (j < 0 || j >= mother->broken_intos_.size ())
208 Grob *neighbor = mother->broken_intos_[j];
210 neighbor->set_property ("direction",
211 me->get_property ("direction"));
213 Spanner *common_mother
214 = dynamic_cast<Spanner*> (common[Y_AXIS]->original_);
216 = broken_spanner_index (dynamic_cast<Spanner*> (common[Y_AXIS]));
217 int common_j = common_k + hdir;
219 if (common_j < 0 || common_j >= common_mother->broken_intos_.size())
222 Grob *common_next_system = common_mother->broken_intos_[common_j];
223 Link_array<Grob> neighbor_cols
224 = Pointer_group_interface__extract_grobs (neighbor, (Grob *)0,
228 = (hdir == RIGHT) ? neighbor_cols[0] : neighbor_cols.top ();
229 Grob *neighbor_common
230 = common_next_system->common_refpoint (neighbor_col, Y_AXIS);
232 Direction vdir = get_grob_direction (me);
234 = neighbor_col->extent (neighbor_common, Y_AXIS)
235 .linear_combination (int(neighbor_cols.size()==1 ? CENTER : vdir))
236 - common_next_system->relative_coordinate (neighbor_common, Y_AXIS);
238 Link_array<Grob> my_cols
239 = Pointer_group_interface__extract_grobs (me, (Grob *)0,
242 Grob *extreme_col = (hdir == RIGHT) ? my_cols.top() : my_cols[0];
243 Real y = extreme_col->extent (common[Y_AXIS], Y_AXIS)
244 .linear_combination (int ((my_cols.size() == 1) ? CENTER : vdir));
245 by = (y*neighbor_cols.size() + neighbor_y*my_cols.size()) /
246 (my_cols.size() + neighbor_cols.size());
252 get_encompass_info (Grob *me,
256 Grob *stem = unsmob_grob (col->get_property ("stem"));
258 Direction dir = get_grob_direction (me);
262 programming_error ("No stem for note column?");
263 ei.x_ = col->relative_coordinate (common[X_AXIS], X_AXIS);
264 ei.head_ = ei.stem_ = col->extent (common[Y_AXIS],
265 Y_AXIS)[get_grob_direction (me)];
268 Direction stem_dir = get_grob_direction (stem);
270 if (Grob *head = Note_column::first_head (col))
271 ei.x_ = head->extent (common[X_AXIS], X_AXIS).center ();
273 ei.x_ = col->extent (common[X_AXIS], X_AXIS).center ();
275 Grob *h = Stem::extremal_heads (stem)[Direction (dir)];
278 ei.head_ = ei.stem_ = col->extent (common[Y_AXIS], Y_AXIS)[dir];
282 ei.head_ = h->extent (common[Y_AXIS], Y_AXIS)[dir];
284 if ((stem_dir == dir)
285 && !stem->extent (stem, Y_AXIS).is_empty ())
287 ei.stem_ = stem->extent (common[Y_AXIS], Y_AXIS)[dir];
288 if (Grob *b = Stem::get_beam (stem))
289 ei.stem_ += stem_dir * 0.5 * Beam::get_thickness (b);
290 ei.x_ = stem->extent (common[X_AXIS], X_AXIS).center ();
300 get_default_dir (Grob*me)
302 Link_array<Grob> encompasses
303 = Pointer_group_interface__extract_grobs (me, (Grob*) 0, "note-columns");
306 for (int i= 0; i < encompasses.size (); i ++)
308 if (Note_column::dir (encompasses[i]) < 0)
317 MAKE_SCHEME_CALLBACK (New_slur, after_line_breaking,1);
319 New_slur::after_line_breaking (SCM smob)
321 Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (smob));
322 if (!scm_ilength (me->get_property ("note-columns")))
325 return SCM_UNSPECIFIED;
328 if (!get_grob_direction (me))
329 set_grob_direction (me, get_default_dir (me));
333 return SCM_UNSPECIFIED;
337 get_bezier (Grob *me, Drul_array<Offset> extremes, Real r_0, Real h_inf)
339 Array<Offset> encompasses;
340 encompasses.push (extremes[LEFT]);
341 encompasses.push (extremes[RIGHT]);
343 Slur_bezier_bow bb (encompasses,
344 get_grob_direction (me), h_inf, r_0);
346 return bb.get_bezier ();
349 Drul_array<Bound_info>
350 get_bound_info (Spanner* me, Grob **common)
352 Drul_array<Bound_info> extremes;
354 Direction dir = get_grob_direction (me);
358 extremes[d].bound_ = me->get_bound (d);
359 if (Note_column::has_interface (extremes[d].bound_))
361 extremes[d].note_column_ = extremes[d].bound_;
362 extremes[d].stem_ = Note_column::get_stem (extremes[d].note_column_);
363 extremes[d].stem_dir_ = get_grob_direction (extremes[d].stem_);
364 extremes[d].stem_extent_[X_AXIS]
365 = extremes[d].stem_->extent (common[X_AXIS], X_AXIS);
366 extremes[d].stem_extent_[Y_AXIS]
367 = extremes[d].stem_->extent (common[Y_AXIS], Y_AXIS);
368 extremes[d].slur_head_
369 = Stem::extremal_heads (extremes[d].stem_)[dir];
370 extremes[d].slur_head_extent_
371 = extremes[d].slur_head_->extent (common[X_AXIS], X_AXIS);
372 extremes[d].staff_ = Staff_symbol_referencer
373 ::get_staff_symbol (extremes[d].slur_head_);
374 extremes[d].staff_space_ = Staff_symbol_referencer
375 ::staff_space (extremes[d].slur_head_);
378 extremes[d].neighbor_y_ = broken_trend_y (me, common, d);
380 while (flip (&d) != LEFT);
385 set_end_points (Grob *me)
387 Link_array<Grob> columns
388 = Pointer_group_interface__extract_grobs (me, (Grob *) 0, "note-columns");
389 Slur_score_parameters params;
390 if (columns.is_empty ())
396 SCM eltlist = me->get_property ("note-columns");
397 SCM extra_list = me->get_property ("encompass-objects");
398 Spanner *sp = dynamic_cast<Spanner*> (me);
400 Grob *common[] = {0, 0};
401 for (int i = X_AXIS; i < NO_AXES; i++)
404 common[a] = common_refpoint_of_list (eltlist, me, a);
405 common[a] = common_refpoint_of_list (extra_list, common[a], a);
408 common[X_AXIS] = common[X_AXIS]->common_refpoint (sp->get_bound (RIGHT),
410 common[X_AXIS] = common[X_AXIS]->common_refpoint (sp->get_bound (LEFT),
413 Drul_array<Bound_info> extremes = get_bound_info (sp, common);
414 Drul_array<Offset> base_attachment
415 = get_base_attachments (sp, common, extremes);
416 Drul_array<Real> end_ys
417 = get_y_attachment_range (sp, common, extremes, base_attachment);
418 Array<Slur_score> scores = enumerate_attachments (me, common, ¶ms,
419 extremes, base_attachment,
422 generate_curves (me, common, extremes, base_attachment, &scores);
423 score_edges (me, common, ¶ms,extremes, base_attachment, &scores);
424 score_slopes (me, common, ¶ms,extremes, base_attachment, &scores);
425 score_encompass (me, common, ¶ms,extremes, base_attachment, &scores);
426 score_extra_encompass (me, common, ¶ms,extremes, base_attachment,
432 for (int i = scores.size (); i--;)
434 if (scores[i].score_ < opt)
436 opt = scores[i].score_;
441 #if DEBUG_SLUR_QUANTING
442 SCM inspect_quants = me->get_property ("inspect-quants");
443 if (to_boolean (me->get_paper ()
444 ->lookup_variable (ly_symbol2scm ("debug-slur-quanting")))
445 && ly_c_pair_p (inspect_quants))
447 Drul_array<Real> ins = ly_scm2interval (inspect_quants);
449 for (int i = 0; i < scores.size (); i ++)
451 Real d =fabs (scores[i].attachment_[LEFT][Y_AXIS] - ins[LEFT])
452 + fabs (scores[i].attachment_[RIGHT][Y_AXIS] - ins[RIGHT]);
460 programming_error ("Could not find quant.");
462 scores[opt_idx].score_card_ += to_string ("i%d", opt_idx);
465 me->set_property ("quant-score",
466 scm_makfrom0str (scores[opt_idx].score_card_.to_str0 ()));
469 Bezier b = scores[opt_idx].curve_;
470 SCM controls = SCM_EOL;
471 for (int i = 4; i--;)
473 Offset o = b.control_[i]
474 - Offset (me->relative_coordinate (common[X_AXIS], X_AXIS),
475 me->relative_coordinate (common[Y_AXIS], Y_AXIS));
476 controls = scm_cons (ly_offset2scm (o), controls);
478 me->set_property ("control-points", controls);
483 get_y_attachment_range (Spanner*me,
485 Drul_array<Bound_info> extremes,
486 Drul_array<Offset> base_attachment)
488 Drul_array<Real> end_ys;
489 Direction dir = get_grob_direction (me);
493 if (extremes[d].note_column_)
496 * ((dir * (base_attachment[d][Y_AXIS] + 4.0 * dir))
497 >? (dir * (dir + extremes[d].note_column_->extent(common[Y_AXIS],
499 >? (dir * base_attachment[-d][Y_AXIS]));
502 end_ys[d] = extremes[d].neighbor_y_ + 4.0 * dir;
504 while (flip (&d) != LEFT);
510 spanner_less (Spanner *s1, Spanner* s2)
516 b1[d] = s1->get_bound (d)->get_column ()->rank_;
517 b2[d] = s2->get_bound (d)->get_column ()->rank_;
518 } while (flip (&d) != LEFT);
520 return b2[LEFT] <= b1[LEFT] && b2[RIGHT] >= b1[RIGHT]
521 && (b2[LEFT] != b1[LEFT] || b2[RIGHT] != b1[RIGHT]);
526 get_base_attachments (Spanner *me,
527 Grob **common, Drul_array<Bound_info> extremes)
529 Link_array<Grob> columns
530 = Pointer_group_interface__extract_grobs (me, (Grob *)0, "note-columns");
531 Drul_array<Offset> base_attachment;
532 Slur_score_parameters params;
533 Real staff_space = Staff_symbol_referencer::staff_space ((Grob *) me);
534 Direction dir = get_grob_direction (me);
538 Grob *stem = extremes[d].stem_;
539 Grob *head = extremes[d].slur_head_;
542 if (!extremes[d].note_column_)
544 y = extremes[d].neighbor_y_;
546 x = extremes[d].bound_->extent (common[X_AXIS], X_AXIS)[d];
548 x = me->get_broken_left_end_align ();
553 (extremes[d].stem_ && extremes[-d].stem_
554 && Stem::get_beam (extremes[d].stem_) == Stem::get_beam (extremes[-d].stem_));
556 && extremes[d].stem_dir_ == dir
557 && Stem::get_beaming (stem, -d)
558 && (!spanner_less (me, Stem::get_beam (stem))
560 y = extremes[d].stem_extent_[Y_AXIS][dir];
562 y = head->extent (common[Y_AXIS], Y_AXIS)[dir];
563 y += dir * 0.5 * staff_space;
566 = (y - extremes[d].staff_->relative_coordinate (common[Y_AXIS],
568 * 2.0 / Staff_symbol::staff_space (extremes[d].staff_);
570 /* start off staffline. */
571 if (fabs (pos - round (pos)) < 0.2
572 && Staff_symbol_referencer::on_staffline (head, (int) rint (pos))
573 && Staff_symbol_referencer::line_count (head) - 1 >= rint (pos)
575 // TODO: calc from slur thick & line thick, parameter.
576 y += 1.5 * staff_space * dir / 10;
578 Grob * fh = Note_column::first_head (extremes[d].note_column_);
579 x = fh->extent (common[X_AXIS], X_AXIS).linear_combination (CENTER);
581 base_attachment[d] = Offset (x, y);
583 } while (flip (&d) != LEFT);
585 return base_attachment;
589 generate_curves (Grob *me, Grob **common,
590 Drul_array<Bound_info> extremes,
592 Array<Slur_score> *scores)
596 Real staff_space = Staff_symbol_referencer::staff_space ((Grob *) me);
597 Real r_0 = robust_scm2double (me->get_property ("ratio"), 0.33);
598 Real h_inf = staff_space * ly_scm2double (me->get_property ("height-limit"));
599 for (int i = 0; i < scores->size(); i++)
601 Bezier bez= get_bezier (me, (*scores)[i].attachment_, r_0, h_inf);
602 bez = avoid_staff_line (me, common, extremes, bez);
603 (*scores)[i].attachment_[LEFT] = bez.control_[0];
604 (*scores)[i].attachment_[RIGHT] = bez.control_[3];
605 (*scores)[i].curve_ = bez;
610 avoid_staff_line (Grob *me, Grob **common,
611 Drul_array<Bound_info> extremes,
615 Array<Real> ts = bez.solve_derivative (horiz);
616 Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
617 Real thick = robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
619 /* TODO: handle case of broken slur. */
621 && (extremes[LEFT].staff_ == extremes[RIGHT].staff_)
622 && extremes[LEFT].staff_ && extremes[RIGHT].staff_)
624 Real y = bez.curve_point (ts[0])[Y_AXIS];
626 Grob *staff = extremes[LEFT].staff_;
628 Real staff_space = extremes[LEFT].staff_space_;
629 Real p = 2 * (y - staff->relative_coordinate (common[Y_AXIS], Y_AXIS))
632 Real distance = fabs (round (p) - p); // in halfspaces
633 if (distance < 4 * thick
634 && (int) fabs (round (p))
635 <= 2 * Staff_symbol_referencer::staff_radius (staff) + 0.1
636 && (int (fabs (round (p))) % 2
637 != Staff_symbol_referencer::line_count (staff) % 2))
639 Direction resolution_dir =
640 (distance ? get_grob_direction (me) : Direction (sign (p - round(p))));
643 Real newp = round (p) + resolution_dir
646 Real dy = (newp - p) * staff_space / 2.0;
648 bez.translate (Offset (0, dy));
650 bez.control_[1][Y_AXIS] += dy;
651 bez.control_[2][Y_AXIS] += dy;
660 enumerate_attachments (Grob *me, Grob *common[],
661 Slur_score_parameters *score_param,
662 Drul_array<Bound_info> extremes,
663 Drul_array<Offset> base_attachment,
664 Drul_array<Real> end_ys)
668 Array<Slur_score> scores;
670 Direction dir = get_grob_direction (me);
671 Real staff_space = Staff_symbol_referencer::staff_space ((Grob *) me);
673 Drul_array<Offset> os;
674 os[LEFT] = base_attachment[LEFT];
675 Real minimum_length = staff_space
676 * robust_scm2double (me->get_property ("minimum-length"), 2.0);
678 for (int i = 0; dir * os[LEFT][Y_AXIS] <= dir * end_ys[LEFT]; i++)
680 os[RIGHT] = base_attachment[RIGHT];
681 for (int j = 0; dir * os[RIGHT][Y_AXIS] <= dir * end_ys[RIGHT]; j++)
685 Drul_array<bool> attach_to_stem (false, false);
688 os[d][X_AXIS] = base_attachment[d][X_AXIS];
689 if (extremes[d].stem_
690 && !Stem::is_invisible (extremes[d].stem_)
691 && extremes[d].stem_dir_ == dir
694 if (extremes[d].stem_extent_[Y_AXIS].contains (os[d][Y_AXIS]))
696 os[d][X_AXIS] = extremes[d].slur_head_extent_[-d]
698 attach_to_stem[d] = true;
700 else if (dir *extremes[d].stem_extent_[Y_AXIS][dir]
701 < dir * os[d][Y_AXIS])
702 os[d][X_AXIS] = extremes[d].stem_extent_[X_AXIS].center();
705 while (flip (&d) != LEFT);
708 dz = os[RIGHT] - os[LEFT];
709 if (dz[X_AXIS] < minimum_length
710 || fabs (dz[Y_AXIS] / dz[X_AXIS]) > score_param->MAX_SLOPE
715 if (extremes[d].slur_head_)
717 os[d][X_AXIS] = extremes[d].slur_head_extent_.center ();
718 attach_to_stem[d] = false;
721 while (flip (&d) != LEFT);
724 dz = os[RIGHT] - os[LEFT];
727 if (extremes[d].slur_head_
728 && !attach_to_stem[d])
730 /* Horizontally move tilted slurs a little. Move
731 more for bigger tilts.
735 -= dir * extremes[d].slur_head_extent_.length ()
736 * sin (dz.arg ()) / 3;
739 while (flip (&d) != LEFT);
744 os[RIGHT][Y_AXIS] += dir * staff_space / 2;
747 os[LEFT][Y_AXIS] += dir * staff_space / 2;
753 score_encompass (Grob *me, Grob *common[],
754 Slur_score_parameters *score_param,
755 Drul_array<Bound_info> extremes,
756 Drul_array<Offset> base_attach,
757 Array<Slur_score> *scores)
762 Link_array<Grob> encompasses
763 = Pointer_group_interface__extract_grobs (me, (Grob *)0, "note-columns");
764 Direction dir = get_grob_direction (me);
766 Array<Encompass_info> infos;
768 for (int i = 0; i < encompasses.size(); i++)
769 infos.push (get_encompass_info (me, encompasses[i], common));
771 for (int i = 0; i < scores->size (); i++)
773 Bezier const &bez (scores->elem (i).curve_);
775 for (int j = 0; j < infos.size(); j++)
777 Real x = infos[j].x_;
780 bool r_edge = j==infos.size()-1;
781 bool edge = l_edge || r_edge;
783 if (!(x < scores->elem (i).attachment_[RIGHT][X_AXIS]
784 && x > scores->elem (i).attachment_[LEFT][X_AXIS]))
787 Real y = bez.get_other_coordinate (X_AXIS, x);
790 Real head_dy = (y - infos[j].head_);
791 if (dir * head_dy < 0)
792 demerit += score_param->HEAD_ENCOMPASS_PENALTY;
796 ? (1 / fabs (head_dy) - 1 / score_param->FREE_HEAD_DISTANCE)
797 : score_param->HEAD_ENCOMPASS_PENALTY;
798 hd = (hd >? 0)<? score_param->HEAD_ENCOMPASS_PENALTY;
804 if (dir * (y - infos[j].stem_) < 0)
806 Real stem_dem =score_param->STEM_ENCOMPASS_PENALTY ;
807 if ((l_edge && dir == UP)
808 || (r_edge && dir == DOWN))
816 ext.add_point (infos[j].stem_);
817 ext.add_point (infos[j].head_);
820 demerit += -score_param->CLOSENESS_FACTOR
822 * (y - (ext[dir] + dir * score_param->FREE_HEAD_DISTANCE))
828 #if DEBUG_SLUR_QUANTING
829 (*scores)[i].score_card_ += to_string ("C%.2f", demerit);
832 (*scores)[i].score_ += demerit;
837 score_extra_encompass (Grob *me, Grob *common[],
838 Slur_score_parameters *score_param,
839 Drul_array<Bound_info> extremes,
840 Drul_array<Offset> base_attach,
841 Array<Slur_score> *scores)
846 Link_array<Grob> encompasses
847 = Pointer_group_interface__extract_grobs (me, (Grob *)0,
848 "encompass-objects");
849 Direction dir = get_grob_direction (me);
850 Real staff_space = Staff_symbol_referencer::staff_space ((Grob *) me);
851 Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
852 Real thick = robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
855 Array<Interval> yexts;
856 Array<Interval> xexts;
857 for (int i = 0; i < encompasses.size (); i++)
859 Grob *g = encompasses [i];
860 Interval xe = g->extent (common[X_AXIS], X_AXIS);
861 Interval ye = g->extent (common[Y_AXIS], Y_AXIS);
865 if (Accidental_interface::has_interface (g))
867 /* Begin copy accidental.cc */
869 if (to_boolean (g->get_property ("cautionary")))
871 SCM cstyle = g->get_property ("cautionary-style");
872 parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
875 SCM accs = g->get_property ("accidentals");
876 SCM scm_style = g->get_property ("style");
877 if (!ly_c_symbol_p (scm_style)
879 && scm_ilength (accs) == 1)
881 /* End copy accidental.cc */
882 switch (ly_scm2int (ly_car (accs)))
899 ye.widen (thick * 0.5);
904 for (int i = 0; i < scores->size (); i++)
906 Bezier const &bez (scores->elem (i).curve_);
908 for (int j = 0; j < xidxs.size(); j++)
910 Drul_array<Offset> at = scores->elem (i).attachment_;
911 Interval slur_wid (at[LEFT][X_AXIS], at[RIGHT][X_AXIS]);
914 to prevent numerical inaccuracies in
915 Bezier::get_other_coordinate().
917 slur_wid.widen (- 0.5 * thick);
918 Real x = xexts[j].linear_combination (xidxs[j]);
920 if (!slur_wid.contains (x))
922 Direction contains_dir = CENTER;
926 if (xexts[j].contains (at[d][X_AXIS]))
929 while (flip (&d) != LEFT);
934 y = at[contains_dir][Y_AXIS];
938 y = scores->elem (i).curve_.get_other_coordinate (X_AXIS, x);
941 if (yexts[j].contains (y))
943 if (Accidental_interface::has_interface (encompasses[j]))
944 demerit += score_param->ACCIDENTAL_COLLISION;
946 demerit += score_param->EXTRA_OBJECT_COLLISION;
949 #if DEBUG_SLUR_QUANTING
950 (*scores)[i].score_card_ += to_string ("X%.2f", demerit);
952 (*scores)[i].score_ += demerit;
957 score_edges (Grob *me, Grob *common[],
958 Slur_score_parameters * score_param,
959 Drul_array<Bound_info> extremes,
960 Drul_array<Offset> base_attach,
961 Array<Slur_score> *scores)
964 Direction dir = get_grob_direction (me);
966 for (int i = 0; i < scores->size (); i++)
971 Real y = scores->elem (i).attachment_[d][Y_AXIS];
972 Real dy = fabs (y - base_attach[d][Y_AXIS]);
974 Real factor = score_param->EDGE_ATTRACTION_FACTOR;
975 Real demerit = factor * dy;
976 if (extremes[d].stem_
977 && extremes[d].stem_dir_ == dir
978 && !Stem::get_beaming (extremes[d].stem_, -d)
982 (*scores)[i].score_ += demerit;
983 #if DEBUG_SLUR_QUANTING
984 (*scores)[i].score_card_ += to_string ("E%.2f", demerit);
987 while (flip (&d) != LEFT);
992 score_slopes (Grob *me, Grob *common[],
993 Slur_score_parameters *score_param,
994 Drul_array<Bound_info> extremes,
995 Drul_array<Offset> base_attach,
996 Array<Slur_score> * scores)
1001 Drul_array<Real> ys;
1005 if (extremes[d].slur_head_)
1006 ys[d] = extremes[d].slur_head_->relative_coordinate (common[Y_AXIS],
1009 ys[d] = extremes[d].neighbor_y_;
1011 while (flip (&d) != LEFT);
1014 = (extremes[LEFT].stem_ && Stem::get_beam (extremes[LEFT].stem_))
1015 || (extremes[RIGHT].stem_ && Stem::get_beam (extremes[RIGHT].stem_));
1017 Real dy = ys[RIGHT] - ys[LEFT];
1018 for (int i = 0; i < scores->size (); i++)
1020 Offset slur_dz = (*scores)[i].attachment_[RIGHT]
1021 - (*scores)[i].attachment_[LEFT];
1022 Real slur_dy = slur_dz[Y_AXIS];
1025 demerit += ((fabs (slur_dy / slur_dz[X_AXIS])
1026 - score_param->MAX_SLOPE) >? 0)
1027 * score_param->MAX_SLOPE_FACTOR;
1029 /* 0.2: account for staffline offset. */
1030 Real max_dy = (fabs (dy) + 0.2);
1034 demerit += score_param->STEEPER_SLOPE_FACTOR
1035 * ((fabs (slur_dy) -max_dy) >? 0);
1037 demerit += ((fabs (slur_dy/slur_dz[X_AXIS])
1038 - score_param->MAX_SLOPE) >? 0)
1039 * score_param->MAX_SLOPE_FACTOR;
1042 && sign (slur_dy) != 0)
1043 demerit += score_param->NON_HORIZONTAL_PENALTY;
1047 && sign (slur_dy) != sign (dy))
1048 demerit += has_beams
1049 ? score_param->SAME_SLOPE_PENALTY / 10
1050 : score_param->SAME_SLOPE_PENALTY;
1052 #if DEBUG_SLUR_QUANTING
1053 (*scores)[i].score_card_ += to_string ("S%.2f", d);
1055 (*scores)[i].score_ += demerit;