[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
change clef inside a grob-callback?
From: |
Mark Polesky |
Subject: |
change clef inside a grob-callback? |
Date: |
Thu, 16 Jul 2009 19:10:15 -0700 (PDT) |
Is there a way to change the clef from within a grob callback?
I'm trying to create an auto-clef-change function that will find the
average staff-position within a chord and change the clef if needed. But
I'm a little stuck. I found a way to calculate each chord's average
staff-position, but it's within a grob-callback. And I can't figure out
how to change the clef from there, or if it's even possible. So for the
moment, I'm having the function display the would-be clef decisions in
the console.
Maybe an entirely different approach is needed -- I don't know.
Can anyone look this over and point me in a helpful direction?
Thanks so much!
- Mark
\version "2.13.2"
#(define (first-note? note-grob)
(let* ((note-column (ly:grob-parent note-grob X))
(note-grob-array (ly:grob-object note-column 'note-heads))
(first-note (ly:grob-array-ref note-grob-array 0)))
(eq? note-grob first-note)))
#(define (get-avg-staff-pos note-grob)
(let* ((note-column (ly:grob-parent note-grob X))
(note-grob-array (ly:grob-object note-column 'note-heads))
(note-count (ly:grob-array-length note-grob-array)))
;; maybe there should be a ly:grob-array-map procedure...
(let loop ((staff-pos-sum 0) (i 0))
(if (>= i note-count)
(/ staff-pos-sum note-count)
(loop (+ staff-pos-sum
(ly:grob-staff-position
(ly:grob-array-ref note-grob-array i)))
(1+ i))))))
autoClefOn =
\override NoteHead #'before-line-breaking =
#(lambda (grob)
(if (first-note? grob)
(if (< (get-avg-staff-pos grob) -6)
(display "bass\n")
(display "treble\n"))))
autoClefOff =
\revert NoteHead #'before-line-breaking
\relative {
\autoClefOn
b <g' b d> c, <g b d>
\autoClefOff
}
- change clef inside a grob-callback?,
Mark Polesky <=