From: Han-Wen Nienhuys Date: Sun, 18 Jul 2004 21:15:24 +0000 (+0000) Subject: * lily/accidental-engraver.cc (process_acknowledged_grobs): X-Git-Tag: release/2.3.7~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b0c32ac16816f585d10199f8de80e15bd7243487;p=lilypond.git * lily/accidental-engraver.cc (process_acknowledged_grobs): make accidental appear to come from note head engraver. * lily/slur-quanting.cc: new file. (score_extra_encompass): new function. Avoid scripts and accidentals --- diff --git a/ChangeLog b/ChangeLog index 75c3259108..7b7efdb143 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-07-18 Han-Wen Nienhuys + + * lily/accidental-engraver.cc (process_acknowledged_grobs): + make accidental appear to come from note head engraver. + + * lily/slur-quanting.cc: new file. + (score_extra_encompass): new function. Avoid scripts and + accidentals + 2004-07-18 Jan Nieuwenhuizen * lily/include/lily-guile.hh: Remove guile-1.4 compatibility. diff --git a/Documentation/topdocs/NEWS.texi b/Documentation/topdocs/NEWS.texi index 032d8adb6f..a32e0884de 100644 --- a/Documentation/topdocs/NEWS.texi +++ b/Documentation/topdocs/NEWS.texi @@ -8,6 +8,14 @@ @itemize @bullet +@item Slur formatting has been rewritten. The new slur code +works similar to the Beam formatter: scores are assigned for all +esthetic components of a slur. A large number of combinations for +begin and end points is then tried out. They will now also take into +account collisions with staff lines, scripts (like staccato and +accent) and accidentals. + + @item In the LilyPond emacs mode, the @code{|} will now display the current beat within the measure. diff --git a/input/regression/new-slur.ly b/input/regression/new-slur.ly index bb9367eb9a..bb269d732b 100644 --- a/input/regression/new-slur.ly +++ b/input/regression/new-slur.ly @@ -40,6 +40,14 @@ c,^( c'' c) c,,^( c'') c,,^( c') + \once \override Script #'padding = #1.2 + b-.8( b-. + \once \override Script #'padding = #1.2 + + b-.) + b-.( b-. + b-.) + s4 | b='2( a4) s4 | b='4.( c8) s2 | << c=''1_( diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc index 31e0998c9e..d718c03208 100644 --- a/lily/accidental-engraver.cc +++ b/lily/accidental-engraver.cc @@ -29,6 +29,7 @@ public: Music *melodic_; Grob *accidental_; Context *origin_; + Engraver *origin_trans_; Grob *head_; bool tied_; @@ -317,7 +318,7 @@ Accidental_engraver::process_acknowledged_grobs () Accidental from the respective Voice. */ Grob *a - = make_item_from_properties (origin->implementation (), + = make_item_from_properties (accidentals_[i].origin_trans_, ly_symbol2scm ("Accidental"), note->self_scm ()); a->set_parent (support, Y_AXIS); @@ -455,6 +456,7 @@ Accidental_engraver::acknowledge_grob (Grob_info info) Accidental_entry entry ; entry.head_ = info.grob_; + entry.origin_trans_ = dynamic_cast (info.origin_trans_); entry.origin_ = info.origin_trans_->context (); entry.melodic_ = note; diff --git a/lily/include/accidental-interface.hh b/lily/include/accidental-interface.hh index b0cb49b5a5..f3b2221fd1 100644 --- a/lily/include/accidental-interface.hh +++ b/lily/include/accidental-interface.hh @@ -10,7 +10,10 @@ source file of the GNU LilyPond music typesetter #ifndef ACCIDENTAL_INTERFACE_HH #define ACCIDENTAL_INTERFACE_HH -#include "grob.hh" +#include "box.hh" +#include "lily-guile.hh" +#include "lily-proto.hh" + class Accidental_interface { diff --git a/lily/new-slur.cc b/lily/new-slur.cc index 3ee7f8aec1..53a004a16d 100644 --- a/lily/new-slur.cc +++ b/lily/new-slur.cc @@ -124,8 +124,6 @@ void New_slur::add_column (Grob*me, Grob*n) { Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-columns"), n); - me->add_dependency (n); - add_bound_item (dynamic_cast (me), dynamic_cast (n)); } @@ -134,12 +132,9 @@ void New_slur::add_extra_encompass (Grob*me, Grob*n) { Pointer_group_interface::add_grob (me, ly_symbol2scm ("encompass-objects"), n); - me->add_dependency (n); - - add_bound_item (dynamic_cast (me), dynamic_cast (n)); } ADD_INTERFACE (New_slur, "new-slur-interface", "A slur", - "extra-encompass control-points dashed details direction height-limit note-columns ratio thickness"); + "encompass-objects control-points dashed details direction height-limit note-columns ratio thickness"); diff --git a/lily/slur-engraver.cc b/lily/slur-engraver.cc index 4164777ea2..7d7abf2440 100644 --- a/lily/slur-engraver.cc +++ b/lily/slur-engraver.cc @@ -105,7 +105,7 @@ Slur_engraver::acknowledge_grob (Grob_info info) else { for (int i = 0; i < slur_stack_.size (); i++) - New_slur::add_extra_encompass (end_slurs_[i], e); + New_slur::add_extra_encompass (slur_stack_[i], e); for (int i = 0; i < end_slurs_.size (); i++) New_slur::add_extra_encompass (end_slurs_[i], e); } @@ -185,9 +185,9 @@ Slur_engraver::stop_translation_timestep () ENTER_DESCRIPTION (Slur_engraver, -/* descr */ "Build slurs from Slur_evs", +/* descr */ "Build slurs grobs from slur events", /* creats*/ "Slur", /* accepts */ "slur-event", -/* acks */ "note-column-interface accidental-interface script-interface", +/* acks */ "note-column-interface accidental-interface fingering-interface script-interface", /* reads */ "slurMelismaBusy", /* write */ ""); diff --git a/lily/slur-quanting.cc b/lily/slur-quanting.cc index 8748218a1f..ba4c56b8e5 100644 --- a/lily/slur-quanting.cc +++ b/lily/slur-quanting.cc @@ -10,6 +10,8 @@ #include +#include "pitch.hh" +#include "accidental-interface.hh" #include "directional-element-interface.hh" #include "group-interface.hh" #include "lily-guile.hh" @@ -24,10 +26,6 @@ #include "warn.hh" #include "beam.hh" - - -#define DEBUG_SLUR_QUANTING 1 - struct Slur_score { Drul_array attachment_; @@ -45,7 +43,9 @@ struct Slur_score }; /* - TODO: put in details property. + TODO: put in details property., + + use lowercase. */ struct Slur_score_parameters { @@ -60,6 +60,8 @@ struct Slur_score_parameters Real HEAD_STRICT_FREE_SPACE; Real MAX_SLOPE; Real MAX_SLOPE_FACTOR; + Real EXTRA_OBJECT_COLLISION; + Real ACCIDENTAL_COLLISION; Real FREE_HEAD_DISTANCE; Slur_score_parameters (); }; @@ -113,6 +115,13 @@ struct Bound_info + +static void +score_extra_encompass (Grob *me, Grob *common[], + Slur_score_parameters *score_param, + Drul_array , + Drul_array , + Array * scores); static void score_slopes (Grob *me, Grob *common[], Slur_score_parameters *score_param, Drul_array, @@ -172,6 +181,8 @@ init_score_param (Slur_score_parameters *score_param) score_param->MAX_SLOPE = 1.1; score_param->MAX_SLOPE_FACTOR = 10; score_param->FREE_HEAD_DISTANCE = 0.3; + score_param->EXTRA_OBJECT_COLLISION = 8; + score_param->ACCIDENTAL_COLLISION = 3; } Slur_score_parameters::Slur_score_parameters() @@ -386,15 +397,23 @@ set_end_points (Grob *me) } SCM eltlist = me->get_property ("note-columns"); - Grob *common[] = {common_refpoint_of_list (eltlist, me, X_AXIS), - common_refpoint_of_list (eltlist, me, Y_AXIS)}; - + + SCM extra_list = me->get_property ("encompass-objects"); Spanner *sp = dynamic_cast (me); - common[X_AXIS] = common[X_AXIS]->common_refpoint (sp->get_bound (RIGHT), - X_AXIS); + + Grob *common[] = {0,0}; + for (int i = X_AXIS; i < NO_AXES; i++) + { + Axis a = (Axis)i; + common[a] = common_refpoint_of_list (eltlist, me, a); + common[a] = common_refpoint_of_list (extra_list, common[a], a); + } + + common[X_AXIS] = common[X_AXIS]->common_refpoint (sp->get_bound (RIGHT),X_AXIS); common[X_AXIS] = common[X_AXIS]->common_refpoint (sp->get_bound (LEFT), X_AXIS); + Drul_array extremes = get_bound_info (sp, common); Drul_array base_attachment = get_base_attachments (sp, common, extremes); @@ -408,6 +427,7 @@ set_end_points (Grob *me) score_edges (me, common, ¶ms,extremes, base_attachment, &scores); score_slopes (me, common, ¶ms,extremes, base_attachment, &scores); score_encompass (me, common, ¶ms,extremes, base_attachment, &scores); + score_extra_encompass (me, common, ¶ms,extremes, base_attachment, &scores); Real opt = 1e6; int opt_idx = 0; @@ -809,6 +829,98 @@ score_encompass (Grob *me, Grob *common[], } } + + +void +score_extra_encompass (Grob *me, Grob *common[], + Slur_score_parameters *score_param, + Drul_array , + Drul_array , + Array * scores) +{ + Link_array encompasses + = Pointer_group_interface__extract_grobs (me, (Grob *)0, "encompass-objects"); + Direction dir = get_grob_direction (me); + Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); + Real thick = robust_scm2double (me->get_property ("thickness"), 1.0) * lt; + + + Array xs; + Array yexts; + for (int i = 0; i < encompasses.size(); i++) + { + Grob *g = encompasses [i]; + Interval xe = g->extent (common[X_AXIS], X_AXIS); + Interval ye = g->extent (common[Y_AXIS], Y_AXIS); + + Real xp = 0.0; + + if (Accidental_interface::has_interface (g)) + { + /* + C&P accidental.cc + */ + bool parens = false; + if (to_boolean (g->get_property ("cautionary"))) + { + SCM cstyle = g->get_property ("cautionary-style"); + parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses")); + + } + + SCM accs = g->get_property ("accidentals"); + SCM scm_style = g->get_property ("style"); + if (!ly_c_symbol_p (scm_style) + && !parens + && scm_ilength (accs) == 1) + { + switch (ly_scm2int (ly_car (accs))) { + case FLAT: + case DOUBLE_FLAT: + xp = LEFT; + case SHARP: + xp = 0.5* dir; + case NATURAL: + xp = -dir; + } + } + + } + xs.push (xe.linear_combination (xp)); + ye.widen (.5 * thick); + yexts.push (ye); + } + + for (int i = 0; i < scores->size (); i++) + { + Bezier const &bez (scores->elem (i).curve_); + Real demerit = 0.0; + for (int j = 0; j < xs.size(); j++) + { + Real x = xs[j]; + if (!(x < scores->elem (i).attachment_[RIGHT][X_AXIS] + && x > scores->elem (i).attachment_[LEFT][X_AXIS])) + continue; + + Real y = bez.get_other_coordinate (X_AXIS, x); + + if (yexts[j].contains (y)) + { + if (Accidental_interface::has_interface (encompasses[j])) + demerit += score_param->ACCIDENTAL_COLLISION; + else + demerit += score_param->EXTRA_OBJECT_COLLISION; + } + } + +#if DEBUG_SLUR_QUANTING + (*scores)[i].score_card_ += to_string ("X%.2f", demerit); +#endif + (*scores)[i].score_ += demerit; + } +} + + void score_edges (Grob *me, Grob **, Slur_score_parameters * score_param, @@ -846,7 +958,7 @@ void score_slopes (Grob *me, Grob *common[], Slur_score_parameters*score_param, Drul_array extremes, - Drul_array base_attach, + Drul_array , Array * scores) { Drul_array ys; diff --git a/scm/safe-lily.scm b/scm/safe-lily.scm index 5a9cbe0348..590aefb465 100644 --- a/scm/safe-lily.scm +++ b/scm/safe-lily.scm @@ -245,9 +245,9 @@ Separating_group_spanner::set_spacing_rods Side_position_interface::aligned_on_support_refpoints Side_position_interface::aligned_side - Slur::after_line_breaking - Slur::height - Slur::print + New_slur::after_line_breaking + New_slur::height + New_slur::print Spacing_spanner::set_springs Span_bar::before_line_breaking Span_bar::get_bar_size