\applyContext, StaffSymbol, and \stopStaff \startStaff
Greetings lilyponders, I’m trying to figure out how to use \applyContext to modify StaffSymbol grob properties. The examples here http://www.lilypond.org/doc/v2.19/Documentation/extending/context-evaluation are very helpful, but I haven’t been able to get things working with StaffSymbol and \stopStaff \startStaff. There’s probably some subtlety that I’m missing… (Maybe it has to do with the difference between \temporary \override and \override ?) Below is a tiny example (not my actual use case). Thanks for any help with this, -Paul \version "2.19.22" % These work as expected { c' \stopStaff \startStaff \override Staff.StaffSymbol.color = #red c' \override Staff.StaffSymbol.color = #green \stopStaff \startStaff c’ } { \applyContext #(lambda (context) ;; access context properties pick a property setting based on them... (ly:context-pushpop-property context 'StaffSymbol 'color blue)) c’ } % But so far these don’t... myfunc = #(define-music-function () () (define mycolor red) #{ \applyContext #(lambda (context) ;; access context properties and pick a property setting based on them... (set! mycolor green)) \override Staff.StaffSymbol.color = #mycolor #}) { c’ % the order of these commands does not seem to affect things \stopStaff \startStaff \applyContext #(lambda (context) ;; access context properties and pick a property setting based on them... (ly:context-pushpop-property context 'StaffSymbol 'color blue)) c' \myfunc \stopStaff \startStaff c' } ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \applyContext, StaffSymbol, and \stopStaff \startStaff
I found another way to do what I was trying to do. (I used \applyContext in a music function to access and then modify a custom staff context property, and then used a custom StaffSymbol engraver to access that context property and change the grob properties of any new StaffSymbol grob accordingly. A bit roundabout but it does the trick.) -Paul ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \applyContext, StaffSymbol, and \stopStaff \startStaff
Paul Morris writes: > % These work as expected > { > c' > \stopStaff > \startStaff > \override Staff.StaffSymbol.color = #red > c' > \override Staff.StaffSymbol.color = #green > \stopStaff > \startStaff > c’ > } > > { > \applyContext > #(lambda (context) > ;; access context properties pick a property setting based on them... > (ly:context-pushpop-property context 'StaffSymbol 'color blue)) > c’ > } > > % But so far these don’t... > > myfunc = > #(define-music-function () () >(define mycolor red) >#{ > \applyContext > #(lambda (context) > ;; access context properties and pick a property setting based on > them... > (set! mycolor green)) > \override Staff.StaffSymbol.color = #mycolor >#}) > > { > c’ > % the order of these commands does not seem to affect things > \stopStaff \startStaff > \applyContext > #(lambda (context) > ;; access context properties and pick a property setting based on them... > (ly:context-pushpop-property context 'StaffSymbol 'color blue)) > c' > \myfunc > \stopStaff \startStaff > c' > } I think your main problem is that you are using \applyContext here at Voice level where it does not really do anything worthwhile. Try \context Staff \applyContext ... Though frankly I have no idea what \myFunc is trying to do. You are keeping state in a global variable which is not going to work when using \myFunc in several contexts in parallel. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \applyContext, StaffSymbol, and \stopStaff \startStaff
> On Oct 19, 2015, at 1:56 AM, David Kastrup wrote: > > I think your main problem is that you are using \applyContext here at > Voice level where it does not really do anything worthwhile. Ah, I see. > Try \context Staff \applyContext … That did the trick and now it works, thanks! \version “2.19.22” myfunc = #(define-music-function () () #{ \context Staff \applyContext #(lambda (context) ;; access context properties and pick a property setting based on them... (ly:context-pushpop-property context 'StaffSymbol 'color green)) \stopStaff \startStaff #}) { c' % now it works! \context Staff \applyContext #(lambda (context) ;; access context properties and pick a property setting based on them... (ly:context-pushpop-property context 'StaffSymbol 'color red)) \stopStaff \startStaff c' % and you can put it in a music function \myfunc c' } > Though frankly I have no idea what \myFunc is trying to do. You are > keeping state in a global variable which is not going to work when using > \myFunc in several contexts in parallel. Um, never mind that, it was just my clumsy attempt to try to use \override Staff.StaffSymbol... to set the grob property when I couldn’t get ly:context-pushpop-property to work. Thanks again, I really appreciate your help. No telling how long or if I would have ever figured that out on my own. -Paul ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \applyContext, StaffSymbol, and \stopStaff \startStaff
Paul Morris writes: >> On Oct 19, 2015, at 1:56 AM, David Kastrup wrote: >> >> I think your main problem is that you are using \applyContext here at >> Voice level where it does not really do anything worthwhile. > > Ah, I see. > >> Try \context Staff \applyContext … > > That did the trick and now it works, thanks! > > \version “2.19.22” > > myfunc = > #(define-music-function () () >#{ > \context Staff > \applyContext > #(lambda (context) > ;; access context properties and pick a property setting based on > them... > (ly:context-pushpop-property context 'StaffSymbol 'color green)) > \stopStaff > \startStaff >#}) Frankly, anything wrong with \temporary \override Staff.StaffSymbol.color = #green here? Assuming you want a temporary override (which is what ly:context-pushpop-property does) in order to be able to revert to the previous setting afterwards. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \applyContext, StaffSymbol, and \stopStaff \startStaff
> On Oct 19, 2015, at 10:59 AM, David Kastrup wrote: > > Paul Morris writes: >> >> That did the trick and now it works, thanks! >> >> \version “2.19.22” >> >> myfunc = >> #(define-music-function () () >> #{ >> \context Staff >> \applyContext >> #(lambda (context) >>;; access context properties and pick a property setting based on >> them... >>(ly:context-pushpop-property context 'StaffSymbol 'color green)) >> \stopStaff >> \startStaff >> #}) > > Frankly, anything wrong with > >\temporary \override Staff.StaffSymbol.color = #green > > here? That would work except I want to be able to access Staff context properties and then, based on their values, decide what to set the StaffSymbol property to. In this example, say color it either green or blue. I just left these details out of my tiny example (as I tried to indicate with the comment "access context properties and pick a property setting based on them…”, which may not have been very clear). > Assuming you want a temporary override (which is what > ly:context-pushpop-property does) in order to be able to revert to the > previous setting afterwards. I actually don’t think I’ll need to be able to revert. I was just using ly:context-pushpop-property because it was shown in the examples in the extending manual. Thanks again, -Paul ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \applyContext, StaffSymbol, and \stopStaff \startStaff
Paul Morris writes: >> On Oct 19, 2015, at 10:59 AM, David Kastrup wrote: >> >> Paul Morris writes: >>> >>> That did the trick and now it works, thanks! >>> >>> \version “2.19.22” >>> >>> myfunc = >>> #(define-music-function () () >>> #{ >>> \context Staff >>> \applyContext >>> #(lambda (context) >>>;; access context properties and pick a property setting based on >>> them... >>>(ly:context-pushpop-property context 'StaffSymbol 'color green)) >>> \stopStaff >>> \startStaff >>> #}) >> >> Frankly, anything wrong with >> >>\temporary \override Staff.StaffSymbol.color = #green >> >> here? > > That would work except I want to be able to access Staff context > properties and then, based on their values, decide what to set the > StaffSymbol property to. In this example, say color it either green > or blue. I just left these details out of my tiny example (as I tried > to indicate with the comment "access context properties and pick a > property setting based on them…”, which may not have been very clear). Ok, that makes sense. One can override grob properties with a callback but they will be called (with the grob as argument) at the time the property is actually needed, and at that time the only context properties from the time of call will be the grob property defaults stored in the grob, in this case the StaffSymbol settings. And it does not sound like that would help you. So \applyContext indeed seems like the right call here. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user