\version "2.15.43" \include "english.ly" % calculate x-alignment based on attribute text + dynamic text % this has to be a markup-command to get stencil-extent based on (interpret-markup layout props ...) #(define-markup-command (center-dyn layout props atr-text dyn)(markup? string?) "x-align on center of dynamic" (let* ( (text (string-append atr-text " ")) (atr-stencil (interpret-markup layout props (markup #:normal-text #:italic text))) (dyn-stencil (interpret-markup layout props (markup #:dynamic dyn))) (atr-x-ext (ly:stencil-extent atr-stencil X)) (dyn-x-ext (ly:stencil-extent dyn-stencil X)) (atr-x (- (cdr atr-x-ext)(car atr-x-ext))) (dyn-x (- (cdr dyn-x-ext)(car dyn-x-ext))) (x-align (* (- (/ (+ atr-x (/ dyn-x 2)) (+ atr-x dyn-x) ) 0.5) 2) ) ) (interpret-markup layout props (markup #:halign x-align #:concat (#:normal-text #:italic text #:dynamic dyn))) )) % define a 'new' attributed dynamic script #(define (make-atr-dynamic-script atr dyn) (let ((dynamic (make-dynamic-script (markup #:center-dyn atr dyn)))) (ly:music-set-property! dynamic 'tweaks (acons 'X-offset 0 (ly:music-property dynamic 'tweaks))) dynamic)) % define some attributed dynamics pocof = #(make-atr-dynamic-script "poco" "f") menof = #(make-atr-dynamic-script "meno" "f") submf = #(make-atr-dynamic-script "subito" "mf") % Solution 1: Using a simple markup with a particular halign value % Drawback: It's a markup, not a dynamic command, so \dynamicDown % etc. will have no effect semppMarkup = \markup { \halign #1.4 \italic "subito" \dynamic "mf" } % Solution 2: Using a dynamic script & shifting with % \once \override ... #'X-offset = .. % Drawback: \once \override needed for every invocation semppK = #(make-dynamic-script (markup #:line (#:normal-text #:italic "subito" #:dynamic "mf"))) % Solution 3: Padding the dynamic script so the center-alignment % puts it at the correct position % Drawback: the padding really reserves the space, nothing else can be there semppT = #(make-dynamic-script (markup #:line (#:normal-text #:italic "subito" #:dynamic "mf" #:hspace 7.1))) % Solution 4: Dynamic, setting the dimensions of the additional text to 0 % Drawback: To lilypond "sempre" has no extent, so it might put % other stuff there => collisions % Drawback: Also, there seems to be some spacing, so it's not exactly the % same alignment as without the additional text semppM = #(make-dynamic-script (markup #:line (#:with-dimensions '(0 . 0) '(0 . 0) #:right-align #:normal-text #:italic "subito" #:dynamic "mf"))) % Solution 5: Dynamic with explicit shifting inside the scheme function semppG = #(make-dynamic-script (markup #:hspace 0 #:translate '(-18.85 . 0) #:line (#:normal-text #:italic "subito" #:dynamic "mf"))) % Solution 6: Dynamic with explicit alignment. This has only effect % if one sets X-offset! % Drawback: One needs to set DynamicText #'X-offset! % Drawback: Aligned at the right edge of the additional text, % not at the center of pp semppMII = #(make-dynamic-script (markup #:line (#:right-align #:normal-text #:italic "subito" #:dynamic "mf"))) \relative c'' { \time 3/4 d2.\mf\> | a2 d8\!\smf( e) | R2. d2.\mf\> | a2 d8\!-\markup{ \italic \tiny subito } \mf( e) | R2. \textLengthOn d2.\mf\> | a2 d8\!-\markup{ \italic \tiny subito \dynamic mf}( e) | \textLengthOff % uncomment the textLengthOn to see if it makes a difference %\textLengthOn % http://lsr.dsi.unimi.it/LSR/Item?id=739 R2. d2.\mf\> | a2 d8\!-\submf( e) | % http://lsr.dsi.unimi.it/LSR/Item?id=393 % Solution 1 R2. d2.\mf\> | a2 d8\!-\semppMarkup( e) | % Solution 2 R2. d2.\mf\> | a2 d8\!-\semppK( e) | % Solution 3 R2. d2.\mf\> | a2 d8\!-\semppT( e) | % Solution 4 R2. d2.\mf\> | a2 d8\!-\semppM( e) | % Solution 5 R2. d2.\mf\> | a2 d8\!-\semppG( e) | % Solution 6 R2. d2.\mf\> | a2 d8\!-\semppMII( e) | }