From d565cc424d8779550e6bed87be9bfb52449759ff Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 11 Jul 2004 02:45:52 +0000 Subject: [PATCH] (class New_slur): new file. Score based slur computations. --- input/test/new-slur.ly | 4 +++- lily/new-slur.cc | 45 +++++++++++++++++++++++++----------------- lily/stem.cc | 6 +++++- scm/define-grobs.scm | 6 +++--- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/input/test/new-slur.ly b/input/test/new-slur.ly index b408a8653e..de408d4317 100644 --- a/input/test/new-slur.ly +++ b/input/test/new-slur.ly @@ -12,5 +12,7 @@ _( f ) _( g ) _( \stemDown g \stemBoth ) - + c,^( c'' c) + c,,^( c'') + c,,^( c') } diff --git a/lily/new-slur.cc b/lily/new-slur.cc index 37f2412433..111fd1b463 100644 --- a/lily/new-slur.cc +++ b/lily/new-slur.cc @@ -10,6 +10,9 @@ #include +#include "font-interface.hh" +#include "text-item.hh" + #include "directional-element-interface.hh" #include "group-interface.hh" #include "group-interface.hh" @@ -141,7 +144,14 @@ New_slur::get_encompass_info (Grob *me, else ei.x_ = col->extent (common[X_AXIS], X_AXIS).center (); - ei.head_ = Stem::extremal_heads (stem)[Direction (stem_dir * dir)]->extent (common[Y_AXIS], Y_AXIS)[dir]; + Grob * h = Stem::extremal_heads (stem)[Direction (dir)]; + if (!h) + { + ei.head_ = ei.stem_ = col->relative_coordinate (common[Y_AXIS], Y_AXIS); + return ei; + } + + ei.head_ = h->extent (common[Y_AXIS], Y_AXIS)[dir]; if ((stem_dir == dir) && !stem->extent (stem, Y_AXIS).is_empty ()) @@ -224,7 +234,11 @@ New_slur::set_end_points (Grob *me) Link_array columns = Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns"); - + if (columns.is_empty ()) + { + me->suicide (); + return ; + } Real staff_space = Staff_symbol_referencer::staff_space ((Grob*)me); Drul_array extremes (columns[0], columns.top ()); Direction dir = get_grob_direction (me); @@ -245,8 +259,7 @@ New_slur::set_end_points (Grob *me) do { Grob *stem = Note_column::get_stem (extremes[d]); - Direction stemdir = get_grob_direction (stem); - Grob * h = Stem::extremal_heads (stem)[Direction (dir * stemdir)]; + Grob * h = Stem::extremal_heads (stem)[Direction (dir)]; staves[d] = Staff_symbol_referencer::get_staff_symbol (h); common[Y_AXIS] = common[Y_AXIS]->common_refpoint (staves[d], Y_AXIS); @@ -256,8 +269,7 @@ New_slur::set_end_points (Grob *me) { // c&p Grob *stem = Note_column::get_stem (extremes[d]); - Direction stemdir = get_grob_direction (stem); - Grob * h = Stem::extremal_heads (stem)[Direction (dir * stemdir)]; + Grob * h = Stem::extremal_heads (stem)[dir]; Real y = h->extent (common[Y_AXIS], Y_AXIS)[dir]; @@ -351,11 +363,11 @@ New_slur::set_end_points (Grob *me) me->set_property ("control-points", controls); #if DEBUG_SLUR_QUANTING - qscores[opt_idx].score_card_ += to_string ("i%d", best_idx); + scores[opt_idx].score_card_ += to_string ("i%d", opt_idx); - // debug quanting - me->set_property ("quant-score", - scm_makfrom0str (scores[opt_idx].score_card_.to_str0 ())); + // debug quanting + me->set_property ("quant-score", + scm_makfrom0str (scores[opt_idx].score_card_.to_str0 ())); #endif } @@ -404,8 +416,8 @@ New_slur::score_encompass (Grob * me, Grob *common[], Drul_array base_a demerit += - CLOSENESS_FACTOR * (dir * (y - (ext[dir] + dir * HEAD_FREE_SPACE)) base_a } while (flip (&d) != LEFT); #if DEBUG_SLUR_QUANTING - (*qscores)[i].score_card_ += to_string ("E%.2f",d); + (*scores)[i].score_card_ += to_string ("E%.2f", demerit); #endif (*scores)[i].score_ += demerit; @@ -437,8 +449,7 @@ New_slur::score_slopes (Grob * me, Grob *common[], Drul_array base_atta Direction d = LEFT; do { Grob *stem = Note_column::get_stem (extremes [d]); - Direction sd = get_grob_direction (stem); - ys[d] = Stem::extremal_heads (stem)[Direction (dir * sd)] + ys[d] = Stem::extremal_heads (stem)[Direction (dir)] ->relative_coordinate (common[Y_AXIS], Y_AXIS); } while (flip (&d) != LEFT); @@ -464,7 +475,7 @@ New_slur::score_slopes (Grob * me, Grob *common[], Drul_array base_atta demerit += SAME_SLOPE_PENALTY; #if DEBUG_SLUR_QUANTING - (*qscores)[i].score_card_ += to_string ("E%.2f",d); + (*scores)[i].score_card_ += to_string ("S%.2f",d); #endif (*scores)[i].score_ += demerit; } @@ -551,8 +562,6 @@ New_slur::print (SCM smob) String str; SCM properties = Font_interface::text_font_alist_chain (me); - Direction stem_dir = stems.size() ? to_dir (stems[0]->get_property ("direction")) : UP; - Stencil tm = *unsmob_stencil (Text_item::interpret_markup (me->get_paper ()->self_scm (), properties, quant_score)); a.add_at_edge (Y_AXIS, get_grob_direction (me), tm, 1.0, 0); diff --git a/lily/stem.cc b/lily/stem.cc index c7914a0540..1d723e72b2 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -154,7 +154,11 @@ Stem::last_head (Grob *me) return 0; } -/* START is part where stem reaches `last' head. */ +/* START is part where stem reaches `last' head. + +This function returns a drul with (bottom-head, top-head). + +*/ Drul_array Stem::extremal_heads (Grob *me) { diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index a4c431b8fe..edbb682aa2 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -828,15 +828,15 @@ (Slur . ( - (print-function . ,Slur::print) + (print-function . ,New_slur::print) (thickness . 1.2) (spacing-procedure . ,Spanner::set_spacing_rods) (minimum-length . 1.5) - (after-line-breaking-callback . ,Slur::after_line_breaking) + (after-line-breaking-callback . ,New_slur::after_line_breaking) (extremity-function . ,calc-slur-extremity) (extremity-offset-alist . ,default-slur-extremity-offset-alist) (de-uglify-parameters . (1.5 0.8 -2.0)) - (Y-extent-callback . ,Slur::height) + (Y-extent-callback . ,#f) ; Slur::height (height-limit . 2.0) (ratio . 0.333) (beautiful . 0.5) -- 2.39.5