[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: |
Thomas Morley |
Subject: |
Re: Can you determine why a grob is being typeset in scheme? |
Date: |
Tue, 21 Apr 2015 00:30:41 +0200 |
2015-04-21 0:21 GMT+02:00 Thomas Morley <address@hidden>:
> 2015-04-20 23:45 GMT+02:00 David Nalesnik <address@hidden>:
>> 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
>
>
>
> Or maybe:
>
> \version "2.19.18"
>
> clef-color-engraver =
> #(lambda (context)
> (let ((clef-props '()))
>
> `((acknowledgers
> (clef-interface
> . ,(lambda (engraver grob source-engraver)
> (let* ((clefGlyph (ly:context-property context 'clefGlyph))
> (clefPosition (ly:context-property context 'clefPosition))
> (clefTransposition
> (ly:context-property context 'clefTransposition 0))
> (new-clef-props
> (list clefGlyph clefPosition clefTransposition)))
> ;(display (equal? clef-props new-clef-props))
> (if (and (not (equal? clef-props new-clef-props))
> ;; to have the first clef colored as well
> ;; comment next line
> (not (null? clef-props))
> )
> (set! (ly:grob-property grob 'color) red))
>
> (set! clef-props new-clef-props))))))))
>
> %%%%%%%%%%%%%%%
> %% EXAMPLE
> %%%%%%%%%%%%%%
>
> \layout {
> \context {
> \Staff
> \consists #clef-color-engraver
> }
> }
> <<
> {
> \clef bass
> R1
> \break
> R1
>
> \clef alto
> R1
> \break
> \clef "G"
> R1
> \clef "G_8"
> R1
> \break
> R1
> \break
> R1
> }
>
> {
> R1
> \break
> R1
> R1
> \break
> \clef "mensural-c3"
> R1
> \clef "alto"
> R1
> \break
> R1
> \break
> R1
> }
>>>
>
>
> Cheers,
> Harm
Didn't know 'non-default myself :(
For the record, with this the engraver could be shortened to:
clef-color-engraver =
#(lambda (context)
(let ((clef-props '()))
`((acknowledgers
(clef-interface
. ,(lambda (engraver grob source-engraver)
(if (boolean? (ly:grob-property grob 'non-default))
(set! (ly:grob-property grob 'color) red))))))))
Cheers,
Harm