Hello everyone! I'm trying to use make-dynamic-script to engrave dynamic marks that also have some kind of text (for example: p dolce, etc) and have them behave consistently with other dynamic marks.
The problem is that I have a difficult time aligning them correctly, as you can see in the example I uploaded (both .ly and .pdf). In the first example, I write a function and tweaked the X-offset of its output so that it would behave like I want, but it only works with scripts that start with either p or f. This approach would require making different functions for every dynamic that I'm going to use. I'm also concerned that if I change layout settings later I'm going to have to tweak everything again. In the second example I attempted to make a function that can calculate the tweaking, modifying this snippet <http://lsr.di.unimi.it/LSR/Item?id=739>. As you can see it's not working as intended. I checked the math a few times and I think it should be right (although I'm sure that I can be wrong on this), and that makes me think that there is something else going on that prevents me from achieving the results I want. How can I solve this issue so that I can have a generic function that corrects the tweaking by itself? Any help with this issue will be greatly appreciated.
\version "2.19.53"
%This method aligns correctly but requires writing different tweaks for each dynamic type
dynSingleText = #(define-event-function (dyn text) (string? markup?)
#{
\tweak X-offset #-0.09
#(make-dynamic-script
(markup #:dynamic dyn #:normal-text #:italic (string-append " " text)))
#} )
pdolce = \dynSingleText "p" "dolce"
pdolcee = \dynSingleText "p" "dolceeeeeeeeeeeeeeeeeeeee"
\score { <<
\new Staff {
\relative c' { c\p d e f } }
\new Staff {
\relative c' { c\pdolce d e f } }
\new Staff {
\relative c' { c\pdolcee d e f } }
\new Staff \with { \magnifyStaff #5/7 } {
\relative c' { c\pdolce d e f } }
>> }
%This method calculates the center of the dynamic, but the results are off
#(define-markup-command (center-dyn-text layout props dyn atr-text) (string? markup?)
(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
(- (/ dyn-x (+ atr-x dyn-x)) 1)))
(interpret-markup layout props
(markup
#:halign x-align
#:concat (#:dynamic dyn #:normal-text #:italic text)))))
#(define (make-dynamic-atr-script dyn atr)
(let* ((dynamic (make-dynamic-script (markup #:center-dyn-text dyn atr))))
#{ \tweak X-offset 0 $dynamic #}))
pdolce = #(make-dynamic-atr-script "p" "dolce")
pdolcee = #(make-dynamic-atr-script "p" "dolceeeeeeeeeeeeeeeeeeeee")
\score { <<
\new Staff {
\relative c' { c\p d e f } }
\new Staff {
\relative c' { c\pdolce d e f } }
\new Staff {
\relative c' { c\pdolcee d e f } }
\new Staff \with { \magnifyStaff #5/7 } {
\relative c' { c\pdolce d e f } }
>> }
aligning dynamics.pdf
Description: Adobe PDF document
_______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
