]> git.donarmstrong.com Git - lilypond.git/commitdiff
Centers DynamicText grobs in Dynamics context on the NoteColumns of
authorMike Solomon <mike@apollinemike.com>
Wed, 28 Dec 2011 09:00:14 +0000 (10:00 +0100)
committerMike Solomon <mike@apollinemike.com>
Wed, 28 Dec 2011 09:00:14 +0000 (10:00 +0100)
a PaperColumn.

Should be tweaked later to filter out NoteColumns in non-pertinent
contexts (for example, in an orchestral score, a Dynamics context in
a PianoStaff should not be influenced by the flute part).

input/regression/dynamics-text-dynamics-context.ly [new file with mode: 0644]
lily/include/self-alignment-interface.hh
lily/self-alignment-interface.cc
ly/engraver-init.ly

diff --git a/input/regression/dynamics-text-dynamics-context.ly b/input/regression/dynamics-text-dynamics-context.ly
new file mode 100644 (file)
index 0000000..3c98ff2
--- /dev/null
@@ -0,0 +1,35 @@
+\version "2.15.24"
+
+\header {
+  texidoc = "The @code{X-offset} of @code{DynamicText} grobs in a
+@code{Dynamics} context should be averaged over the center of
+@code{NoteColumn} grobs in the @code{DynamicText}'s @code{PaperColumn}.
+"
+}
+
+\score {
+  <<
+    \new PianoStaff <<
+      \new Staff = "up" {
+        \clef treble
+        \relative c' {
+          c4\p c c\mp c |
+          c4\mf c c\f c |
+          <<
+            \repeat unfold 8 c4
+            \new Dynamics = "dynamics" \with {
+              alignBelowContext = "up"
+            } {
+              s4\p s s\mp s |
+              s4\mf s s\f s
+            }
+          >>
+        }
+      }
+      \new Staff = "down" {
+        \clef bass
+        \repeat unfold 16 c4
+      }
+    >>
+  >>
+}
index 80a7c0d37ac9d8511b6557fe89f8cf889caf8881..1a5099d2a2475ca3d5bbd69a0b6815ab00139b14 100644 (file)
@@ -40,6 +40,7 @@ struct Self_alignment_interface
 
   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 (x_centered_on_y_parent, (SCM element));
index a6fde153e043e826b4865c467c3267d6bdeb1685..edf0b2395dbd6a533255a921cf8c17037e634519 100644 (file)
@@ -23,6 +23,7 @@
 #include "grob.hh"
 #include "grob-array.hh"
 #include "interval-minefield.hh"
+#include "note-column.hh"
 #include "paper-column.hh"
 #include "pointer-group-interface.hh"
 #include "warn.hh"
@@ -79,6 +80,27 @@ 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)
index d1f43f79fe0266a9f5262b47a0ba484faa98e89e..0a372ce2d9878796a377e05569f4f71469c746b2 100644 (file)
@@ -410,6 +410,13 @@ a collection of staves, with a bracket in front and spanning bar lines."
        (padding . 0.5))
   \override TextScript #'font-shape = #'italic
   \override DynamicLineSpanner #'Y-offset = #0
+  \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."