lilypond-user
[Top][All Lists]

Re: difficulty implementing grob-suicide! for spanned bendAfter

 From: Mark Polesky Subject: Re: difficulty implementing grob-suicide! for spanned bendAfter Date: Thu, 9 Jul 2009 21:47:42 -0700 (PDT)

Mike Solomon wrote:
> Hey lilypond-users,
>     I am working on a piece with lots of beams/events across
> staves, many of which have bendAfter attached to them.  The
> spanned bend after clashes with some other stuff in the work, so
> I wanted to kill it w/ a callback function, but after having
> written the bit of code below I came to realize that this didn't
> exist as I was conceiving it (should have checked the docs
> first...). Taking a peek at the code below, do any of you have
> suggestions for how I could make this work?

Mike, I *do* want to be encouraging, but you really have to format
the scheme code. It's really hard to read, and the good developers
are not going to waste their time rewriting it.

*Please* do something more like this:

#(define (bendcallback grob)
(let* ((orig (ly:grob-original grob))
(siblings (if (ly:grob? orig)
(ly:spanner-broken-into orig)
'())))
(begin
(format #t "I will print if this function is called.\n")
(if (>= (length siblings) 2)
(if (not (eqv? grob (car siblings)))
(ly:grob-suicide! grob))))))

I can understand this in about 30 seconds. It would take me about
2 or 3 minutes to understand it the way you have it formatted. It's
quicker for me to rewrite it than to try to figure it out the way
you have it. But ultimately it's not worth my time to rewrite it.

If you have trouble finding matching parentheses, use an editor
with bracket matching. Personally I use LilyPondTool (there are
others as well) - I can put the cursor to the right of a ")", do
"<ctrl>-]" and it takes me to the matching "(".

Also, the code didn't compile - there's an error on this line:
\bendAfter #-3 c1 \bendAf

1) This:
\score {{ \new Staff {
\relative c'' { ...

can be simplified to this:
\score {
\new Staff \relative c'' {
...

2) This:
\override Voice . BendAfter #'after-line-break =
#(lambda (grob) (bendcallback grob))

can be simplified to this:
\override Voice.BendAfter #'after-line-break = #bendcallback

3) An initial quarter rest followed by whole notes doesn't fit the
time signature. Either remove the "r4" or add "\partial 4".

4) You can automate repetitive input this way:
\repeat unfold 45 { \bendAfter #-3 c1 }

5) The \layout block goes *inside* the \score block.

7) Before you post to the mailing list, always do a final
test compile to make sure what you're sending compiles!

___________________________________

So here's my rewrite:

\version "2.13.0"

#(define (bendcallback grob)
(let* ((orig (ly:grob-original grob))
(siblings
(if (ly:grob? orig)
(ly:spanner-broken-into orig)
'())))
(begin
(format #t "I will print if this function is called.\n")
(if (>= (length siblings) 2)
(if (not (eqv? grob (car siblings)))
(ly:grob-suicide! grob))))))

\score {
\new Staff \relative c'' {
\override Voice.BendAfter #'after-line-break = bendcallback
\repeat unfold 45 { \bendAfter #-3 c1 }
}
\layout {
\context {
\Voice
\remove "Forbid_line_break_engraver"
}
}
}

I'm only doing this so that you see what it should look like.
I understand that a lot of the coding stuff is tricky; there
are a lot of things that are easy for a beginner to forget and
many useful tricks that a beginner just doesn't know yet. Most
of us are more than happy to help out with those things.

But we can't and won't keep rewriting code!

still problems with the code. But I think proper formatting is
more important than you realize. In terms of content, I'm
actually fairly impressed -- you're tackling some ambitious
concepts.

Okay, I'm sure someone can take over where I've left off...
If not, I'll try to help some more later.

- Mark