lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting LedgerLineSpanner props from a NoteHead callback?


From: Thomas Morley
Subject: Re: getting LedgerLineSpanner props from a NoteHead callback?
Date: Tue, 20 Aug 2013 01:09:31 +0200

2013/8/19 Mark Polesky <address@hidden>:
> I'm trying to retrieve the value of
> LedgerLineSpanner.length-fraction from within a NoteHead
> callback, and I can't figure it out.  Is there a way?
>
> Thanks.
> - Mark
>
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user

Hi Mark,

a quick shot, seems to work, though:

\version "2.17.24"

#(define (look-up-for-parent name-symbol axis grob)
"
 Return the parent of @var{grob}, specified by it's @var{name-symbol} in
 axis @var{axis}.
 If not found, look up for the next parent.
"
 (let* ((parent (ly:grob-parent grob axis))
        (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name))))
 (cond
   ((not (ly:grob? parent))
    (ly:error
       (_"Perhaps typing error for \"~a\" or \"~a\" is not in the parent-tree.")
       name-symbol name-symbol))
   ((not (equal? name-symbol (grob-name parent)))
    (look-up-for-parent name-symbol axis parent))
   (else parent))))

#(define (read-out l1 l2)
   (define (helper ls1 ls2 ls3)
   "Filters all elements of ls1 from ls2 by their grob-name and
appends it to ls3"
    (let ((grob-name-proc (lambda (x) (assq-ref (ly:grob-property x
'meta) 'name))))
     (if (null? ls1)
         ls3
         (helper
           (cdr ls1)
           ls2
           (append ls3 (filter (lambda (x) (eq? (car ls1)
(grob-name-proc x))) ls2))))))
  (helper l1 l2 '()))

foo =
\override NoteHead.before-line-breaking =
  #(lambda (grob)
    (let* ((sys (look-up-for-parent 'System X grob))
           (all (ly:grob-array->list (ly:grob-object sys 'all-elements)))
           (llsp (read-out '(LedgerLineSpanner) all))
           (l-f (ly:grob-property (car llsp) 'length-fraction)))
    (display l-f)
    ))


{
    \foo
    a'
}


HTH,
   Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]