#include "main.hh"
#include "group-interface.hh"
#include "staff-symbol-referencer.hh"
+#include "spanner.hh"
-Slur::Slur (SCM s)
- : Spanner (s)
+
+void
+Slur::set_interface (Score_element*me)
{
- set_elt_property ("attachment", gh_cons (SCM_BOOL_F, SCM_BOOL_F));
- set_elt_property ("note-columns", SCM_EOL);
- set_elt_property ("control-points", SCM_EOL);
+ me-> set_elt_property ("attachment", gh_cons (SCM_BOOL_F, SCM_BOOL_F));
+ me->set_elt_property ("note-columns", SCM_EOL);
+ me->set_elt_property ("control-points", SCM_EOL);
+ me->set_interface (ly_symbol2scm ("slur-interface"));
}
void
-Slur::add_column (Note_column*n)
+Slur::add_column (Score_element*me, Score_element*n)
{
if (!gh_pair_p (n->get_elt_property ("note-heads")))
warning (_ ("Putting slur over rest. Ignoring."));
else
{
- Pointer_group_interface (this, "note-columns").add_element (n);
- add_dependency (n);
+ Pointer_group_interface (me, "note-columns").add_element (n);
+ me->add_dependency (n);
}
- add_bound_item (this, n);
+ add_bound_item (dynamic_cast<Spanner*> (me), dynamic_cast<Item*>(n));
}
void
-Slur::de_uglyfy (Slur_bezier_bow* bb, Real default_height)
+Slur::de_uglyfy (Score_element*me, Slur_bezier_bow* bb, Real default_height)
{
Real length = bb->curve_.control_[3][X_AXIS] ;
Real ff = bb->fit_factor ();
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");
+ Real c1 = me->paper_l ()->get_var ("bezier_control1");
+ Real c2 = me->paper_l ()->get_var ("bezier_control2");
+ Real c3 = me->paper_l ()->get_var ("bezier_control3");
if (h > c1 * f)
{
h = c1 * f;
}
Direction
-Slur::get_default_dir () const
+Slur::get_default_dir (Score_element*me)
{
- Link_array<Note_column> encompass_arr =
- Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+ Link_array<Score_element> encompass_arr =
+ Pointer_group_interface__extract_elements (me, (Score_element*)0, "note-columns");
Direction d = DOWN;
for (int i=0; i < encompass_arr.size (); i ++)
{
- if (encompass_arr[i]->dir () < 0)
+ if (Note_column::dir (encompass_arr[i]) < 0)
{
d = UP;
break;
Offset
-Slur::encompass_offset (Score_element* col,
- Score_element **common) const
+Slur::encompass_offset (Score_element*me,
+ Score_element* col,
+ Score_element **common)
{
Offset o;
Score_element* stem_l = unsmob_element (col->get_elt_property ("stem"));
- Direction dir = Directional_element_interface (this).get ();
+ Direction dir = Directional_element_interface (me).get ();
if (!stem_l)
{
/*
leave a gap: slur mustn't touch head/stem
*/
- o[Y_AXIS] += dir * paper_l ()->get_var ("slur_y_free");
+ o[Y_AXIS] += dir * me->paper_l ()->get_var ("slur_y_free");
return o;
}
Slur::after_line_breaking (SCM smob)
{
Score_element *me = unsmob_element (smob);
- Slur * sl = dynamic_cast<Slur*>(me);
- sl->set_extremities ();
- sl->set_control_points ();
+ set_extremities (me);
+ set_control_points (me);
return SCM_UNDEFINED;
}
void
-Slur::set_extremities ()
+Slur::set_extremities (Score_element*me)
{
- if (!Directional_element_interface (this).get ())
- Directional_element_interface (this).set (get_default_dir ());
+ if (!Directional_element_interface (me).get ())
+ Directional_element_interface (me).set (get_default_dir (me));
Direction dir = LEFT;
do
{
- if (!gh_symbol_p (index_cell (get_elt_property ("attachment"), dir)))
+ if (!gh_symbol_p (index_cell (me->get_elt_property ("attachment"), dir)))
{
// for (SCM s = get_elt_property ("slur-extremity-rules"); s != SCM_EOL; s = gh_cdr (s))
for (SCM s = scm_eval (ly_symbol2scm ("slur-extremity-rules"));
s != SCM_EOL; s = gh_cdr (s))
{
- SCM r = gh_call2 (gh_caar (s), this->self_scm_,
+ SCM r = gh_call2 (gh_caar (s), me->self_scm_,
gh_int2scm ((int)dir));
if (r != SCM_BOOL_F)
{
- index_set_cell (get_elt_property ("attachment"), dir,
+ index_set_cell (me->get_elt_property ("attachment"), dir,
gh_cdar (s));
break;
}
}
Offset
-Slur::get_attachment (Direction dir,
- Score_element **common) const
+Slur::get_attachment (Score_element*me,Direction dir,
+ Score_element **common)
{
- SCM s = get_elt_property ("attachment");
+ Spanner*sp = dynamic_cast<Spanner*>(me);
+ SCM s = me->get_elt_property ("attachment");
SCM a = dir == LEFT ? gh_car (s) : gh_cdr (s);
String str = ly_symbol2string (a);
- Real ss = Staff_symbol_referencer::staff_space ((Score_element*)this);
+ Real ss = Staff_symbol_referencer::staff_space ((Score_element*)me);
Real hs = ss / 2.0;
Offset o;
-
- if (Note_column* n = dynamic_cast<Note_column*> (get_bound (dir)))
+
+ if (Note_column::has_interface (sp->get_bound (dir)))
{
- if (n->stem_l ())
+ Score_element * n =sp->get_bound (dir);
+ if (Score_element*st = Note_column::stem_l (n))
{
- Score_element*st = n->stem_l();
+
if (str == "head")
{
o = Offset (0, Stem::chord_start_f (st ));
Default position is centered in X, on outer side of head Y
*/
o += Offset (0.5 * n->extent (X_AXIS).length (),
- 0.5 * ss * Directional_element_interface (this).get ());
+ 0.5 * ss * Directional_element_interface (me).get ());
}
else if (str == "alongside-stem")
{
*/
o += Offset (n->extent (X_AXIS).length ()
* (1 + Stem::get_direction (st )),
- 0.5 * ss * Directional_element_interface (this).get ());
+ 0.5 * ss * Directional_element_interface (me).get ());
}
else if (str == "stem")
{
SCM other_a = dir == LEFT ? gh_cdr (s) : gh_car (s);
if (ly_symbol2string (other_a) != "loose-end")
{
- o = Offset (0, get_attachment (-dir, common)[Y_AXIS]);
+ o = Offset (0, get_attachment (me, -dir, common)[Y_AXIS]);
}
}
SCM l = scm_assoc
(scm_listify (a,
gh_int2scm (Stem::get_direction (st ) * dir),
- gh_int2scm (Directional_element_interface (this).get () * dir),
+ gh_int2scm (Directional_element_interface (me).get () * dir),
SCM_UNDEFINED),
scm_eval (ly_symbol2scm ("slur-extremity-offset-alist")));
What if get_bound () is not a note-column?
*/
if (str != "loose-end"
- && get_bound (dir)->common_refpoint (common[Y_AXIS], Y_AXIS) == common[Y_AXIS])
+ && sp->get_bound (dir)->common_refpoint (common[Y_AXIS], Y_AXIS) == common[Y_AXIS])
{
- o[Y_AXIS] += get_bound (dir)->relative_coordinate (common[Y_AXIS], Y_AXIS)
- - relative_coordinate (common[Y_AXIS], Y_AXIS);
+ o[Y_AXIS] += sp->get_bound (dir)->relative_coordinate (common[Y_AXIS], Y_AXIS)
+ - me->relative_coordinate (common[Y_AXIS], Y_AXIS);
}
return o;
}
Array<Offset>
-Slur::get_encompass_offset_arr () const
+Slur::get_encompass_offset_arr (Score_element*me)
{
- SCM eltlist = get_elt_property ("note-columns");
- Score_element *common[] = {common_refpoint (eltlist,X_AXIS),
- common_refpoint (eltlist,Y_AXIS)};
+ Spanner*sp = dynamic_cast<Spanner*>(me);
+ SCM eltlist = me->get_elt_property ("note-columns");
+ Score_element *common[] = {me->common_refpoint (eltlist,X_AXIS),
+ me->common_refpoint (eltlist,Y_AXIS)};
- common[X_AXIS] = common[X_AXIS]->common_refpoint (get_bound (RIGHT), X_AXIS);
- common[X_AXIS] = common[X_AXIS]->common_refpoint (get_bound (LEFT), X_AXIS);
+ 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);
Link_array<Score_element> encompass_arr;
while (gh_pair_p (eltlist))
Array<Offset> offset_arr;
- Offset origin (relative_coordinate (common[X_AXIS], X_AXIS),
- relative_coordinate (common[Y_AXIS], Y_AXIS));
+ Offset origin (me->relative_coordinate (common[X_AXIS], X_AXIS),
+ me->relative_coordinate (common[Y_AXIS], Y_AXIS));
int first = 1;
int last = encompass_arr.size () - 2;
- offset_arr.push (get_attachment (LEFT, common));
+ offset_arr.push (get_attachment (me, LEFT, common));
/*
left is broken edge
*/
- if (encompass_arr[0] != get_bound (LEFT))
+ if (encompass_arr[0] != sp->get_bound (LEFT))
{
first--;
// ?
offset_arr[0][Y_AXIS] -=
encompass_arr[0]->relative_coordinate (common[Y_AXIS], Y_AXIS)
- - relative_coordinate (common[Y_AXIS], Y_AXIS);
+ - me->relative_coordinate (common[Y_AXIS], Y_AXIS);
}
/*
right is broken edge
*/
- if (encompass_arr.top () != get_bound (RIGHT))
+ if (encompass_arr.top () != sp->get_bound (RIGHT))
{
last++;
}
for (int i = first; i <= last; i++)
{
- Offset o (encompass_offset (encompass_arr[i], common));
+ Offset o (encompass_offset (me, encompass_arr[i], common));
offset_arr.push (o - origin);
}
- offset_arr.push (Offset (spanner_length (), 0) + get_attachment (RIGHT,common));
+ offset_arr.push (Offset (sp->spanner_length (), 0) + get_attachment (me, RIGHT,common));
- if (encompass_arr[0] != get_bound (LEFT))
+ if (encompass_arr[0] != sp->get_bound (LEFT))
{
offset_arr.top ()[Y_AXIS] -= encompass_arr.top ()->relative_coordinate (common[Y_AXIS], Y_AXIS)
- - relative_coordinate (common[Y_AXIS], Y_AXIS);
+ - me->relative_coordinate (common[Y_AXIS], Y_AXIS);
}
return offset_arr;
}
-Array<Rod>
-Slur::get_rods () const
+MAKE_SCHEME_CALLBACK(Slur,set_spacing_rods);
+SCM
+Slur::set_spacing_rods (SCM smob)
{
- Array<Rod> a;
+ Score_element*me = unsmob_element (smob);
+
Rod r;
-
- 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");
+ Spanner*sp = dynamic_cast<Spanner*>(me);
+ r.item_l_drul_[LEFT] = sp->get_bound (LEFT);
+ r.item_l_drul_[RIGHT] = sp->get_bound (RIGHT);
+ r.distance_f_ = me->paper_l ()->get_var ("slur_x_minimum");
- a.push (r);
- return a;
+ r.add_to_cols ();
+ return SCM_UNDEFINED;
}
SCM
Slur::brew_molecule (SCM smob)
{
- Slur * me = dynamic_cast<Slur*> (unsmob_element (smob));
-
-
+ Score_element * me = unsmob_element (smob);
Real thick = me->paper_l ()->get_var ("slur_thickness");
- Bezier one = me->get_curve ();
+ Bezier one = get_curve (me);
Molecule a;
SCM d = me->get_elt_property ("dashed");
}
void
-Slur::set_control_points ()
+Slur::set_control_points (Score_element*me)
{
- Slur_bezier_bow bb (get_encompass_offset_arr (),
- Directional_element_interface (this).get ());
+ Slur_bezier_bow bb (get_encompass_offset_arr (me),
+ Directional_element_interface (me).get ());
- Real staff_space = Staff_symbol_referencer::staff_space (this);
- Real h_inf = paper_l ()->get_var ("slur_height_limit_factor") * staff_space;
- Real r_0 = paper_l ()->get_var ("slur_ratio");
+ Real staff_space = Staff_symbol_referencer::staff_space (me);
+ Real h_inf = me->paper_l ()->get_var ("slur_height_limit_factor") * staff_space;
+ Real r_0 = me->paper_l ()->get_var ("slur_ratio");
bb.set_default_bezier (h_inf, r_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);
+ bb.minimise_enclosed_area (me->paper_l(), default_height);
- Real bff = paper_l ()->get_var ("slur_force_blowfit");
+ Real bff = me->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 sb = me->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);
+ de_uglyfy (me, &bb, default_height);
}
Bezier b = bb.get_bezier ();
for (int i= 4; i--;)
controls = gh_cons ( ly_offset2scm (b.control_[i]), controls);
- set_elt_property ("control-points", controls);
+ me->set_elt_property ("control-points", controls);
}
Bezier
-Slur::get_curve () const
+Slur::get_curve (Score_element*me)
{
Bezier b;
int i = 0;
- if (!Directional_element_interface (this).get ()
- || ! gh_symbol_p (index_cell (get_elt_property ("attachment"), LEFT)))
- ((Slur*)this)->set_extremities ();
+ if (!Directional_element_interface (me).get ()
+ || ! gh_symbol_p (index_cell (me->get_elt_property ("attachment"), LEFT)))
+ set_extremities (me);
- if (!gh_pair_p (get_elt_property ("control-points")))
- ((Slur*)this)->set_control_points ();
+ if (!gh_pair_p (me->get_elt_property ("control-points")))
+ set_control_points (me);
- for (SCM s= get_elt_property ("control-points"); s != SCM_EOL; s = gh_cdr (s))
+ for (SCM s= me->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_interface (this).get ();
+ Array<Offset> enc (get_encompass_offset_arr (me));
+ Direction dir = Directional_element_interface (me).get ();
Real x1 = enc[0][X_AXIS];
Real x2 = enc.top ()[X_AXIS];
return b;
}
+
+bool
+Slur::has_interface (Score_element*me)
+{
+ return me->has_interface ("slur-interface");
+}
+
+