]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/side-position-interface.cc
release: 1.3.93
[lilypond.git] / lily / side-position-interface.cc
index de2d398b70ad7eb9776fa2af73bcc4c7b6f5bb92..efbaf148448e2767809656e712b4022014f5fe21 100644 (file)
@@ -108,30 +108,32 @@ Side_position::side_position (Score_element *cme, Axis axis)
   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;
 }
 
@@ -148,7 +150,10 @@ directed_round (Real f, Direction d)
 
 /*
   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 )
 {
@@ -158,9 +163,10 @@ 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;
@@ -219,11 +225,6 @@ Side_position::add_staff_support (Score_element*me)
 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);
 }
@@ -263,14 +264,14 @@ Side_position::set_padding (Score_element*me, Real p)
 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);
 }