From 8abb84c2bf30e32702ecd274df7bfa114f0d851f Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Thu, 31 Oct 2013 21:15:06 +0100 Subject: [PATCH] Make Dynamics into a Staff-like context. This commit creates a DynamicsVoice context, and moves the former Dynamics context to a higher (Staff-like) level. This should allow to assign variables that contain polyphonic sections without unintended side effects (such as additional Voice and Staff contexts being created whenever a VoiceSeparator \\ is entered). --- input/regression/dynamics-polyphony.ly | 42 ++++++++++++++++++++++++++++++++++ ly/engraver-init.ly | 27 +++++++++++++++------- 2 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 input/regression/dynamics-polyphony.ly diff --git a/input/regression/dynamics-polyphony.ly b/input/regression/dynamics-polyphony.ly new file mode 100644 index 0000000..898913e --- /dev/null +++ b/input/regression/dynamics-polyphony.ly @@ -0,0 +1,42 @@ +\version "2.17.30" + +\header { + texidoc = "The Dynamics context can handle multiple voices, +even though it may lead to collisions." +} + +music = \relative c' { + f2\mp c' | + << % Creating two temporary DynamicsVoice contexts. + { bes8\> c d bes a2\p } + \\ + { g\sfz f } % collides with the spanner. + >> +} + +% The actual staves will be printed without dynamics. +#(define (dynamic? x) + (let ((name (ly:music-property x 'name))) + (or + (eq? name 'DynamicEvent) + (eq? name 'AbsoluteDynamicEvent) + (eq? name 'CrescendoEvent) + (eq? name 'DecrescendoEvent) + (eq? name 'SpanDynamicEvent)))) + +removeDynamics = +#(define-music-function (parser location music) (ly:music?) + (music-filter + (lambda (x) + (not (dynamic? x))) + music)) + +\score { + \new PianoStaff << + \new Staff \removeDynamics \music + \new Dynamics \music + \new Staff \removeDynamics { + \clef bass \transpose c c, \music + } + >> +} diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 9c8547d..27381b3 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -16,7 +16,7 @@ %%%% You should have received a copy of the GNU General Public License %%%% along with LilyPond. If not, see . -\version "2.17.29" +\version "2.17.30" \context { \name "Global" @@ -391,7 +391,7 @@ a collection of staves, with a bracket in front and spanning bar lines." \context { \type "Engraver_group" - \name Dynamics + \name DynamicsVoice \alias Voice \consists "Output_property_engraver" \consists "Bar_engraver" @@ -402,14 +402,9 @@ a collection of staves, with a bracket in front and spanning bar lines." \consists "Text_engraver" \consists "Text_spanner_engraver" \consists "Font_size_engraver" - \consists "Axis_group_engraver" pedalSustainStrings = #'("Ped." "*Ped." "*") pedalUnaCordaStrings = #'("una corda" "" "tre corde") - \override VerticalAxisGroup.staff-affinity = #CENTER - \override VerticalAxisGroup.nonstaff-relatedstaff-spacing = - #'((basic-distance . 5) - (padding . 0.5)) \override TextScript.font-shape = #'italic \override DynamicLineSpanner.Y-offset = #0 \override DynamicLineSpanner.outside-staff-priority = ##f @@ -423,11 +418,27 @@ a collection of staves, with a bracket in front and spanning bar lines." ,(ly:make-simple-closure (list ly:self-alignment-interface::x-aligned-on-self)))) + \description "Corresponds to the dynamics of a single voice. +Using the upper-level Dynamics context as a wrapper is preferred, +since it can handle polyphonic variables as well." +} + +\context { + \type "Engraver_group" + \name "Dynamics" + \alias "Staff" + \accepts "DynamicsVoice" + \defaultchild "DynamicsVoice" + \consists "Axis_group_engraver" + \override VerticalAxisGroup.staff-affinity = #CENTER + \override VerticalAxisGroup.nonstaff-relatedstaff-spacing = + #'((basic-distance . 5) + (padding . 0.5)) + \description "Holds a single line of dynamics, which will be centered between the staves surrounding this context." } - \context{ \type "Engraver_group" -- 1.8.3.1