[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Center-aligning objects in Scheme - slight improvement
From: |
Trevor Bača |
Subject: |
Re: Center-aligning objects in Scheme - slight improvement |
Date: |
Thu, 15 Mar 2007 18:53:07 -0500 |
On 3/15/07, Mats Bengtsson <address@hidden> wrote:
I polished the function a bit further:
hairpinWithCenteredText = #(define-music-function
(parser location text) (markup?)
#{
\override Voice.Hairpin #'stencil = #(lambda (grob)
(ly:stencil-aligned-to
(ly:stencil-combine-at-edge
(ly:stencil-aligned-to (ly:hairpin::print grob) X CENTER)
Y
DOWN
(ly:stencil-aligned-to (ly:text-interface::print grob) X CENTER))
X LEFT))
\override Voice.Hairpin #'text = $text
#})
/Mats
Maximilian Albert wrote:
>Hi again,
>
>below is a slight improvement of the previous version which saves you
>from typing the whole function definition over and over again just to
>change the markup text. The function 'hairpinWithCenteredText' takes a
>single markup as argument. The usage should be straightforward (see the
>example).
>
>Max
>
>
>%%% begin code %%%
>
>hairpinWithCenteredText = #(define-music-function
> (parser location text) (markup?)
>#{
> \override Voice.Hairpin #'stencil = #(lambda (grob)
> (let ((ext (ly:stencil-extent (ly:hairpin::print grob) 0)))
> (ly:stencil-combine-at-edge
> (ly:stencil-aligned-to (ly:hairpin::print grob) 0 -1)
> 1
> -1
> (ly:stencil-translate-axis
> (ly:stencil-aligned-to (ly:text-interface::print grob) 0 0)
> (/ (- (cdr ext) (car ext)) 2)
> 0))))
> \override Voice.Hairpin #'text = $text
>#})
>
>hairpinMolto = \hairpinWithCenteredText \markup {\italic "molto"}
>hairpinMore = \hairpinWithCenteredText \markup {\bigger "moltissimo"}
>
>\new Staff {
> \hairpinMolto c'2\< c'2\f
> \hairpinMore c'2\< c'2\f
>}
>
>%%% end code %%%
Nice work, Mats and Max :-)
FWIW, I'd love it if this one patched its way into the next release ...
;-)
--
Trevor Bača
address@hidden