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).
--- /dev/null
+\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
+ }
+ >>
+ >>
+}
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));
#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"
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)
(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."