[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic alignment

From: Marek Klein
Subject: Re: dynamic alignment
Date: Wed, 15 Dec 2010 14:59:40 +0100

Hi Jan-Peter,

2010/12/13 Jan-Peter Voigt <address@hidden>
Hello list,

I wrote a script to align dynamics centered on the corresponding note:

\version "2.12.3"

% calculate x-alignment based on attribute text + dynamic text
#(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)))
           (* (-
                (/ (+ 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 some dynamics
pocof = #(make-dynamic-script (markup #:center-dyn "poco" "f"))
menof = #(make-dynamic-script (markup #:center-dyn "meno" "f"))
subp = #(make-dynamic-script (markup #:center-dyn "subito" "p"))

% activate X-offset, so that halign works
dynx = #(define-music-function (parser location musik)(ly:music?)
   \override DynamicText #'X-offset = #0 $musik \revert DynamicText #'X-offset

%%%%% example %%%%%
 \new Staff <<
   \relative c'' {
     d \dynx c\pocof d e | d\ff d cis eis ~ | \dynx eis1\subp | r4 \dynx b\menof c\f

This script first calculates the widthes of the "attribute"-text (wa) and the dynamic text (wd), so that I can calculate the right \halign value:
halign = ((wa + (wd / 2)) / (wa + wd) - 0.5) * 2

Then I use a markup with \halign. This works quite well as long DynamicText #'X-offset is set! If that is set all other dynamics are aligned badly.
So I wrote a little function, that sets and unsets (reverts) that value to let the halign work.

My question is:
Is it possible to set that value inside the make-dynamic-script or align it some other way, so that I can simply use my defined \pocof (etc.) without switching X-offset on and off?

I can not answer your question, but it is probably better placed on lilypond-devel (cc-ing).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]