[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Better slashed graces
From: |
David Nalesnik |
Subject: |
Re: Better slashed graces |
Date: |
Mon, 19 Dec 2016 15:07:42 -0600 |
On Mon, Dec 19, 2016 at 1:32 PM, Gilberto Agostinho
<address@hidden> wrote:
> Hi David,
>
> First of all, thanks for your reply and for your help!
>
>
> David Nalesnik wrote
>> The problem is that there is no Beam grob, so an error is raised when
>> you query its properties.
>
> I see!
>
>
>> Following is a simple way to use substitute values when there is no Beam
>> object.
>
> This modified function does compile, but actually it's not doing what it's
> supposed to do in the case of single notes: for that, LilyPond already
> slashes them, so now the function is attempting to add a second slash, see:
>
> <http://lilypond.1069038.n5.nabble.com/file/n198193/33.png>
>
> That's what I said about the conditional,
You simply wrote that the file wouldn't compile. Unfortunately, my
eyesight seems to be worse than I thought, and I missed the second
slash.
I think the function needs
> something like "if there is a beam, then add a slash, else if no beam then
> no slash". Do you think you could give me a hand with that?
Sure, that's no problem. And it looks a bit cleaner than what I went
in the last reply:
slash =
#(define-music-function (parser location ang stem-fraction protrusion)
(number? number? number?)
(remove-grace-property 'Voice 'Stem 'direction)
#{
\once \override Stem #'stencil =
#(lambda (grob)
(let* ((x-parent (ly:grob-parent grob X))
(is-rest? (ly:grob? (ly:grob-object x-parent 'rest)))
(beam (ly:grob-object grob 'beam))
(stil (ly:stem::print grob)))
(cond
(is-rest? empty-stencil)
((ly:grob? beam)
(let* ((refp (ly:grob-system grob))
(stem-y-ext (ly:grob-extent grob grob Y))
(stem-length (- (cdr stem-y-ext) (car stem-y-ext)))
(beam-X-pos (ly:grob-property beam 'X-positions))
(beam-Y-pos (ly:grob-property beam 'positions))
(beam-slope (/ (- (cdr beam-Y-pos) (car beam-Y-pos))
(- (cdr beam-X-pos) (car beam-X-pos))))
(beam-angle (atan beam-slope))
(dir (ly:grob-property grob 'direction))
(line-dy (* stem-length stem-fraction))
(line-dy-with-protrusions (if (= dir 1)
(+ (* 4 protrusion) beam-angle)
(- (* 4 protrusion)
beam-angle)))
(ang (if (> beam-slope 0)
(if (= dir 1)
(+ (degrees->radians ang) (* beam-angle 0.7))
(degrees->radians ang))
(if (= dir 1)
(degrees->radians ang)
(- (degrees->radians ang) (* beam-angle 0.7)))))
(line-dx (/ line-dy-with-protrusions (tan ang)))
(protrusion-dx (/ protrusion (tan ang)))
(corr (if (= dir 1) (car stem-y-ext) (cdr stem-y-ext))))
(ly:stencil-add
stil
(grob-interpret-markup grob
(markup
;#:with-color red
#:translate
(cons (- protrusion-dx)
(+ corr
(* dir
(- stem-length (+ stem-fraction protrusion)))))
#:draw-line
(cons line-dx
(* dir line-dy-with-protrusions)))))))
(else stil))))
#})
>
> Thanks a lot once again, I really appreciate your help!
>
You're welcome!
David
Re: Better slashed graces, Andrew Bernard, 2016/12/19