X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fslur.cc;h=8439b6a35c0a70296a79e44a7f50ae710b45dfb2;hb=e7d84e6728ecfdf74d8f214486a29c2aca199819;hp=bc8fa4b5a7212a2413195812959bcf96dc9c9bf6;hpb=91629326e2c28dab86952c2abbe786978b7c1e92;p=lilypond.git diff --git a/lily/slur.cc b/lily/slur.cc index bc8fa4b5a7..8439b6a35c 100644 --- a/lily/slur.cc +++ b/lily/slur.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1996, 1997--1999 Han-Wen Nienhuys + (c) 1996--2000 Han-Wen Nienhuys Jan Nieuwenhuizen */ @@ -13,8 +13,9 @@ * broken slur should have uniform trend */ +#include "directional-element-interface.hh" +#include "group-interface.hh" #include "slur.hh" -#include "scalar.hh" #include "lookup.hh" #include "paper-def.hh" #include "note-column.hh" @@ -23,34 +24,259 @@ #include "molecule.hh" #include "debug.hh" #include "box.hh" -#include "bezier.hh" -#include "encompass-info.hh" +#include "bezier-bow.hh" #include "main.hh" +#include "cross-staff.hh" +#include "group-interface.hh" +#include "staff-symbol-referencer.hh" + +class Slur_bezier_bow : public Bezier_bow +{ +public: + Slur_bezier_bow (Array encompass, Direction dir); + Array area_x_gradients_array (Real area); + void blow_fit (); + Real enclosed_area_f () const; + Real fit_factor () const; + void minimise_enclosed_area (Paper_def* paper_l, Real default_height); +}; + +Slur_bezier_bow::Slur_bezier_bow (Array encompass, Direction dir) + : Bezier_bow (encompass, dir) +{ +} + +void +Slur_bezier_bow::blow_fit () +{ + Real len = curve_.control_[3][X_AXIS]; + Real h = curve_.control_[1][Y_AXIS] * fit_factor () / len; + curve_.control_[1][Y_AXIS] = h * len; + curve_.control_[2][Y_AXIS] = h * len; + curve_.assert_sanity (); +} + + +Real +Slur_bezier_bow::enclosed_area_f () const +{ + Real a = 0; + for (int i=0; i < encompass_.size (); i++) + { + Interval x; + Interval y; + if (i == 0) + { + x = Interval (0, encompass_[1][X_AXIS] / 2); + y = Interval (0, + curve_.get_other_coordinate (X_AXIS, + encompass_[1][X_AXIS] + / 2)); + } + else if (i == encompass_.size () - 1) + { + x = Interval ((encompass_[i-1][X_AXIS] + encompass_[i][X_AXIS])/2, + encompass_[i][X_AXIS]); + y = Interval (0, + (curve_.get_other_coordinate (X_AXIS, + (x[MIN] + x[MAX]) / 2))); + } + else + { + x = Interval ((encompass_[i-1][X_AXIS] + encompass_[i][X_AXIS]) / 2, + (encompass_[i][X_AXIS] + encompass_[i+1][X_AXIS]) / 2); + y = Interval (encompass_[i][Y_AXIS], + (curve_.get_other_coordinate (X_AXIS, x[MIN]) + + curve_.get_other_coordinate (X_AXIS, + (x[MIN] + x[MAX]) / 2) + + curve_.get_other_coordinate (X_AXIS, x[MAX])) / 3); + } + + Real da = x.length () * y.length (); + a += da; + } + return a; +} + +Array +Slur_bezier_bow::area_x_gradients_array (Real area) +{ + Real len = curve_.control_[3][X_AXIS]; + Real grow = len / 10.0; + Array da (2); + for (int i=0; i < 2; i++) + { + Real r = curve_.control_[i+1][X_AXIS]; + curve_.control_[i+1][X_AXIS] += grow; + da[i] = (enclosed_area_f () - area) / grow; + curve_.control_[i+1][X_AXIS] = r; + } + return da; +} + +void +Slur_bezier_bow::minimise_enclosed_area (Paper_def* paper_l, + Real default_height) +{ + Real length = curve_.control_[3][X_AXIS]; + Real sb = paper_l->get_var ("slur_beautiful"); + Real beautiful = length * default_height * sb; + + DEBUG_OUT << to_str ("Beautiful: %f\n", beautiful); + DEBUG_OUT << to_str ("Length: %f\n", length); + DEBUG_OUT << to_str ("D-height: %f\n", default_height); + DEBUG_OUT << to_str ("FitFac: %f\n", fit_factor ()); + + if (fit_factor () > 1.0) + blow_fit (); + + Real pct_c0 = paper_l->get_var ("bezier_pct_c0"); + Real pct_c3 = paper_l->get_var ("bezier_pct_c3"); + Real pct_in_max = paper_l->get_var ("bezier_pct_in_max"); + Real pct_out_max = paper_l->get_var ("bezier_pct_out_max"); + Real steps = paper_l->get_var ("bezier_area_steps"); + + for (int i=0; i < steps; i++) + { + Real area = enclosed_area_f (); + if (!i) + DEBUG_OUT << to_str ("Init area: %f\n", area); + + if (area <= beautiful) + break; + + Array da = area_x_gradients_array (area); + + // urg + Real pct = pct_c0 + pct_c3 * length * length * length; + pct *= (steps - i) / steps; + if (da[0] > 0 || da[1] < 0) + pct = pct x1 && encompass_[i][X_AXIS] < x2) + { + Real y = curve_.get_other_coordinate (X_AXIS, encompass_[i][X_AXIS]); + if (y>0) + { + Real f = encompass_[i][Y_AXIS] / y; + factor = factor >? f; + } + } + } + + + return factor; +} + + + + + +/* + Slur +*/ + Slur::Slur () { + // URG + dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = 0.0; + dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0; + + set_elt_pointer ("note-columns", SCM_EOL); + set_elt_property ("control-points", SCM_EOL); } void Slur::add_column (Note_column*n) { - if (!n->head_l_arr_.size ()) - warning (_ ("Putting slur over rest. Ignoring")); + if (!gh_pair_p (n->get_elt_pointer ("note-heads"))) + warning (_ ("Putting slur over rest. Ignoring.")); else { - encompass_arr_.push (n); + Pointer_group_interface (this, "note-columns").add_element (n); add_dependency (n); } } +void +Slur::de_uglyfy (Slur_bezier_bow* bb, Real default_height) +{ + Real length = bb->curve_.control_[3][X_AXIS] ; + Real ff = bb->fit_factor (); + for (int i = 1; i < 3; i++) + { + Real ind = abs (bb->curve_.control_[(i-1)*3][X_AXIS] + - bb->curve_.control_[i][X_AXIS]) / length; + Real h = bb->curve_.control_[i][Y_AXIS] * ff / length; + + Real f = default_height / length; + Real c1 = paper_l ()->get_var ("bezier_control1"); + Real c2 = paper_l ()->get_var ("bezier_control2"); + Real c3 = paper_l ()->get_var ("bezier_control3"); + if (h > c1 * f) + { + h = c1 * f; + } + else if (h > c2 + c3 * ind) + { + h = c2 + c3 * ind; + } + + bb->curve_.control_[i][Y_AXIS] = h * length; + } + + bb->curve_.assert_sanity (); +} + Direction Slur::get_default_dir () const { + Link_array encompass_arr = + Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns"); + Direction d = DOWN; - for (int i=0; i < encompass_arr_.size (); i ++) + for (int i=0; i < encompass_arr.size (); i ++) { - if (encompass_arr_[i]->dir () < 0) + if (encompass_arr[i]->dir () < 0) { d = UP; break; @@ -62,42 +288,88 @@ Slur::get_default_dir () const void Slur::do_add_processing () { - set_bounds (LEFT, encompass_arr_[0]); - if (encompass_arr_.size () > 1) - set_bounds (RIGHT, encompass_arr_.top ()); -} + Link_array encompass_arr = + Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns"); -void -Slur::do_pre_processing () -{ - // don't set directions + if (encompass_arr.size ()) + { + set_bound (LEFT, encompass_arr[0]); + if (encompass_arr.size () > 1) + set_bound (RIGHT, encompass_arr.top ()); + } } -void -Slur::do_substitute_element_pointer (Score_element*o, Score_element*n) + + +Offset +Slur::encompass_offset (Note_column const* col) const { - int i; - while ((i = encompass_arr_.find_i (dynamic_cast (o))) >=0) + Offset o; + Stem* stem_l = col->stem_l (); + Direction dir = directional_element (this).get (); + + if (!stem_l) { - if (n) - encompass_arr_[i] = dynamic_cast (n); - else - encompass_arr_.del (i); + warning (_ ("Slur over rest?")); + o[X_AXIS] = col->relative_coordinate (0, X_AXIS); + o[Y_AXIS] = col->extent (Y_AXIS)[dir]; + return o; } + Direction stem_dir = directional_element (stem_l).get (); + o[X_AXIS] = stem_l->relative_coordinate (0, X_AXIS); + + /* + Simply set x to middle of notehead + */ + + o[X_AXIS] -= 0.5 * stem_dir * col->extent (X_AXIS).length (); + + if ((stem_dir == dir) + && !stem_l->extent (Y_AXIS).empty_b ()) + { + o[Y_AXIS] = stem_l->extent (Y_AXIS)[dir]; + } + else + { + o[Y_AXIS] = col->extent (Y_AXIS)[dir]; + } + + /* + leave a gap: slur mustn't touch head/stem + */ + o[Y_AXIS] += dir * paper_l ()->get_var ("slur_y_free"); + o[Y_AXIS] -= calc_interstaff_dist (stem_l, this); + return o; } -static int -Note_column_compare (Note_column *const&n1 , Note_column* const&n2) +void +Slur::after_line_breaking () { - return Item::left_right_compare (n1, n2); -} + set_extremities (); + set_control_points (); +} +/* + urg + FIXME + */ void -Slur::do_post_processing () +Slur::set_extremities () { - encompass_arr_.sort (Note_column_compare); - if (!dir_) - dir_ = get_default_dir (); + Link_array encompass_arr = + Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns"); + + if (!encompass_arr.size ()) + { + set_elt_property ("transparent", SCM_BOOL_T); + set_extent_callback (0, X_AXIS); + set_extent_callback (0, Y_AXIS); + return; + } + + if (!directional_element (this).get ()) + directional_element (this).set (get_default_dir ()); + /* Slur and tie placement [OSU] @@ -110,63 +382,68 @@ Slur::do_post_processing () y = length >= 5ss : y next interline - d * 0.25 ss */ - Real interline_f = paper_l ()->get_realvar (interline_scm_sym); - Real internote_f = interline_f / 2; + Real staff_space = paper_l ()->get_var ("interline"); + Real half_staff_space = staff_space / 2; Real x_gap_f = paper_l ()->get_var ("slur_x_gap"); Real y_gap_f = paper_l ()->get_var ("slur_y_gap"); Drul_array note_column_drul; - note_column_drul[LEFT] = encompass_arr_[0]; - note_column_drul[RIGHT] = encompass_arr_.top (); + note_column_drul[LEFT] = encompass_arr[0]; + note_column_drul[RIGHT] = encompass_arr.top (); bool fix_broken_b = false; + + Direction my_dir = directional_element (this).get (); + Direction d = LEFT; do { - dx_f_drul_[d] = dy_f_drul_[d] = 0; - if ((note_column_drul[d] == spanned_drul_[d]) - && note_column_drul[d]->head_l_arr_.size () - && (note_column_drul[d]->stem_l_)) + dx_f_drul_[d] = 0; + dy_f_drul_[d] = 0; + + if ((note_column_drul[d] == get_bound (d)) + && note_column_drul[d]->first_head () + && (note_column_drul[d]->stem_l ())) { - Stem* stem_l = note_column_drul[d]->stem_l_; + Stem* stem_l = note_column_drul[d]->stem_l (); /* side directly attached to note head; no beam getting in the way */ if ((stem_l->extent (Y_AXIS).empty_b () - || !((stem_l->dir_ == dir_) && (dir_ != d))) - && !((dir_ == stem_l->dir_) - && stem_l->beam_l_ && (stem_l->beams_i_drul_[-d] >= 1))) + || !((stem_l->get_direction () == my_dir) && (my_dir != d))) + && !((my_dir == stem_l->get_direction ()) + && stem_l->beam_l () && (stem_l->beam_count (-d) >= 1))) { - dx_f_drul_[d] = spanned_drul_[d]->extent (X_AXIS).length () / 2; + dx_f_drul_[d] = get_bound (d)->extent (X_AXIS).length () / 2; dx_f_drul_[d] -= d * x_gap_f; - if (stem_l->dir_ != dir_) + if (stem_l->get_direction () != my_dir) { - dy_f_drul_[d] = note_column_drul[d]->extent (Y_AXIS)[dir_]; + dy_f_drul_[d] = note_column_drul[d]->extent (Y_AXIS)[my_dir]; } else { dy_f_drul_[d] = stem_l->chord_start_f () - + dir_ * internote_f; + + my_dir * half_staff_space; } - dy_f_drul_[d] += dir_ * y_gap_f; + dy_f_drul_[d] += my_dir * y_gap_f; } /* side attached to (visible) stem */ else { - dx_f_drul_[d] = stem_l->hpos_f () - - spanned_drul_[d]->absolute_coordinate (X_AXIS); + dx_f_drul_[d] = stem_l->relative_coordinate (0, X_AXIS) + - get_bound (d)->relative_coordinate (0, X_AXIS); /* side attached to beamed stem */ - if (stem_l->beam_l_ && (stem_l->beams_i_drul_[-d] >= 1)) + if (stem_l->beam_l () && (stem_l->beam_count (-d) >= 1)) { - dy_f_drul_[d] = stem_l->extent (Y_AXIS)[dir_]; - dy_f_drul_[d] += dir_ * 2 * y_gap_f; + dy_f_drul_[d] = stem_l->extent (Y_AXIS)[my_dir]; + dy_f_drul_[d] += my_dir * 2 * y_gap_f; } /* side attached to notehead, with stem getting in the way @@ -176,8 +453,8 @@ Slur::do_post_processing () dx_f_drul_[d] -= d * x_gap_f; dy_f_drul_[d] = stem_l->chord_start_f () - + dir_ * internote_f; - dy_f_drul_[d] += dir_ * y_gap_f; + + my_dir * half_staff_space; + dy_f_drul_[d] += my_dir * y_gap_f; } } } @@ -186,11 +463,7 @@ Slur::do_post_processing () */ else { - /* - need break-align too. what about other spanners? - */ - if (d == LEFT) - dx_f_drul_[d] = spanned_drul_[LEFT]->extent (X_AXIS).length (); + dx_f_drul_[d] = get_broken_left_end_align (); /* broken: should get y from other piece, so that slur @@ -203,210 +476,68 @@ Slur::do_post_processing () } while (flip (&d) != LEFT); - int interstaff_i = 0; - for (int i = 0; i < encompass_arr_.size (); i++) + int cross_count = cross_staff_count (); + bool interstaff_b = (0 < cross_count) && (cross_count < encompass_arr.size ()); + + Drul_array info_drul; + Drul_array interstaff_interval; + + do { - Encompass_info info (encompass_arr_[i], dir_, this); - if (info.interstaff_f_) - { - interstaff_i++; - } + info_drul[d] = encompass_offset (encompass_arr.boundary (d, 0)); + interstaff_interval[d] = - calc_interstaff_dist (encompass_arr.boundary (d,0), + this); } - bool interstaff_b = interstaff_i && (interstaff_i < encompass_arr_.size ()); - - Drul_array info_drul; - info_drul[LEFT] = Encompass_info (encompass_arr_[0], dir_, this); - info_drul[RIGHT] = Encompass_info (encompass_arr_.top (), dir_, this); - Real interstaff_f = info_drul[RIGHT].interstaff_f_ - - info_drul[LEFT].interstaff_f_; + while (flip (&d) != LEFT); + + Real interstaff_f = interstaff_interval[RIGHT] - interstaff_interval[LEFT]; if (fix_broken_b) { - Direction d = (encompass_arr_.top () != spanned_drul_[RIGHT]) ? + Direction d = (encompass_arr.top () != get_bound (RIGHT)) ? RIGHT : LEFT; - dy_f_drul_[d] = info_drul[d].o_[Y_AXIS]; + dy_f_drul_[d] = info_drul[d][Y_AXIS]; if (!interstaff_b) { - dy_f_drul_[d] -= info_drul[d].interstaff_f_; - - if (interstaff_i) + dy_f_drul_[d] -= interstaff_interval[d]; + if (cross_count) // interstaff_i ? { - dy_f_drul_[LEFT] += info_drul[d].interstaff_f_; - dy_f_drul_[RIGHT] += info_drul[d].interstaff_f_; + dy_f_drul_[LEFT] += interstaff_interval[d]; + dy_f_drul_[RIGHT] += interstaff_interval[d]; } } } - - /* - Now we've got a fine slur - Catch and correct some ugly cases - */ - - Real height_damp_f; - Real slope_damp_f; - Real snap_f; - Real snap_max_dy_f; - - if (!interstaff_b) - { - height_damp_f = paper_l ()->get_var ("slur_height_damping"); - slope_damp_f = paper_l ()->get_var ("slur_slope_damping"); - snap_f = paper_l ()->get_var ("slur_snap_to_stem"); - snap_max_dy_f = paper_l ()->get_var ("slur_snap_max_slope_change"); - } - else - { - height_damp_f = paper_l ()->get_var ("slur_interstaff_height_damping"); - slope_damp_f = paper_l ()->get_var ("slur_interstaff_slope_damping"); - snap_f = paper_l ()->get_var ("slur_interstaff_snap_to_stem"); - snap_max_dy_f = paper_l ()->get_var ("slur_interstaff_snap_max_slope_change"); - } - if (!fix_broken_b) dy_f_drul_[RIGHT] += interstaff_f; +} - Real dy_f = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]; - if (!fix_broken_b) - dy_f -= interstaff_f; - Real dx_f = do_width ().length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]; - - /* - Avoid too steep slurs. - */ - Real slope_ratio_f = abs (dy_f / dx_f); - if (slope_ratio_f > slope_damp_f) - { - Direction d = (Direction)(- dir_ * (sign (dy_f))); - if (!d) - d = LEFT; - Real damp_f = (slope_ratio_f - slope_damp_f) * dx_f; - /* - must never change sign of dy - */ - damp_f = damp_f curve_xy_drul = curve_extent_drul (); - Real height_f = curve_xy_drul[Y].length (); - Real width_f = curve_xy_drul[X].length (); - - dy_f = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]; - if (!fix_broken_b) - dy_f -= interstaff_f; - Real height_ratio_f = abs (height_f / width_f); - if (height_ratio_f > height_damp_f) - { - Direction d = (Direction)(- dir_ * (sign (dy_f))); - if (!d) - d = LEFT; - /* take third step */ - Real damp_f = (height_ratio_f - height_damp_f) * width_f / 3; - /* - if y positions at about the same height, correct both ends - */ - if (abs (dy_f / dx_f ) < slope_damp_f) - { - dy_f_drul_[-d] += dir_ * damp_f; - dy_f_drul_[d] += dir_ * damp_f; - } - /* - don't change slope too much, would have been catched by slope damping - */ - else - { - damp_f = damp_f encompass_arr = + Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns"); - /* - If, after correcting, we're close to stem-end... - */ - Drul_array snapy_f_drul; - snapy_f_drul[LEFT] = snapy_f_drul[RIGHT] = 0; - Drul_array snapx_f_drul; - snapx_f_drul[LEFT] = snapx_f_drul[RIGHT] = 0; - Drul_array snapped_b_drul; - snapped_b_drul[LEFT] = snapped_b_drul[RIGHT] = false; - do - { - if ((note_column_drul[d] == spanned_drul_[d]) - && (note_column_drul[d]->stem_l_) - && (note_column_drul[d]->stem_l_->dir_ == dir_) - && (abs (note_column_drul[d]->stem_l_->extent (Y_AXIS)[dir_] - - dy_f_drul_[d] + (d == LEFT ? 0 : interstaff_f)) - <= snap_f)) - { - /* - prepare to attach to stem-end - */ - Stem* stem_l = note_column_drul[d]->stem_l_; - snapx_f_drul[d] = stem_l->hpos_f () - - spanned_drul_[d]->absolute_coordinate (X_AXIS); - snapy_f_drul[d] = stem_l->extent (Y_AXIS)[dir_]; - snapy_f_drul[d] += info_drul[d].interstaff_f_; - snapy_f_drul[d] += dir_ * 2 * y_gap_f; - snapped_b_drul[d] = true; - } - } - while (flip (&d) != LEFT); + int k=0; - /* - only use snapped positions if sign (dy) will not change - and dy doesn't change too much - */ - if (!fix_broken_b) - dy_f += interstaff_f; - if (snapped_b_drul[LEFT] && snapped_b_drul[RIGHT] - && ((sign (snapy_f_drul[RIGHT] - snapy_f_drul[LEFT]) == sign (dy_f))) - && (!dy_f || (abs (snapy_f_drul[RIGHT] - snapy_f_drul[LEFT] - dy_f) - < abs (dy_f * snap_max_dy_f)))) - { - do - { - dy_f_drul_[d] = snapy_f_drul[d]; - dx_f_drul_[d] = snapx_f_drul[d]; - } - while (flip (&d) != LEFT); - - } - else if (snapped_b_drul[LEFT] - && ((sign (dy_f_drul_[RIGHT] - snapy_f_drul[LEFT]) == sign (dy_f))) - && (!dy_f || (abs (dy_f_drul_[RIGHT] - snapy_f_drul[LEFT] - dy_f) - < abs (dy_f * snap_max_dy_f)))) - { - Direction d = LEFT; - dy_f_drul_[d] = snapy_f_drul[d]; - dx_f_drul_[d] = snapx_f_drul[d]; - } - else if (snapped_b_drul[RIGHT] - && ((sign (snapy_f_drul[RIGHT] - dy_f_drul_[LEFT]) == sign (dy_f))) - && (!dy_f || (abs (snapy_f_drul[RIGHT] - dy_f_drul_[LEFT] - dy_f) - < abs (dy_f * snap_max_dy_f)))) + for (int i = 0; i < encompass_arr.size (); i++) { - Direction d = RIGHT; - dy_f_drul_[d] = snapy_f_drul[d]; - dx_f_drul_[d] = snapx_f_drul[d]; + if (calc_interstaff_dist (encompass_arr[i], this)) + k++; } + return k; } + Array Slur::get_encompass_offset_arr () const { + Link_array encompass_arr = + Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns"); + Array offset_arr; + #if 0 /* check non-disturbed slur @@ -416,50 +547,43 @@ Slur::get_encompass_offset_arr () const offset_arr.push (Offset (0, dy_f_drul_[RIGHT])); return offset_arr; #endif - - int interstaff_i = 0; - for (int i = 0; i < encompass_arr_.size (); i++) - { - Encompass_info info (encompass_arr_[i], dir_, this); - if (info.interstaff_f_) - { - interstaff_i++; - } - } - bool interstaff_b = interstaff_i && (interstaff_i < encompass_arr_.size ()); - Offset origin (absolute_coordinate (X_AXIS), 0); + Offset origin (relative_coordinate (0, X_AXIS), 0); int first = 1; - int last = encompass_arr_.size () - 2; + int last = encompass_arr.size () - 2; offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT])); + /* left is broken edge */ - if (encompass_arr_[0] != spanned_drul_[LEFT]) + + int cross_count = cross_staff_count (); + bool cross_b = cross_count && cross_count < encompass_arr.size (); + if (encompass_arr[0] != get_bound (LEFT)) { first--; - Encompass_info left_info (encompass_arr_[0], dir_, this); - if (interstaff_b) - offset_arr[0][Y_AXIS] += left_info.interstaff_f_; + Real is = calc_interstaff_dist (encompass_arr[0], this); + if (cross_b) + offset_arr[0][Y_AXIS] += is; } /* right is broken edge */ - if (encompass_arr_.top () != spanned_drul_[RIGHT]) + if (encompass_arr.top () != get_bound (RIGHT)) { last++; } for (int i = first; i <= last; i++) { - Encompass_info info (encompass_arr_[i], dir_, this); - offset_arr.push (info.o_ - origin); + Offset o (encompass_offset (encompass_arr[i])); + offset_arr.push (o - origin); } - offset_arr.push (Offset (do_width ().length () + dx_f_drul_[RIGHT], + offset_arr.push (Offset (spanner_length ()+ dx_f_drul_[RIGHT], dy_f_drul_[RIGHT])); return offset_arr; @@ -471,10 +595,117 @@ Slur::get_rods () const { Array a; Rod r; - r.item_l_drul_ = spanned_drul_; + + r.item_l_drul_[LEFT] = get_bound (LEFT); + r.item_l_drul_[RIGHT] = get_bound (RIGHT); r.distance_f_ = paper_l ()->get_var ("slur_x_minimum"); a.push (r); return a; } + + +/* + Ugh should have dash-length + dash-period + */ +Molecule +Slur::do_brew_molecule () const +{ + Real thick = paper_l ()->get_var ("slur_thickness"); + Bezier one = get_curve (); + + Molecule a; + SCM d = get_elt_property ("dashed"); + if (gh_number_p (d)) + a = lookup_l ()->dashed_slur (one, thick, thick * gh_scm2double (d)); + else + a = lookup_l ()->slur (one, directional_element (this).get () * thick, thick); + + return a; +} + +void +Slur::set_control_points () +{ + Slur_bezier_bow bb (get_encompass_offset_arr (), + directional_element (this).get ()); + + Real staff_space = Staff_symbol_referencer_interface (this).staff_space (); + Real h_inf = paper_l ()->get_var ("slur_height_limit_factor") * staff_space; + Real r_0 = paper_l ()->get_var ("slur_ratio"); + + bb.set_default_bezier (h_inf, r_0); + + if (bb.fit_factor () > 1.0) + { + Real length = bb.curve_.control_[3][X_AXIS]; + Real default_height = bb.get_default_height (h_inf, r_0, length); + bb.minimise_enclosed_area (paper_l(), default_height); + + Real bff = paper_l ()->get_var ("slur_force_blowfit"); + bb.curve_.control_[1][Y_AXIS] *= bff; + bb.curve_.control_[2][Y_AXIS] *= bff; + bb.blow_fit (); + + Real sb = paper_l ()->get_var ("slur_beautiful"); + Real beautiful = length * default_height * sb; + Real area = bb.enclosed_area_f (); + + /* + Slurs that fit beautifully are not ugly + */ + if (area > beautiful) + de_uglyfy (&bb, default_height); + } + + Bezier b = bb.get_bezier (); + + + SCM controls = SCM_EOL; + for (int i= 4; i--;) + controls = gh_cons ( ly_offset2scm (b.control_[i]), controls); + + set_elt_property ("control-points", controls); +} + + +Bezier +Slur::get_curve () const +{ + Bezier b; + int i = 0; + + if (!directional_element (this).get ()) + ((Slur*)this)->set_extremities (); + + if (!gh_pair_p (get_elt_property ("control-points"))) + ((Slur*)this)->set_control_points (); + + + for (SCM s= get_elt_property ("control-points"); s != SCM_EOL; s = gh_cdr (s)) + { + b.control_[i] = ly_scm2offset (gh_car (s)); + i++; + } + + Array enc (get_encompass_offset_arr ()); + Direction dir = directional_element (this).get (); + + Real x1 = enc[0][X_AXIS]; + Real x2 = enc.top ()[X_AXIS]; + + Real off = 0.0; + for (int i=1; i < enc.size ()-1; i++) + { + Real x = enc[i][X_AXIS]; + if (x > x1 && x ? dir * (enc[i][Y_AXIS] - y); + } + } + b.translate (Offset (0, dir * off)); + return b; +} +