]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 3978: Merge alignment cleanup
authorJanek Warchoł <lemniskata.bernoullego@gmail.com>
Sat, 5 Jul 2014 21:11:40 +0000 (23:11 +0200)
committerJanek Warchoł <lemniskata.bernoullego@gmail.com>
Sat, 5 Jul 2014 21:12:36 +0000 (23:12 +0200)
Make DynamicTexts, TextScripts and many other grobs use aligned_on_parent,
which makes their behaviour consitent, predictable and thus more user-friendly.

input/regression/text-spanner-attachment-alignment.ly
lily/dynamic-engraver.cc
lily/fingering-engraver.cc
lily/include/self-alignment-interface.hh
lily/new-fingering-engraver.cc
lily/self-alignment-interface.cc
ly/engraver-init.ly
scm/define-grobs.scm

index 098ef131dbe4c417abd352bf69677aa0dc366e64..02f97ff82971b70c61d8f3425f1fe5d428e5c51c 100644 (file)
@@ -1,23 +1,21 @@
 \header {
-
   texidoc = "Text and trill spanners are attached to note columns, so
   attachments in other staves have no effect on them."
-  
-  }
+}
 
 \layout {
   ragged-right = ##t
-  }
+}
 
 \version "2.17.6"
 <<
-   \new Staff {
+  \new Staff {
     \override TextSpanner.bound-details.left.text = "*"
-      c'16 \startTrillSpan c' c' c' \stopTrillSpan 
-      c'16 \startTextSpan c' c' c' \stopTextSpan 
-   }
-   \new Staff {
-     \override TextScript.self-alignment-X = #RIGHT 
-     \repeat unfold 2 {c'4 _ \markup { "FAT" } } 
-   }
+    c'16 \startTrillSpan c' c' c' \stopTrillSpan
+    c'16 \startTextSpan c' c' c' \stopTextSpan
+  }
+  \new Staff {
+    \override TextScript.self-alignment-X = #RIGHT
+    \repeat unfold 2 {c'4 _ \markup { "LONG" } }
+  }
 >>
index d1b8cf00b52d931605eacb16c9a179d898d74597..a91d742ee80306de3221656808baea2d52ff3ed1 100644 (file)
@@ -268,10 +268,7 @@ Dynamic_engraver::acknowledge_note_column (Grob_info info)
                         ? heads[0]
                         : unsmob_grob (info.grob ()->get_object ("rest")));
       if (x_parent)
-        {
-          script_->set_parent (x_parent, X_AXIS);
-          Self_alignment_interface::set_center_parent (script_, X_AXIS);
-        }
+        script_->set_parent (x_parent, X_AXIS);
     }
 
   if (current_spanner_ && !current_spanner_->get_bound (LEFT))
index d23a5e35f81852ab7088c2f451ea2458a91b6140..b8e7d94df12bc4065e623d8b3c15b4af11306ce8 100644 (file)
@@ -109,8 +109,7 @@ Fingering_engraver::make_script (Direction d, Stream_event *r, int i)
     fingerings for chords need different settings.
   */
   Side_position_interface::set_axis (fingering, Y_AXIS);
-  Self_alignment_interface::set_align_self (fingering, X_AXIS);
-  Self_alignment_interface::set_center_parent (fingering, X_AXIS);
+  Self_alignment_interface::set_aligned_on_parent (fingering, X_AXIS);
 
   // Hmm
   int priority = 200;
index 823556a4c2f7ac30ec930927955423b958faf19d..867f97bf86da98f90ed792aade88489b9a679750 100644 (file)
@@ -30,15 +30,13 @@ struct Self_alignment_interface
   static SCM aligned_on_self (Grob *me, Axis a, bool pure, int start, int end);
   static SCM centered_on_object (Grob *me, Axis a);
   static SCM aligned_on_parent (Grob *me, Axis a);
-  static void set_center_parent (Grob *me, Axis a);
-  static void set_align_self (Grob *me, Axis a);
+  static void set_aligned_on_parent (Grob *me, Axis a);
 
   DECLARE_SCHEME_CALLBACK (x_aligned_on_self, (SCM element));
   DECLARE_SCHEME_CALLBACK (y_aligned_on_self, (SCM element));
 
   DECLARE_SCHEME_CALLBACK (pure_y_aligned_on_self, (SCM element, SCM start, SCM end));
 
-  DECLARE_SCHEME_CALLBACK (centered_on_note_columns, (SCM element));
   DECLARE_SCHEME_CALLBACK (centered_on_x_parent, (SCM element));
   DECLARE_SCHEME_CALLBACK (centered_on_y_parent, (SCM element));
   DECLARE_SCHEME_CALLBACK (aligned_on_x_parent, (SCM element));
index 51eb26c6d29a1f89aa20836950cba09dc1f36e22..7f504ae4521115214e411399547634e3aac7b32b 100644 (file)
@@ -288,8 +288,7 @@ New_fingering_engraver::position_scripts (SCM orientations,
         Side_position_interface::add_support (f,
                                               unsmob_grob (ft.head_->get_object ("dot")));
 
-      Self_alignment_interface::set_align_self (f, Y_AXIS);
-      Self_alignment_interface::set_center_parent (f, Y_AXIS);
+      Self_alignment_interface::set_aligned_on_parent (f, Y_AXIS);
       Side_position_interface::set_axis (f, X_AXIS);
 
       f->set_property ("direction", scm_from_int (hordir));
@@ -307,8 +306,7 @@ New_fingering_engraver::position_scripts (SCM orientations,
           f->set_property ("script-priority",
                            scm_from_int (finger_prio + d * ft.position_));
 
-          Self_alignment_interface::set_align_self (f, X_AXIS);
-          Self_alignment_interface::set_center_parent (f, X_AXIS);
+          Self_alignment_interface::set_aligned_on_parent (f, X_AXIS);
           Side_position_interface::set_axis (f, Y_AXIS);
 
           f->set_property ("direction", scm_from_int (d));
index eb51dc7f1b4e981902ddaf35a0d68ed2516dbb4f..d1cb1bf50ca54e92295d13ef468b0e5580585936 100644 (file)
@@ -79,27 +79,6 @@ Self_alignment_interface::centered_on_x_parent (SCM smob)
   return centered_on_object (unsmob_grob (smob)->get_parent (X_AXIS), X_AXIS);
 }
 
-MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_note_columns, 1);
-SCM
-Self_alignment_interface::centered_on_note_columns (SCM smob)
-{
-  Item *it = unsmob_item (smob)->get_column ();
-  if (!it)
-    return scm_from_double (0.0);
-
-  extract_grob_set (it, "elements", elts);
-  vector<Grob *> ncs;
-  Interval centers;
-  for (vsize i = 0; i < elts.size (); i++)
-    if (Note_column::has_interface (elts[i]))
-      centers.add_point (scm_to_double (centered_on_object (elts[i], X_AXIS)));
-
-  if (centers.is_empty ())
-    return scm_from_double (0.0);
-
-  return scm_from_double (centers.center ());
-}
-
 MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_y_parent, 1);
 SCM
 Self_alignment_interface::centered_on_y_parent (SCM smob)
@@ -166,18 +145,10 @@ Self_alignment_interface::aligned_on_parent (Grob *me, Axis a)
 }
 
 void
-Self_alignment_interface::set_center_parent (Grob *me, Axis a)
-{
-  add_offset_callback (me,
-                       (a == X_AXIS) ? centered_on_x_parent_proc : centered_on_y_parent_proc,
-                       a);
-}
-
-void
-Self_alignment_interface::set_align_self (Grob *me, Axis a)
+Self_alignment_interface::set_aligned_on_parent (Grob *me, Axis a)
 {
   add_offset_callback (me,
-                       (a == X_AXIS) ? x_aligned_on_self_proc : y_aligned_on_self_proc,
+                       (a == X_AXIS) ? aligned_on_x_parent_proc : aligned_on_y_parent_proc,
                        a);
 }
 
index ebfff6a2fcd2889c14b287db84a28d6bc7d2a10e..ec34cd64c33fa1187504bfc9ebd02f5a14ec4768 100644 (file)
@@ -420,13 +420,6 @@ a collection of staves, with a bracket in front and spanning bar lines."
   \override DynamicLineSpanner.outside-staff-priority = ##f
   \override DynamicText.outside-staff-priority = ##f
   \override Hairpin.outside-staff-priority = ##f
-  \override DynamicText.X-offset =
-  #(ly:make-simple-closure
-    `(,+
-      ,(ly:make-simple-closure
-         (list ly:self-alignment-interface::centered-on-note-columns))
-      ,(ly:make-simple-closure
-        (list ly:self-alignment-interface::x-aligned-on-self))))
 
   \description "Holds a single line of dynamics, which will be
 centered between the staves surrounding this context."
index aa3e605aeb60423810836df9cbdf49cf70badc37..ddacbcb7ec1131864197462b77ef59f7dca37b4b 100644 (file)
         (staff-padding . 0.25)
         (stencil . ,ly:accidental-interface::print)
         (X-extent . ,ly:accidental-interface::width)
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self)))))
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-extent . ,accidental-interface::height)
         (Y-offset . ,side-position-interface::y-aligned-side)
         (meta . ((class . Item)
      . (
         (break-visibility . ,(grob::inherit-parent-property
                               X 'break-visibility))
-        (font-shape . italic)
-        (font-size . -4)
-        (transparent . ,(grob::inherit-parent-property
-                         X 'transparent))
         (color . ,(grob::inherit-parent-property
                    X 'color))
+        (font-shape . italic)
+        (font-size . -4)
         (self-alignment-X . ,CENTER)
         (staff-padding . 0.7)
         (stencil . ,ly:text-interface::print)
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent)))))
-        (Y-offset . ,side-position-interface::y-aligned-side)
+        (transparent . ,(grob::inherit-parent-property
+                         X 'transparent))
         (vertical-skylines . ,grob::always-vertical-skylines-from-stencil)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-extent . ,grob::always-Y-extent-from-stencil)
+        (Y-offset . ,side-position-interface::y-aligned-side)
         (meta . ((class . Item)
                  (interfaces . (clef-modifier-interface
                                 font-interface
         (outside-staff-priority . 450)
         (padding . 0.5)
         (script-priority . 200)
+        (self-alignment-X . #f)
         (side-axis . ,Y)
         (staff-padding . 0.5)
-        ;; todo: add X self alignment?
         (stencil . ,ly:text-interface::print)
-        (X-offset . ,ly:self-alignment-interface::x-aligned-on-self)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-offset . ,side-position-interface::y-aligned-side)
         (Y-extent . ,grob::always-Y-extent-from-stencil)
         (meta . ((class . Item)
                  (interfaces . (font-interface
                                 outside-staff-interface
+                                self-alignment-interface
                                 side-position-interface
                                 text-interface
                                 text-script-interface))))))
         (side-axis . ,Y)
         (staff-padding . 0.25)
         (stencil . ,ly:text-interface::print)
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self)))))
-        (Y-offset . ,side-position-interface::y-aligned-side)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-extent . ,grob::always-Y-extent-from-stencil)
+        (Y-offset . ,side-position-interface::y-aligned-side)
         (meta . ((class . Item)
                  (interfaces . (font-interface
                                 outside-staff-interface
         (stencil . ,ly:text-interface::print)
         (vertical-skylines . ,grob::always-vertical-skylines-from-stencil)
         (Y-extent . ,grob::always-Y-extent-from-stencil)
-        (X-offset . ,ly:self-alignment-interface::x-aligned-on-self)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-offset . ,(scale-by-font-size -0.6)) ; center on an 'm'
         (meta . ((class . Item)
                  (interfaces . (dynamic-interface
         (layer . 0)
         (self-alignment-X . ,CENTER)
         (stencil . ,ly:grid-line-interface::print)
-        (X-extent  . ,ly:grid-line-interface::width)
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self)))))
+        (X-extent . ,ly:grid-line-interface::width)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (meta . ((class . Item)
                  (interfaces . (grid-line-interface
                                 self-alignment-interface))))))
         (springs-and-rods . ,ly:multi-measure-rest::set-text-rods)
         (staff-padding . 0.4)
         (stencil . ,ly:text-interface::print)
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent)))))
-        (Y-offset . ,side-position-interface::y-aligned-side)
         (vertical-skylines . ,grob::unpure-vertical-skylines-from-stencil)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-extent . ,grob::always-Y-extent-from-stencil)
+        (Y-offset . ,side-position-interface::y-aligned-side)
         (meta . ((class . Spanner)
                  (interfaces . (font-interface
                                 multi-measure-interface
         (skyline-horizontal-padding . 0.2)
         (staff-padding . 0.25)
         (stencil . ,ly:text-interface::print)
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self)))))
-        (Y-offset . ,side-position-interface::y-aligned-side)
         (vertical-skylines . ,grob::unpure-vertical-skylines-from-stencil)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-extent . ,grob::always-Y-extent-from-stencil)
+        (Y-offset . ,side-position-interface::y-aligned-side)
         (meta . ((class . Spanner)
                  (interfaces . (font-interface
                                 multi-measure-interface
         (self-alignment-X . ,CENTER)
         (staff-padding . 0.25)
         (stencil . ,ly:text-interface::print)
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self)))))
-        (Y-offset . ,side-position-interface::y-aligned-side)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-extent . ,grob::always-Y-extent-from-stencil)
+        (Y-offset . ,side-position-interface::y-aligned-side)
         (meta . ((class . Spanner)
                  (interfaces . (font-interface
                                 percent-repeat-interface
         (stencil . ,ly:stem-tremolo::print)
         (style . ,ly:stem-tremolo::calc-style)
         (X-extent . ,ly:stem-tremolo::width)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-extent . ,(grob::unpure-Y-extent-from-stencil ly:stem-tremolo::pure-height))
-        (X-offset . ,(ly:make-simple-closure
-                      `(,+
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::centered-on-x-parent))
-                        ,(ly:make-simple-closure
-                          (list ly:self-alignment-interface::x-aligned-on-self)))))
         (Y-offset . ,(ly:make-unpure-pure-container ly:stem-tremolo::calc-y-offset ly:stem-tremolo::pure-calc-y-offset))
         (meta . ((class . Item)
                  (interfaces . (self-alignment-interface
         (padding . 0.3)
 
         (script-priority . 200)
+        ;; self-alignment cannot be LEFT because of fingering diagrams.
+        (self-alignment-X . #f)
         (side-axis . ,Y)
         (slur-padding . 0.5)
         (staff-padding . 0.5)
         (stencil . ,ly:text-interface::print)
         (vertical-skylines . ,grob::always-vertical-skylines-from-stencil)
-        ;; todo: add X self alignment?
         (Y-extent . ,grob::always-Y-extent-from-stencil)
-        (X-offset . ,ly:self-alignment-interface::x-aligned-on-self)
+        (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent)
         (Y-offset . ,side-position-interface::y-aligned-side)
         (meta . ((class . Item)
                  (interfaces . (font-interface