lilypond-user
[Top][All Lists]
Advanced

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

Re: Whiteout box function by Thomas Morley / need help


From: David Nalesnik
Subject: Re: Whiteout box function by Thomas Morley / need help
Date: Thu, 12 Jun 2014 12:58:49 -0500

Hi Karol,


On Thu, Jun 12, 2014 at 12:48 PM, Karol Majewski <address@hidden> wrote:
I'm trying to make this function work via \tweak. Grob-name string is no longer needed. The following code doesn't work. Perhaps I missed something that is obvious to schemers. Any ideas are welcome.

moreWhiteout =
#(define-music-function (parser location adds)(pair?)
  (define more-stencil-whiteout
    (lambda (grob)
      (let* ((function (assoc-get 'stencil
                            (reverse (ly:grob-basic-properties grob))))
             (stil
                   (if (and (procedure? function)
                            (not (eq? (procedure-name function)
                                      'more-stencil-whiteout)))
                       (function grob)
                       (begin
                         (ly:warning "~a has no stencil. Ignoring" grob)
                         #f))))
        (if stil
            (let*((x-ext (ly:stencil-extent stil X))
                  (y-ext (ly:stencil-extent stil Y))
                  (add-to-x-ext (if (pair? (car adds)) (car adds) adds))
                  (add-to-y-ext (if (pair? (cdr adds)) (cadr adds) '(0 . 0)))
                  (new-stil
                    (ly:make-stencil
                       (ly:stencil-expr stil)
                       (offset-add x-ext add-to-x-ext)
                       (offset-add y-ext add-to-y-ext))))
              (if (grob::has-interface grob 'dynamic-text-interface)
                  (let* ((new-stencil-length
                           (interval-length (ly:stencil-extent new-stil X)))
                         (orig-stencil-length
                           (interval-length (ly:stencil-extent stil X))))
                    (ly:grob-set-property! grob 'self-alignment-X
                      (if (not (= 0 (- new-stencil-length orig-stencil-length)))
                          (/ (- (- new-stencil-length (cdr add-to-x-ext))
                                (+ orig-stencil-length (cdr add-to-x-ext)))
                             new-stencil-length)
                          0))))
              new-stil)
            #f))))
  #{
    -\tweak layer #10
    -\tweak whiteout ##t
    -\tweak stencil #more-stencil-whiteout
  #})

%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%

\layout {
  \override DynamicText.extra-spacing-width = #'(+inf.0 . -inf.0)
}

musicI = { \time 2/4 \repeat unfold 16 b8 }

musicII = {
  r2
  b4 \moreWhiteout #'((-2 . 0.5)(0 . 2)) ^"XXXXXX"
  b
  r

  r^ \moreWhiteout #'((-3.2 . 4.12)(0 . 0)) \pppp
  b4 \moreWhiteout #'(-2 . 10.5) ^"XXXXXX" b
}

\new StaffGroup <<
  \new Staff \relative c'' \musicI
  \new Staff \relative c'' \musicII
>>


You might look to see how \shape is defined in ly/music-functions-init.ly.

HTH,
David  

reply via email to

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