On Fri, May 1, 2015 at 3:49 PM, David Nalesnik <david.nales...@gmail.com>
wrote:
>
>
> In other news:
>
> **Attached please find a version that handles tweaks and overrides. It
> will also deal with \temporary, too.**
>
Drat...wrong file!
>
\version "2.19"
override-color = #red
tweak-color = #blue
%tweak-color = #override-color
colorOverride =
#(define-music-function (parser location music) (ly:music?)
(music-map
(lambda (mus)
;; overrides
(if (and (music-is-of-type? mus 'context-specification)
(ly:music? (ly:music-property mus 'element)))
(let ((elt (ly:music-property mus 'element))
(context (ly:music-property mus 'context-type)))
(cond
((music-is-of-type? elt 'override-property-event)
(let* ((grob-name (ly:music-property elt 'symbol))
(prop-path (ly:music-property elt 'grob-property-path))
(once? (ly:music-property elt 'once))
; is the previous setting remembered?
(pop-first? (ly:music-property elt 'pop-first)))
(cond
; non-user overrides don't set property path
((null? prop-path) #{ #})
; \once \override
((eq? #t once?)
(set! mus
#{
\once \override #(list context grob-name 'color)
= #override-color
#mus
#}))
; \override
((eq? pop-first? #t)
(set! mus
#{
\override #(list context grob-name 'color)
= #override-color
#mus
#}))
; \temporary
((null? pop-first?)
(set! mus
#{
\temporary \override #(list context grob-name 'color)
= #override-color
#mus
#})))))
;; reverts
((and (music-is-of-type? elt 'layout-instruction-event)
(eq? (ly:music-property elt 'name) 'RevertProperty))
(let ((grob-name (ly:music-property elt 'symbol)))
(set! mus
#{
\revert #(list context grob-name 'color)
#mus
#})))))
;; tweaks
(let ((tweaks (ly:music-property mus 'tweaks)))
(if (pair? tweaks)
;(begin
(set! (ly:music-property mus 'tweaks)
(let loop ((tweaks tweaks) (result '()))
(cond
((null? tweaks) result)
; basic tweak:
; ( (font-size . 2) [...] )
((symbol? (caar tweaks))
(loop (cdr tweaks)
(append
result
(list (cons 'color tweak-color))
(list (car tweaks)))))
; 'directed' tweak:
; ( ((NoteHead . font-size) . 2) [...] )
(else
(loop (cdr tweaks)
(append
result
(list
(cons (cons (caaar tweaks) 'color) tweak-color))
(list (car tweaks))))))))
;(display (ly:music-property mus 'tweaks)) (newline)
;)
))
)
mus)
music)
music)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\displayMusic
\colorOverride
\new PianoStaff <<
\new Staff <<
\new Voice {
\voiceOne
c''4
\once \override NoteHead.after-line-breaking =
#(lambda (grob)
(let ((stil (ly:note-head::print grob)))
(set! (ly:grob-property grob 'stencil)
(ly:stencil-scale stil 1.5 1.5))))
d'' e''->
\override Voice.Stem.padding = 2
f''
g''1
}
\new Voice {
\voiceTwo
c'4 d'
\override Script.font-size = 3
e'-> f'->
\revert Script.font-size
g'1->
\override Staff.Clef.extra-offset = #'(0 . 5)
\oneVoice
\clef alto
\shape #'((0 . 0) (0 . 3) (0 . 3) (0 . 0)) Tie % \shape is \once
c'1~
\revert Staff.Clef.extra-offset
\clef treble
c'1~
c'1
\override NoteHead.font-size = 4
<c' c''>1
%\unfoldRepeats
\repeat volta 2 {
c'1
}
\override Score.BarLine.X-extent = #'(-3 . 3)
}
>>
\new Staff <<
\clef bass
\new Voice {
\voiceOne
c'4 d' e'->
\override Voice.Stem.padding = 2
f'
g'1\fermata
\oneVoice
\clef treble
c'
\clef alto
R1
\once \override Voice.MultiMeasureRest.Y-offset = -5
R1
R1
R1
}
\new Voice {
\voiceTwo
c4 d
\override Script.font-size = 3
e-> f->
g1->
}
>>
>>
%\displayMusic
\colorOverride
{
\tweak font-size 3
c'
\tweak NoteHead.font-size 3
\tweak Stem.thickness 2
c'2
<c' \tweak font-size 3 e'>
<\tweak NoteHead.font-size 3 c' e'>1
\override NoteHead.font-size = 4
c'1
\temporary \override NoteHead.font-size = 12
c'1
\revert NoteHead.font-size
c'1
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user