#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_pointer ("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_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_pointer ("note-heads")))
+ 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;
return d;
}
-void
-Slur::do_add_processing ()
-{
-#if 0
- 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 ());
- }
-#endif
-}
Offset
-Slur::encompass_offset (Note_column const* col) const
+Slur::encompass_offset (Score_element*me,
+ Score_element* col,
+ Score_element **common)
{
Offset o;
- Stem* stem_l = col->stem_l ();
- Direction dir = Directional_element_interface (this).get ();
+ Score_element* stem_l = unsmob_element (col->get_elt_property ("stem"));
+
+ Direction dir = Directional_element_interface (me).get ();
if (!stem_l)
{
warning (_ ("Slur over rest?"));
- o[X_AXIS] = col->relative_coordinate (0, X_AXIS);
- o[Y_AXIS] = col->relative_coordinate (0, Y_AXIS);
+ o[X_AXIS] = col->relative_coordinate (common[X_AXIS], X_AXIS);
+ o[Y_AXIS] = col->relative_coordinate (common[Y_AXIS], Y_AXIS);
return o;
}
Direction stem_dir = Directional_element_interface (stem_l).get ();
if ((stem_dir == dir)
&& !stem_l->extent (Y_AXIS).empty_b ())
{
- o[Y_AXIS] = stem_l->relative_coordinate (0, Y_AXIS);
+ o[Y_AXIS] = stem_l->relative_coordinate (common[Y_AXIS], Y_AXIS); // iuhg
}
else
{
- o[Y_AXIS] = col->relative_coordinate (0, Y_AXIS);
+ o[Y_AXIS] = col->relative_coordinate (common[Y_AXIS], Y_AXIS); // ugh
}
/*
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;
}
-GLUE_SCORE_ELEMENT(Slur,after_line_breaking);
+MAKE_SCHEME_CALLBACK(Slur,after_line_breaking);
SCM
-Slur::member_after_line_breaking ()
+Slur::after_line_breaking (SCM smob)
{
- set_extremities ();
- set_control_points ();
- return SCM_UNDEFINED;
+ Score_element *me = unsmob_element (smob);
+ set_extremities (me);
+ set_control_points (me);
+ return SCM_UNSPECIFIED;
}
-SCM
-slur_get_bound (SCM slur, SCM dir)
-{
- return ((Slur*)unsmob_element (slur))->get_bound (to_dir (dir))->self_scm_;
-}
-
-SCM
-score_element_get_pointer (SCM se, SCM name)
-{
- SCM s = scm_assq (name, unsmob_element (se)->pointer_alist_);
- return (s == SCM_BOOL_F) ? SCM_UNDEFINED : gh_cdr (s);
-}
-
-SCM
-score_element_get_property (SCM se, SCM name)
-{
- SCM s = scm_assq (name, unsmob_element (se)->property_alist_);
- return (s == SCM_BOOL_F) ? SCM_UNDEFINED : gh_cdr (s);
-}
-
void
-init_score_elts ()
+Slur::set_extremities (Score_element*me)
{
- scm_make_gsubr ("get-pointer", 2 , 0, 0,
- (SCM(*)(...)) score_element_get_pointer);
- scm_make_gsubr ("get-property", 2 , 0, 0,
- (SCM(*)(...)) score_element_get_property);
- scm_make_gsubr ("get-bound", 2 , 0, 0,
- (SCM(*)(...)) slur_get_bound);
-}
-
-ADD_SCM_INIT_FUNC (score_elt, init_score_elts);
-
-void
-Slur::set_extremities ()
-{
- 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) 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_interface (this).staff_space ();
+ 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 (Stem* st = dynamic_cast<Stem*> (n->stem_l ()))
+ Score_element * n =sp->get_bound (dir);
+ if (Score_element*st = Note_column::stem_l (n))
{
+
if (str == "head")
{
- o = Offset (0, st->chord_start_f ());
+ 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 (0, st->chord_start_f ());
+ o = Offset (0, Stem::chord_start_f (st ));
/*
Default position is on stem X, on outer side of head Y
*/
o += Offset (n->extent (X_AXIS).length ()
- * (1 + st->get_direction ()),
- 0.5 * ss * Directional_element_interface (this).get ());
+ * (1 + Stem::get_direction (st )),
+ 0.5 * ss * Directional_element_interface (me).get ());
}
else if (str == "stem")
{
- o = Offset (0, st->stem_end_position () * hs);
+ o = Offset (0, Stem::stem_end_position (st ) * hs);
/*
Default position is on stem X, at stem end Y
*/
o += Offset (0.5 *
(n->extent (X_AXIS).length ()
- st->extent (X_AXIS).length ())
- * (1 + st->get_direction ()),
+ * (1 + Stem::get_direction (st )),
0);
}
else if (str == "loose-end")
SCM other_a = dir == LEFT ? gh_cdr (s) : gh_car (s);
if (ly_symbol2string (other_a) != "loose-end")
{
- o = Offset (0, get_attachment (-dir)[Y_AXIS]);
+ o = Offset (0, get_attachment (me, -dir, common)[Y_AXIS]);
}
}
SCM l = scm_assoc
(scm_listify (a,
- gh_int2scm (st->get_direction () * dir),
- gh_int2scm (Directional_element_interface (this).get () * dir),
+ gh_int2scm (Stem::get_direction (st ) * dir),
+ gh_int2scm (Directional_element_interface (me).get () * dir),
SCM_UNDEFINED),
scm_eval (ly_symbol2scm ("slur-extremity-offset-alist")));
}
}
- if (str != "loose-end")
- o += Offset (0, get_bound (dir)->relative_coordinate (0, Y_AXIS)
- - relative_coordinate (0, Y_AXIS));
-
+
+ /*
+ What if get_bound () is not a note-column?
+ */
+ if (str != "loose-end"
+ && sp->get_bound (dir)->common_refpoint (common[Y_AXIS], Y_AXIS) == common[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)
{
- Link_array<Note_column> encompass_arr =
- Pointer_group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+ 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 (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))
+ {
+ encompass_arr.push (unsmob_element (gh_car (eltlist)));
+ eltlist =gh_cdr (eltlist);
+ }
+ encompass_arr.reverse ();
+
Array<Offset> offset_arr;
- Offset origin (relative_coordinate (0, X_AXIS),
- relative_coordinate (0, 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));
+ 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 (0, Y_AXIS)
- - relative_coordinate (0, Y_AXIS);
+
+ // ?
+ offset_arr[0][Y_AXIS] -=
+ encompass_arr[0]->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]));
+ Offset o (encompass_offset (me, encompass_arr[i], common));
offset_arr.push (o - origin);
}
- offset_arr.push (Offset (spanner_length (), 0) + get_attachment (RIGHT));
+ 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 (0, Y_AXIS)
- - relative_coordinate (0, Y_AXIS);
+ offset_arr.top ()[Y_AXIS] -= encompass_arr.top ()->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;
- 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");
+ Score_element*me = unsmob_element (smob);
- a.push (r);
- return a;
+ Rod r;
+ 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_ =
+ gh_scm2double (me->get_elt_property ("minimum-length"))
+ * me->paper_l ()->get_var ("staffspace");
+
+ r.add_to_cols ();
+ return SCM_UNSPECIFIED;
}
/*
Ugh should have dash-length + dash-period
*/
-GLUE_SCORE_ELEMENT(Slur,brew_molecule);
+MAKE_SCHEME_CALLBACK(Slur,brew_molecule);
SCM
-Slur::member_brew_molecule () const
+Slur::brew_molecule (SCM smob)
{
- Real thick = paper_l ()->get_var ("slur_thickness");
- Bezier one = get_curve ();
+ Score_element * me = unsmob_element (smob);
+ Real thick = me->paper_l ()->get_var ("stafflinethickness") *
+ gh_scm2double (me->get_elt_property ("thickness"));
+ Bezier one = get_curve (me);
Molecule a;
- SCM d = get_elt_property ("dashed");
+ SCM d = me->get_elt_property ("dashed");
if (gh_number_p (d))
- a = lookup_l ()->dashed_slur (one, thick, thick * gh_scm2double (d));
+ a = me->lookup_l ()->dashed_slur (one, thick, thick * gh_scm2double (d));
else
- a = lookup_l ()->slur (one, Directional_element_interface (this).get () * thick, thick);
+ a = me->lookup_l ()->slur (one, Directional_element_interface (me).get () * thick, thick);
return a.create_scheme();
}
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 ());
-
- 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);
+ Real staff_space = Staff_symbol_referencer::staff_space ((Score_element*)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");
+
+ Slur_bezier_bow bb (get_encompass_offset_arr (me),
+ Directional_element_interface (me).get (),
+ 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 default_height = slur_height (length, h_inf, r_0);
+ bb.minimise_enclosed_area (me->paper_l());
- 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 (ly_symbol2scm ("slur-interface"));
+}
+
+