lilypond-user
[Top][All Lists]
Advanced

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

Re: Can you determine why a grob is being typeset in scheme?


From: David Nalesnik
Subject: Re: Can you determine why a grob is being typeset in scheme?
Date: Mon, 20 Apr 2015 16:45:24 -0500

Hi Steven,

On Mon, Apr 20, 2015 at 3:40 PM, Steven Weber <address@hidden> wrote:

Since I always highlight clef changes in my music and I have access to a color printer, I thought it’d be more efficient to let Lilypond do the highlighting for me.  I wrote a handy function that places a filled-box behind the clef grob, and it works great, as long as I add it manually for every clef change.   What I really want is to add this to the Staff context so I never have to think about it again.  So I created an override function for the Staff.Clef.stencil which does the same thing as my manual function and again, it does highlight the clefs.  Unfortunately, it highlights every single clef (i.e., all the clefs at the beginning of the staves, not just the clef changes), which is overkill and defeats the purpose of highlighting things I need to pay attention to.

 

Is there a way in scheme to say “is this grob being typeset because of an explicit command (\clef bass), or implicitly (because of a line break)”?

 


I can think of two ways to go about this.  Hopefully the first gives you what you want, because the second will take some doing.

Breakable items like clefs have directions attached depending on where they are: -1 means end of line, 0 unbroken, and 1 beginning of line.  You can use the function ly:item-break-dir like so:

\version "2.19"

#(define highlight
   (lambda (grob)
     (let ((ibd (ly:item-break-dir grob)))
       (if (= ibd 1) black green))))

{
  \override Staff.Clef.color = #highlight
  
  c' d' e' f'
  \clef bass
  c d e f
  \break
  c d e f
  \clef treble
  c' d' e' f'
  \break
  c' d' e' f'
  \clef bass
  \break
  c d e f
}


%%%

One drawback here would be if you want to highlight both the cautionary clef and the beginning-of-line clef at the end of the example...  To do that and not catch other beginning-of-line clefs, we would have to use the other method, which is to insert the override into the music _expression_.

I'm going to drop out at this point :)   But, as a head start, compare the results of running the following with the override left in or commented out:

\displayMusic {
  c'
  %\override Staff.Clef.color = #highlight
  \clef bass
  c
}

The extending manual discusses this sort of manipulation with respect to music functions.  There are other useful commands like map-some-music which crop up periodically on the lists.  

Hope this is useful--

David
 


reply via email to

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