On 17.09.2015 14:51, David Nalesnik wrote:
Hi Simon,

On Thu, Sep 17, 2015 at 7:20 AM, David Kastrup <[email protected] <mailto:[email protected]>> wrote:

    Simon Albrecht <[email protected]
    <mailto:[email protected]>> writes:

    > Hello,
    >
    > I’ve written a music function which applies some tweaks on
    dynamics to
    > offset them. Unfortunately, it’s not possible to use the offset
    music
    > function on X-offset, because it is a mutable property.

You can use \offset on DynamicText.X-offset.

Silly me.
Of course; the problem was that I overlooked the \version 2.19.23 in my test file, which is the /last/ version in which this does /not/ work. Since David K’s fix (thanks a lot!) for issue 4516, it has been working.
Sorry!



If you do need the name, try:

test =
#(define-music-function (ev) (ly:music?)
   (if (eq? (ly:music-property ev 'name) 'AbsoluteDynamicEvent)

And thanks for that, nevertheless.

Find attached what I’ve now got as a result, however intermediary it may prove. The example is of course far from any actual use case, but it demonstrates the functionality well.

Yours, Simon
\version "2.19.24"

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 item-x-off 0)
  (define item-y-off #f)
  (define span-y-off 0)
  (define inside-staff? #t)
  (define dynamic? #f)

  (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))
  (define (cond-offset cond? prop offs item)
    (if cond? (offset prop offs item) item))

  ;; differentiate between spec-types
  (cond
   ;; no further complications: proper pair for input
   ((not (list? spec))
    (set! item-x-off (car spec))
    (set! item-y-off (cdr spec)))
   ;; Offset DynamicText or Hairpin
   ;; input: three-element list '(spec-type x y)
   ;;;; 1. at the beginning of a DynamicLineSpanner
   ((spec-type? spec '(dynamic-line-spanner dls))
    (set! dynamic? #t)
    (set! item-x-off (second spec))
    (set! span-y-off (third spec)))
   ;;;; 2. when a DynamicLineSpanner is already active
   ((spec-type? spec '(dynamic d))
    (set! dynamic? #t)
    (set! item-x-off (second spec))
    (set! item-y-off (third spec))
    ;(format #t "item-y-off is ~a" item-y-off)
    )
   (else (ly:warning "Cannot read specification for offset - using default 
values.")))

  (cond-tweak inside-staff? 'outside-staff-priority #f
    (cond-tweak item-x-off 'X-offset item-x-off
      (cond-offset item-y-off 'Y-offset item-y-off
        (cond-tweak
         (and dynamic? inside-staff?)
         '(DynamicLineSpanner outside-staff-priority)
         #f
         (cond-tweak dynamic? '(DynamicLineSpanner Y-offset) span-y-off 
event))))))
\version "2.19.24"
\include "offII.ily"

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

Reply via email to