Hi Paolo,
The main problem here is that \tweak can only modify the object that is
next to it, so you can tweak a NoteHead to modify an automatic beam, but to
modify a beam that is created manually because of a [ in the input you need
to place the tweak before the [. See:
%%%%%%%%%%%%%%%%%
\version "2.19.83"
\relative {
c'8[ \tweak Beam.color #red d] %doesn't work
\tweak Beam.color #red e f %works
\tweak Beam.color #red g[ a] %doesn't work
b -\tweak Beam.color #red [ c ] %works
}
%%%%%%%%%%%%%%%%%
That said, I modified the function you sent so that it also considerds
NoteEvents and modifies the automatically created beams with the desired
properties:
%%%%%%%%%%%%%%%%%
\version "2.19.83"
token = #(let* ((ctr 0)
(ctr! (lambda ()
(set! ctr (1+ ctr))
ctr)))
(define-music-function (mus) (ly:music?)
(let* ((id (format #f "foobar_~a" (ctr!)))
(type (ly:music-property mus 'name))
(mexp (case type
((BeamEvent NoteEvent)
#{ \tweak Beam.after-line-breaking #(lambda (grob)
(let* ((outprop (ly:grob-property grob
'output-attributes))
(beam-thickness (ly:grob-property grob
'beam-thickness))
(outprop (append outprop
`((beam-thickness . ,beam-thickness)))))
;(display (format #f "\n****\n~a\n****\n"
beam-thickness))
(ly:grob-set-property! grob 'output-attributes
outprop)))
\tweak Beam.output-attributes.id #id #mus #} )
(else #{ \tweak output-attributes.id #id #mus #} ))))
mexp)))
\relative { c'4 d8-\token [ e ] \token f g c,4 }
%%%%%%%%%%%%%%%%%
The code could be cleaner I think, I'll try to improve it if I get some
free time. Meanwhile I hope this helps
El dom., 22 dic. 2019 a las 7:58, Paolo Prete (<[email protected]>)
escribió:
> Hello all.
>
> the following function (thanks to Stefano!) inserts the beam-thickness
> property of a Beam in the list of output-attributes of the corresponding
> SVG item. It does its job if I place the function soon before a beam symbol
> "[". But it doesn't work (no errors, but the output-attributes property is
> not set) if place it before a notename. How can I fix that? Should I
> map-some-music() and iterate until I find the BeamEvent? I tried that too,
> but without success.
> Thanks.
>
> token = #(let* ((ctr 0)
> (ctr! (lambda ()
> (set! ctr (1+ ctr))
> ctr)))
> (define-music-function (mus) (ly:music?)
> (let* ((id (format #f "foobar_~a" (ctr!)))
> (mexp #{ \tweak output-attributes.id #id #mus #} )
> (type (ly:music-property mus 'name))
> (mexp (case type
> ('BeamEvent
> #{ \tweak Beam.after-line-breaking #(lambda (grob)
> (let* ((outprop (ly:grob-property grob
> 'output-attributes))
> (beam-thickness (ly:grob-property grob
> 'beam-thickness))
> (outprop (append outprop
> `((beam-thickness . ,beam-thickness)))))
> (begin
> (ly:grob-set-property! grob
> 'output-attributes outprop)
> (display "\n****\n")
> (display beam-thickness)
> (display "\n****\n"))))
> #mexp #} )
> (else mexp))))
> mexp)))
>
> \relative { c'4 d8-\token [ e ] \token f[ g ] c,4 }
>