[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: accessing accidentals with \tweak
From: |
Mark Polesky |
Subject: |
Re: accessing accidentals with \tweak |
Date: |
Wed, 15 Jul 2009 11:56:42 -0700 (PDT) |
Carl Sorensen wrote:
> What if a property like tweak-callback were added, whose job is
> just to trigger the grob callback necessary for what you want to
> do?
>
> Then you could have
> \relative {
> <c! \tweak #'tweak-callback #color-accidental e! g!>
> }
>
> I think you could have multiple calls to #'tweak-callback,
> because all of the tweaks are stored in a list, and would all be
> executed.
>
> \displayMusic
> \relative {
> <c
> \tweak #'color #red
> \tweak #'color #yellow
> d>
> }
Unfortunately this doesn't seem to work. See attached PNG and
console output below. When using this "indirect" tweaking method,
only the *last* tweak affects the typeset output. The desired
output in the example below is to have both E-naturals colored red
and reduced in size. The first one is reduced but not colored; the
second one is colored, but not reduced.
It seems to me that a satisfactory resolution of this issue will
have significant implications for my LilyPond projects, so
hopefully someone can help me find the answer!
Thanks so much.
- Mark
____________________
\version "2.13.2"
#(define (color-accidental note-grob color)
;; notehead before-line-breaking callback
(let ((accidental (ly:grob-object note-grob 'accidental-grob)))
(if (not (null? accidental))
(ly:grob-set-property! accidental 'color color))))
#(define (resize-accidental note-grob fontsize)
;; notehead before-line-breaking callback
(let ((accidental (ly:grob-object note-grob 'accidental-grob)))
(if (not (null? accidental))
(ly:grob-set-property! accidental 'font-size fontsize))))
\relative {
<c!
\tweak #'before-line-breaking
#(lambda (grob) (color-accidental grob red))
\tweak #'before-line-breaking
#(lambda (grob) (resize-accidental grob -3)) e!>
\displayMusic
<c!
\tweak #'before-line-breaking
#(lambda (grob) (resize-accidental grob -3))
\tweak #'before-line-breaking
#(lambda (grob) (color-accidental grob red)) e!>
}
____________________
(make-music
'EventChord
'elements
(list (make-music
'NoteEvent
'duration
(ly:make-duration 2 0 1 1)
'force-accidental
#t
'pitch
(ly:make-pitch -1 0 0))
(make-music
'NoteEvent
'duration
(ly:make-duration 2 0 1 1)
'tweaks
(list (cons 'before-line-breaking
#<procedure #f (grob)>)
(cons 'before-line-breaking
#<procedure #f (grob)>))
'force-accidental
#t
'pitch
(ly:make-pitch -1 2 0))))
accidental-tweaks.png
Description: PNG image