source file of the GNU LilyPond music typesetter
- (c) 1996, 1997--1999, 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1996--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
*/
/*
[TODO]
- * URG: share code with tie
- * begin and end should be treated as a Script.
- * damping
- * slur from notehead to stemend: c''()b''
+ * begin and end should be treated as a/acknowledge Scripts.
+ * 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"
#include "stem.hh"
-#include "p-col.hh"
+#include "paper-column.hh"
#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"
-Slur::Slur ()
+
+class Slur_bezier_bow : public Bezier_bow
+{
+public:
+ Slur_bezier_bow (Array<Offset> encompass, Direction dir);
+ Array<Real> 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<Offset> encompass, Direction dir)
+ : Bezier_bow (encompass, dir)
{
}
void
-Slur::add_column (Note_column*n)
+Slur_bezier_bow::blow_fit ()
{
- if (!n->head_l_arr_.size ())
- warning (_ ("Putting slur over rest."));
- encompass_arr_.push (n);
- // n->stem_l_->slur_l_ = this;
- add_dependency (n);
+ 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 ();
}
-void
-Slur::set_default_dir ()
+
+Real
+Slur_bezier_bow::enclosed_area_f () const
{
- dir_ = DOWN;
- for (int i=0; i < encompass_arr_.size (); i ++)
+ Real a = 0;
+ for (int i=0; i < encompass_.size (); i++)
{
- if (encompass_arr_[i]->dir_ < 0)
+ Interval x;
+ Interval y;
+ if (i == 0)
{
- dir_ = UP;
- break;
+ 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;
}
-void
-Slur::do_add_processing ()
+Array<Real>
+Slur_bezier_bow::area_x_gradients_array (Real area)
{
- set_bounds (LEFT, encompass_arr_[0]);
- if (encompass_arr_.size () > 1)
- set_bounds (RIGHT, encompass_arr_.top ());
+ Real len = curve_.control_[3][X_AXIS];
+ Real grow = len / 10.0;
+ Array<Real> 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::do_pre_processing ()
+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<Real> 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 <? pct_out_max;
+ else
+ pct = pct <? pct_in_max;
+
+ Real u = (abs (curve_.control_[1][X_AXIS] / da[0])
+ <? abs ((curve_.control_[3][X_AXIS]
+ - curve_.control_[2][X_AXIS]) / da[1]));
+
+ DEBUG_OUT << to_str ("pct: %f\n", pct);
+ DEBUG_OUT << to_str ("u: %f\n", u);
+
+ DEBUG_OUT << to_str ("da: (%f, %f)\n", da[0], da[1]);
+ DEBUG_OUT << to_str ("da*u: (%f, %f)\n", da[0]*u*pct, da[1]*u*pct);
+ DEBUG_OUT << to_str ("cx: (%f, %f)\n", curve_.control_[1][X_AXIS],
+ curve_.control_[2][X_AXIS]);
+
+ curve_.control_[1][X_AXIS] -= da[0] * u * pct;
+ curve_.control_[2][X_AXIS] -= da[1] * u * pct;
+ }
+
+ Real area = enclosed_area_f ();
+ DEBUG_OUT << to_str ("Exarea: %f\n", area);
+}
+
+
+
+/*
+ max ( encompass.y / curve.y )
+
+ */
+Real
+Slur_bezier_bow::fit_factor () const
+{
+ Real x1 = encompass_[0][X_AXIS];
+ Real x2 = encompass_.top ()[X_AXIS];
+
+ Real factor = 0.0;
+ for (int i=1; i < encompass_.size ()-1; i++)
+ {
+ if (encompass_[i][X_AXIS] > 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 ()
{
- // don't set directions
+ // 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::do_substitute_element_pointer (Score_element*o, Score_element*n)
+Slur::add_column (Note_column*n)
{
- int i;
- while ((i = encompass_arr_.find_i (dynamic_cast<Note_column *> (o))) >=0)
+ if (!gh_pair_p (n->get_elt_pointer ("note-heads")))
+ warning (_ ("Putting slur over rest. Ignoring."));
+ else
{
- if (n)
- encompass_arr_[i] = dynamic_cast<Note_column *> (n);
- else
- encompass_arr_.del (i);
+ Pointer_group_interface (this, "note-columns").add_element (n);
+ add_dependency (n);
}
}
-static int
-Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
+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
{
- return Item::left_right_compare (n1, n2);
+ Link_array<Note_column> 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 ++)
+ {
+ if (encompass_arr[i]->dir () < 0)
+ {
+ d = UP;
+ break;
+ }
+ }
+ return d;
}
-static bool
-broken_edge_b (Slur*s, Drul_array<Note_column*>& extrema, Direction dir)
+void
+Slur::do_add_processing ()
{
- return extrema[dir] != s->spanned_drul_[dir];
+ Link_array<Note_column> encompass_arr =
+ Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+
+ if (encompass_arr.size ())
+ {
+ set_bound (LEFT, encompass_arr[0]);
+ if (encompass_arr.size () > 1)
+ set_bound (RIGHT, encompass_arr.top ());
+ }
}
-static bool
-normal_edge_b (Slur*s, Drul_array<Note_column*>& extrema, Direction dir)
+
+
+Offset
+Slur::encompass_offset (Note_column const* col) const
{
- Note_column *n = extrema[dir];
- return !broken_edge_b (s, extrema, dir)
- && n->stem_l_
- && n->stem_l_->get_elt_property (transparent_scm_sym) == SCM_BOOL_F
- && n->head_l_arr_.size ();
+ Offset o;
+ Stem* stem_l = col->stem_l ();
+ Direction dir = directional_element (this).get ();
+
+ if (!stem_l)
+ {
+ 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;
}
void
-Slur::do_post_processing ()
+Slur::after_line_breaking ()
{
- encompass_arr_.sort (Note_column_compare);
- if (!dir_)
- set_default_dir ();
+ set_extremities ();
+ set_control_points ();
+}
+
+/*
+ urg
+ FIXME
+ */
+void
+Slur::set_extremities ()
+{
+ Link_array<Note_column> 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 ());
- Real interline_f = paper_l ()->get_realvar (interline_scm_sym);
- Real internote_f = interline_f / 2;
- // URG
- Real notewidth_f = paper_l ()->note_width () * 0.8;
/*
- [OSU]: slur and tie placement
+ Slur and tie placement [OSU]
- slurs:
- * x = centre of head (upside-down: inner raakpunt stem) - d * gap
+ Slurs:
+ * x = centre of head - d * x_gap_f
- * y = length < 5ss : horizontal raakpunt + d * 0.25 ss
+ TODO:
+ * y = length < 5ss : horizontal tangent + d * 0.25 ss
y = length >= 5ss : y next interline - d * 0.25 ss
- --> height <= 5 length ?? we use <= 3 length, now...
*/
-
- Real gap_f = paper_l ()->get_var ("slur_x_gap");
- Drul_array<Note_column*> extrema;
- extrema[LEFT] = encompass_arr_[0];
- extrema[RIGHT] = encompass_arr_.top ();
+ Real staff_space = paper_l ()->get_var ("interline");
+ Real half_staff_space = staff_space / 2;
- Direction d=LEFT;
-
+ 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*> note_column_drul;
+ 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
{
- if (broken_edge_b (this, extrema, d))
+ 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 ()))
{
- // ugh -- check if needed
- dx_f_drul_[d] = -d
- *(spanned_drul_[d]->extent (X_AXIS).length () - 0.5 * notewidth_f);
-
- // prebreak
- if (d == RIGHT)
+ 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->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_[LEFT] = spanned_drul_[LEFT]->extent (X_AXIS).length ();
+ dx_f_drul_[d] = get_bound (d)->extent (X_AXIS).length () / 2;
+ dx_f_drul_[d] -= d * x_gap_f;
- // urg -- check if needed
- if (encompass_arr_.size () > 1)
- dx_f_drul_[RIGHT] += notewidth_f;
+ if (stem_l->get_direction () != my_dir)
+ {
+ dy_f_drul_[d] = note_column_drul[d]->extent (Y_AXIS)[my_dir];
+ }
+ else
+ {
+ dy_f_drul_[d] = stem_l->chord_start_f ()
+ + my_dir * half_staff_space;
+ }
+ dy_f_drul_[d] += my_dir * y_gap_f;
}
- }
- /*
- normal slur
- */
- else if (normal_edge_b (this, extrema, d))
- {
- Real notewidth_f = extrema[d]->extent (X_AXIS).length ();
- dy_f_drul_[d] = (int)rint (extrema[d]->stem_l_-> extent (Y_AXIS)[dir_]);
- dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
- if (dir_ == extrema[d]->stem_l_->dir_)
+ /*
+ side attached to (visible) stem
+ */
+ else
{
- if (dir_ == d)
- dx_f_drul_[d] += 0.5 * (dir_ * d) * d * notewidth_f;
+ 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->beam_count (-d) >= 1))
+ {
+ 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
+ */
else
- dx_f_drul_[d] += 0.25 * (dir_ * d) * d * notewidth_f;
+ {
+ dx_f_drul_[d] -= d * x_gap_f;
+
+ dy_f_drul_[d] = stem_l->chord_start_f ()
+ + my_dir * half_staff_space;
+ dy_f_drul_[d] += my_dir * y_gap_f;
+ }
}
}
- else
- {
- Real notewidth_f = extrema[d]->extent (X_AXIS).length ();
- dy_f_drul_[d] = (int)rint (extrema[d]->head_positions_interval ()
- [dir_]) * internote_f;
- dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
+ /*
+ loose end
+ */
+ else
+ {
+ dx_f_drul_[d] = get_broken_left_end_align ();
+
+ /*
+ broken: should get y from other piece, so that slur
+ continues up/down trend
+
+ for now: be horizontal..
+ */
+ fix_broken_b = true;
}
- dy_f_drul_[d] += dir_ * interline_f;
- if (extrema[d]->stem_l_ && (dir_ == extrema[d]->stem_l_->dir_))
- dy_f_drul_[d] -= dir_ * internote_f;
- }
- while (flip(&d) != LEFT);
+ }
+ while (flip (&d) != LEFT);
- // now that both are set, do dependent
- do
- {
- if (broken_edge_b (this, extrema, d))
- {
- Direction u = d;
- flip(&u);
+ int cross_count = cross_staff_count ();
+ bool interstaff_b = (0 < cross_count) && (cross_count < encompass_arr.size ());
- // postbreak
- if (d == LEFT)
- dy_f_drul_[u] += dir_ * internote_f;
+ Drul_array<Offset> info_drul;
+ Drul_array<Real> interstaff_interval;
- dy_f_drul_[d] = dy_f_drul_[u];
- }
- }
- while (flip(&d) != LEFT);
+ do
+ {
+ info_drul[d] = encompass_offset (encompass_arr.boundary (d, 0));
+ interstaff_interval[d] = - calc_interstaff_dist (encompass_arr.boundary (d,0),
+ this);
+ }
+ while (flip (&d) != LEFT);
+
+ Real interstaff_f = interstaff_interval[RIGHT] - interstaff_interval[LEFT];
- /*
- Slur should follow line of music
- */
- if (normal_edge_b (this, extrema, LEFT)
- && normal_edge_b (this, extrema, RIGHT)
- && (extrema[LEFT]->stem_l_ != extrema[RIGHT]->stem_l_))
+ if (fix_broken_b)
{
- Real note_dy = extrema[RIGHT]->stem_l_->head_positions ()[dir_]
- - extrema[LEFT]->stem_l_->head_positions ()[dir_];
- Real dy = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
- /*
- Should we always follow note-heads, (like a tie)?
- For now, only if the note_dy != slur_dy, we'll do
- slur_dy := note_dy * factor.
- */
- if (sign (dy) != sign (note_dy))
+ Direction d = (encompass_arr.top () != get_bound (RIGHT)) ?
+ RIGHT : LEFT;
+ dy_f_drul_[d] = info_drul[d][Y_AXIS];
+ if (!interstaff_b)
{
- Real damp_f = paper_l ()->get_var ("slur_slope_follow_music_factor");
- Real realdy = note_dy * damp_f;
- Direction adjust_dir = (Direction)(- dir_ * sign (realdy));
- if (!adjust_dir)
- adjust_dir = -dir_;
- /*
- adjust only if no beam gets in the way
- */
- if (!extrema[adjust_dir]->stem_l_->beam_l_
- || (adjust_dir == extrema[adjust_dir]->stem_l_->dir_)
- || (extrema[adjust_dir]->stem_l_->beams_i_drul_[-adjust_dir] < 1))
+ dy_f_drul_[d] -= interstaff_interval[d];
+ if (cross_count) // interstaff_i ?
{
- dy_f_drul_[adjust_dir] = dy_f_drul_[-adjust_dir]
- + 2 * adjust_dir * realdy;
- Real dx = notewidth_f / 2;
- if (adjust_dir != extrema[adjust_dir]->stem_l_->dir_)
- dx /= 2;
- dx_f_drul_[adjust_dir] -= adjust_dir * dx;
+ dy_f_drul_[LEFT] += interstaff_interval[d];
+ dy_f_drul_[RIGHT] += interstaff_interval[d];
}
}
}
-
- /*
- Avoid too steep slurs.
- */
- Real damp_f = paper_l ()->get_var ("slur_slope_damping");
- Offset d_off = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
- dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
- d_off[X_AXIS] += extent (X_AXIS).length ();
-
- Real ratio_f = abs (d_off[Y_AXIS] / d_off[X_AXIS]);
- if (ratio_f > damp_f)
- dy_f_drul_[(Direction)(- dir_ * sign (d_off[Y_AXIS]))] +=
- dir_ * (ratio_f - damp_f) * d_off[X_AXIS];
+
+ if (!fix_broken_b)
+ dy_f_drul_[RIGHT] += interstaff_f;
}
-Array<Offset>
-Slur::get_encompass_offset_arr () const
-{
- Real notewidth = paper_l ()->note_width () * 0.8;
- Real gap = paper_l ()->get_var ("slur_x_gap");
-
- Offset left = Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]);
- left[X_AXIS] += encompass_arr_[0]->stem_l_->hpos_f ();
- Real internote = encompass_arr_[0]->stem_l_->staff_line_leading_f ()/2.0;
- /*
- <URG>
- i don't understand these two, but *must* for symmetry
- look at encompass array:
- lilypond -D input/test/slur-symmetry*.ly
- lilypond -D input/test/sleur.ly
+int
+Slur::cross_staff_count ()const
+{
+ Link_array<Note_column> encompass_arr =
+ Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns");
- do_post_processing should have calculated these into
- dx_f_drul_[], no??
+ int k=0;
- */
+ for (int i = 0; i < encompass_arr.size (); i++)
+ {
+ if (calc_interstaff_dist (encompass_arr[i], this))
+ k++;
+ }
+ return k;
+}
- if (dir_ != encompass_arr_[0]->stem_l_->dir_)
- left[X_AXIS] += - 0.5 * notewidth * encompass_arr_[0]->stem_l_->dir_
- + gap;
- else if (encompass_arr_[0]->stem_l_->dir_ == UP)
- left[X_AXIS] -= notewidth;
- if ((dir_ == encompass_arr_[0]->stem_l_->dir_)
- && (encompass_arr_[0]->stem_l_->dir_ == DOWN))
- left[Y_AXIS] -= internote * encompass_arr_[0]->stem_l_->dir_;
- /* </URG> */
+Array<Offset>
+Slur::get_encompass_offset_arr () const
+{
+ Link_array<Note_column> encompass_arr =
+ Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+
+ Array<Offset> offset_arr;
- Offset d = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
- dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
- d[X_AXIS] += extent (X_AXIS).length ();
+#if 0
+ /*
+ check non-disturbed slur
+ FIXME: x of ends off by a tiny bit!!
+ */
+ offset_arr.push (Offset (0, dy_f_drul_[LEFT]));
+ offset_arr.push (Offset (0, dy_f_drul_[RIGHT]));
+ return offset_arr;
+#endif
+
+ Offset origin (relative_coordinate (0, X_AXIS), 0);
int first = 1;
- int last = encompass_arr_.size () - 1;
+ int last = encompass_arr.size () - 2;
- // prebreak
- if (encompass_arr_.top () != spanned_drul_[RIGHT])
- last++;
+ offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
- // postbreak
- if (encompass_arr_[0] != spanned_drul_[LEFT])
- first--;
+ /*
+ left is broken edge
+ */
- Array<Offset> notes;
- notes.push (Offset (0,0));
+ int cross_count = cross_staff_count ();
+ bool cross_b = cross_count && cross_count < encompass_arr.size ();
+ if (encompass_arr[0] != get_bound (LEFT))
+ {
+ first--;
+ Real is = calc_interstaff_dist (encompass_arr[0], this);
+ if (cross_b)
+ offset_arr[0][Y_AXIS] += is;
+ }
- for (int i = first; i < last; i++)
+ /*
+ right is broken edge
+ */
+ if (encompass_arr.top () != get_bound (RIGHT))
{
- Encompass_info info (encompass_arr_[i], dir_, this);
- notes.push (info.o_ - left);
+ last++;
}
- Encompass_info info (encompass_arr_.top (), dir_, this);
-
- // urg:
- Slur* urg = (Slur*)this;
- urg->interstaff_f_ = info.interstaff_f_;
-
- d[Y_AXIS] += interstaff_f_;
- // prebreak
- if (interstaff_f_ && (encompass_arr_.top () != spanned_drul_[RIGHT]))
+ for (int i = first; i <= last; i++)
{
- Encompass_info info (encompass_arr_[encompass_arr_.size () - 1], dir_, this);
- d[Y_AXIS] -= info.o_[Y_AXIS] - interstaff_f_;
+ Offset o (encompass_offset (encompass_arr[i]));
+ offset_arr.push (o - origin);
}
- notes.push (d);
+ offset_arr.push (Offset (spanner_length ()+ dx_f_drul_[RIGHT],
+ dy_f_drul_[RIGHT]));
- return notes;
+ return offset_arr;
}
{
Array<Rod> 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<Offset> 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 <x2)
+ {
+ Real y = b.get_other_coordinate (X_AXIS, x);
+ off = off >? dir * (enc[i][Y_AXIS] - y);
+ }
+ }
+ b.translate (Offset (0, dir * off));
+ return b;
+}
+