Hello,

while developing a workaround (or solution?) for issue 4316 <https://code.google.com/p/lilypond/issues/detail?id=4316>, I encountered the following problem: \offset cannot be used on X and Y offset properties, apparently because these are mutable, and as the doc string for (offsetter) in scm/music-functions.scm states, \offset is limited to work only on immutable properties. (I haven’t really gotten behind the distinction of mutable/immutable properties…) Now, I don’t really know how to circumvent this, and it seems like a really important usecase for \offset. Do you have any ideas here?

For more context, see issue 4316 and the current version of the \off function I’m developing (attached; I hope it’s readable by the comments I gave).

TIA,
Simon
\version "2.19.23"

off =
#(define-music-function
  (spec event)
  (pair? ly:music?)
  "Shift grobs using X- and Y-offset, with outside-staff-priority unset by default.

Provides dedicated input modes for Dynamics in order to handle the tricky interaction with DynamicLineSpanner and both settings of outside-staff-priority.
"
  ;; default values
  (define x-off 0)
  (define y-off 0)
  (define inside-staff? #t)
  (define dynamic? #f)
  (define dyn-line-off 0)

  (define (spec-type? spec symbol-list)
    (and (list? spec)
         (member (car spec) symbol-list)))

  ;; Apply tweak only if cond? is true
  (define (cond-tweak cond? prop val arg)
    (if cond? (tweak prop val arg) arg))

  ;; differentiate between spec-types
  (cond
   ((number-pair? spec)
    (set! x-off (car spec))
    (set! y-off (cdr spec)))
   ;; Offset DynamicText and Hairpin.
   ((spec-type? spec '(dynamic dyn d))
    (set! dynamic? #t)
    (set! x-off (second spec))
    (set! y-off (third spec)))
   ;; Offset DynamicLineSpanner; Y-offset only
   ((spec-type? spec '(dynamic-line dyn-line dl))
    ;; Allow requiring outside-staff placement
    ;; by giving #f as an additional element.
    (if (= 3 (length spec)) (set! inside-staff? (third spec)))
    (set! dyn-line-off (second spec)))
   (else (ly:warning "Cannot read specification for offset - using default values.")))

  (cond-tweak inside-staff? 'outside-staff-priority #f
    (offset 'X-offset x-off
      (offset 'Y-offset y-off
        (cond-tweak
         (and dynamic? inside-staff?)
         '(DynamicLineSpanner outside-staff-priority)
         #f
         (offset '(DynamicLineSpanner Y-offset) dyn-line-off event))))))

\relative {
  \hideNotes
  \dynamicUp
  b'2-\off #'(dl 0) -\off #'(d 0 0) \< 2\f\>
  2 2\!\<
  2\f
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to