Hello Werner,

properties handle this by having internally not a single value, but a list of 
values, and
temporary overriding simply means adding to that list. Context properties do 
currently
not allow for this mechanic, but we could simulate it ourselves:

#(set-object-property! 'details
                       'translation-type?
                       list?)

tset =
#(define-music-function (path value)
   (key-list? scheme?)
   (if (= (length path) 1) (set! path (cons 'Voice path)))
   (context-spec-music
    (make-music 'ApplyContext
                'procedure
                (lambda (ctx)
                  (let* ((details (ly:context-property ctx 'details))
                         (this-hierarchy (assoc-get (cadr path) details '()))
                         (this-val (ly:context-property ctx (cadr path))))
                    (ly:context-set-property! ctx
                                              'details
                                              (assoc-set!
                                               details
                                               (cadr path)
                                               (cons this-val this-hierarchy)))
                    (ly:context-set-property! ctx (cadr path) value))))
    (car path)))

rset =
#(define-music-function (path)
   (key-list?)
   (if (= (length path) 1) (set! path (cons 'Voice path)))
   (context-spec-music
    (make-music 'ApplyContext
                'procedure
                (lambda (ctx)
                  (let* ((details (ly:context-property ctx 'details))
                         (this-hierarchy (assoc-get (cadr path) details '())))
                    (if (null? this-hierarchy)
                        (ly:context-unset-property ctx (cadr path))
                        (begin
                         (ly:context-set-property! ctx (cadr path) (car 
this-hierarchy))
                         (ly:context-set-property! ctx
                                                   'details
                                                   (assoc-set!
                                                    details
                                                    (cadr path)
                                                    (cdr this-hierarchy))))))))
    (car path)))

{
  \set Staff.middleCPosition = 0
  c1
  \set Staff.middleCPosition = 1
  c1
  \unset Staff.middleCPosition
  c1
  
  \break
  
  \tset Staff.middleCPosition 0
  c1
  \tset Staff.middleCPosition 1
  c1
  \rset Staff.middleCPosition
  c1
  \rset Staff.middleCPosition
  c1
}

Cheers,
Valentin

Am Montag, 25. März 2024, 08:31:34 CET schrieb Werner LEMBERG:
> LilyPond provides `\temporary` and `\revert` to set a grob property
> temporarily, and afterwards the value of the grob property is the same
> as before.
> 
> Is there a similar possiblity for `\set` (or something usable in
> Scheme)?  I guess not, but I couldn't find this documented
> somewhere...
> 
> 
>     Werner

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to