From 47236e0a7a5a75d5dd2be521c44102b20d8c76ce Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Wed, 28 Dec 2011 10:00:14 +0100 Subject: [PATCH] Centers DynamicText grobs in Dynamics context on the NoteColumns of 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). --- .../dynamics-text-dynamics-context.ly | 35 +++++++++++++++++++ lily/include/self-alignment-interface.hh | 1 + lily/self-alignment-interface.cc | 22 ++++++++++++ ly/engraver-init.ly | 7 ++++ 4 files changed, 65 insertions(+) create mode 100644 input/regression/dynamics-text-dynamics-context.ly diff --git a/input/regression/dynamics-text-dynamics-context.ly b/input/regression/dynamics-text-dynamics-context.ly new file mode 100644 index 0000000000..3c98ff2cd7 --- /dev/null +++ b/input/regression/dynamics-text-dynamics-context.ly @@ -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 + } + >> + >> +} diff --git a/lily/include/self-alignment-interface.hh b/lily/include/self-alignment-interface.hh index 80a7c0d37a..1a5099d2a2 100644 --- a/lily/include/self-alignment-interface.hh +++ b/lily/include/self-alignment-interface.hh @@ -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)); diff --git a/lily/self-alignment-interface.cc b/lily/self-alignment-interface.cc index a6fde153e0..edf0b2395d 100644 --- a/lily/self-alignment-interface.cc +++ b/lily/self-alignment-interface.cc @@ -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 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) diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index d1f43f79fe..0a372ce2d9 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -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." -- 2.39.2