On Thu, Sep 8, 2016 at 1:08 PM, David Nalesnik <david.nales...@gmail.com> wrote:

>
> So, to get the positions of the note-heads under a Beam, you could
> write something like:

Appended as a file because of awkward line-breaks when inlining....

David
\version "2.19.46"

#(define my-positions
   (lambda (grob)
     (let* ((stems (ly:grob-object grob 'stems))
            ;; convert grob array to a list because few Scheme facilities for dealing with grob arrays
            (stem-list (ly:grob-array->list stems))
            ;; list of grob arrays of NoteHead for each Stem
            (note-heads (map (lambda (x) (ly:grob-object x 'note-heads)) stem-list))
            ;; convert the above to a list of lists of NoteHead grobs
            (note-heads-list
             (map (lambda (x)
                    ;; if no note heads (i.e. beamed rest), no array...
                    (if (ly:grob-array? x) (ly:grob-array->list x) '()))
               note-heads))
            ;; staff-positions of beamed notes, a list for each group
            (note-positions
             (map (lambda (x)
                    (map (lambda (y) (ly:grob-property y 'staff-position)) x))
               note-heads-list))
            ;; since we just want absolute max and min, we can flatten the nested list
            ;; for convenience:
            ;; i.e., ((1 2) (3) (4 5 6)) --> (1 2 3 4 5 6)
            (flattened-list (append-map identity note-positions))
            (highest (apply max flattened-list))
            (lowest (apply min flattened-list)))

       (format #t "highest: ~a lowest: ~a~%" highest lowest)

       ; return default positions for sake of demo
       (beam::place-broken-parts-individually grob))))

{
  \override Beam.positions = #my-positions
  f''16 d'' b' g'
  <f'' b''>16 <d'' f''> <b' d''> <g' b'>
  r16 d'' b''' g,
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to