Dynamics with expressive text, like "p espressivo" are meant to have the
dynamic aligned on the notehead the same as ordinary dynamics, with the
expressive text following. Here is a snippet I've written to align custom
dynamics correctly.

\version "2.18.2"

\paper {
  ragged-right = ##f
  indent = 0\cm
}

dynText = #(define-event-function (parser location dyn expr) (markup?
markup?)
             (let* (
                     (mark #{ \markup { \dynamic $dyn \normal-text\italic
$expr } #})
                     (offset (lambda (grob)
                               (let* (
                                       (layout (ly:grob-layout grob))
                                       (props (ly:grob-alist-chain grob
                                                (ly:output-def-lookup layout
'text-font-defaults)))
                                       (target-X-extent
                                        (ly:stencil-extent
                                        
(ly:text-interface::interpret-markup layout props dyn)
                                         X))
                                       (width (abs
                                               (- (cdr target-X-extent) (car
target-X-extent))))
                                       )
                                 (display target-X-extent)
                                 (- 1 (/ width 2))
                                 )
                               )
                       )
                     )
               #{
                 \tweak DynamicText.X-offset #offset
                 #(make-dynamic-script mark) 
               #}
               )
             )

%% Example

\new Staff \with {
  \omit TimeSignature
} \relative c' {
  c1\dynText "p" "sub."
  c1\dynText "fff" "espressivo"
  c1\dynText "p" "espressivo"
  c1\dynText "fffff" "sub."
  \break
  c1\p
  c1\fff
  c1\p
  c1\fffff
}



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/snippet-to-properly-align-dynamics-with-expressive-text-tp204305.html
Sent from the User mailing list archive at Nabble.com.

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to