On Tue, Sep 27, 2016 at 10:33 AM, David Nalesnik
<[email protected]> wrote:

>  In the attachment...

And now for the file...

David
\version "2.19.46"

% angle brackets cause SVG error so reformat:
% #<Mom 1> becomes [Mom 1]
#(define (reformat-moment mom)
   (let* ((mom (format #f "~a" mom))
          (mom (string-drop mom 2))
          (mom (string-drop-right mom 1)))
     (string-concatenate (list "[" mom "]"))))

#(define clef-map
   '(("clefs.C" .
       ((0 . "alto") (2 . "tenor")))
     ("clefs.C_change" .
       ((0 . "alto") (2 . "tenor")))
     ("clefs.F" .
      ((2 . "bass")))
     ("clefs.F_change" .
       ((2 . "bass")))
     ("clefs.G" .
       ((-2 . "treble")))
     ("clefs.G_change" .
       ((-2 . "treble")))))

#(define (get-clef-string glyph pos)
   (let* ((clef-map-glyph (assoc-get glyph clef-map))
          (name (and clef-map-glyph
                    (assoc-get pos clef-map-glyph))))
     (if (and clef-map-glyph name)
         (format #f ",~a" name)
         (format #f ",~a at ~a" glyph pos))))

% grob name + absolute moment + (system) coordinates should be enough for a unique id...
#(define (get-unique-id grob)
   (let* ((sys (ly:grob-system grob))
          (name (grob::name grob))
          (str (format #f "~a/~a,(~a,~a)"
                 name
                 (reformat-moment (grob::when grob))
                 (ly:grob-relative-coordinate grob sys X)
                 (ly:grob-relative-coordinate grob sys Y)))
          (props (ly:grob-properties grob)))
     (if (eq? name 'Clef)
         (let ((glyph (assoc-get 'glyph-name props))
               (pos (assoc-get 'staff-position props)))
           (string-append str (get-clef-string glyph pos)))
         str)))

assignIDs =
#(let ((grob-names (map car all-grob-descriptions)))
   #{
     #@(map (lambda (x)#{ \override #(list 'Score x 'id) = #get-unique-id #})
     grob-names)
   #})

{
  \assignIDs
  \clef treble
  c2
  \clef alto
  c
  \clef tenor
  c
  \clef bass
  c
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to