callback that centers the element on itself
*/
Real
-Side_position::aligned_on_self (Score_element *elm, Axis ax)
+Side_position::aligned_on_self (Score_element *me, Axis ax)
{
String s ("self-alignment-");
s += (ax == X_AXIS) ? "X" : "Y";
- SCM align (elm->get_elt_property (s.ch_C()));
- if (isdir_b (align))
+ SCM align (me->get_elt_property (s.ch_C()));
+ if (gh_number_p (align))
{
- Direction d = to_dir (align);
- Interval ext(elm->extent (ax));
+ Interval ext(me->extent (ax));
if (ext.empty_b ())
{
programming_error ("I'm empty. Can't align on self");
return 0.0;
}
- else if (d)
+ else
{
- return - ext[d];
+ Real lambda = (0.5 - gh_scm2double (align) / 2.0);
+ return - (lambda * ext[LEFT] + (1 - lambda) * ext[RIGHT]);
}
- return - ext.center ();
}
- else
+ else if (unsmob_element (align))
+ {
+ return - unsmob_element (align)->relative_coordinate (me, ax);
+ }
return 0.0;
}
/*
Callback that quantises in staff-spaces, rounding in the direction
- of the elements "direction" elt property. */
+ of the elements "direction" elt property.
+
+ Only rounds when we're inside the staff, as determined by
+ Staff_symbol_referencer::staff_radius() */
Real
Side_position::quantised_position (Score_element *me, Axis )
{
{
Real p = Staff_symbol_referencer::position_f (me);
Real rp = directed_round (p, d);
-
+ Real rad = Staff_symbol_referencer::staff_radius (me) *2 ;
int ip = int (rp);
- if ((ip % 2) == 0)
+
+ if (abs (ip) < rad && Staff_symbol_referencer::on_staffline (me,ip))
{
ip += d;
rp += d;
void
Side_position::set_axis (Score_element*me, Axis a)
{
- /*
- // prop transparent ?
- if (me->get_elt_property ("side-support-elements") == SCM_UNDEFINED)
- me->set_elt_property ("side-support-elements" ,SCM_EOL);
- */
if (!me->has_offset_callback_b (aligned_side, a))
me->add_offset_callback (aligned_side, a);
}
bool
Side_position::has_interface (Score_element*me)
{
- return me->get_elt_property ("side-support-elements") != SCM_EOL;
+ return me->has_interface (ly_symbol2scm ("side-position-interface"));
}
bool
Side_position::supported_b (Score_element*me)
{
SCM s = me->get_elt_property ("side-support-elements");
- return s != SCM_UNDEFINED && s != SCM_EOL;
+ return gh_pair_p(s);
}