lilypond-user
[Top][All Lists]
Advanced

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

Re: SVG output - Group multiple grobs together


From: David Nalesnik
Subject: Re: SVG output - Group multiple grobs together
Date: Wed, 10 Jan 2018 09:21:46 -0600

Hi James,

On Wed, Jan 10, 2018 at 5:51 AM, James Opstad <address@hidden> wrote:
> Hello,
>
>
> I have been experimenting with the new output-attributes grob property for
> SVG output. For example, the following code creates a group with id="noteC"
> around the C notehead.
>
>
> \version "2.19.80"
> \pointAndClickOff
> \relative c' {
>   \once \override NoteHead.output-attributes = #'((id . noteC))
>   c4 d e f |
> }
>
> How would I include multiple grobs within the same group e.g. all the grobs
> associated with a single note (NoteHead, Stem, Accidental etc.)?
>

All grobs have pointers to other single grobs or arrays of other
grobs.  You gain access to these through such functions as
ly:grob-parent, ly:grob-object, ly:grob-array, ly:item-get-column.
The idea of "multiple grobs within the same group e.g. all the grobs
associated with a single note" can prove to be complex since your idea
of a grouping is not necesarily LilyPond's.  You may have to follow
chains of pointers--as I did below to arrive at the Stem grob from
NoteHead: i.e, through NoteColumn, the Y-parent of the NoteHead.

So here is something quickly hacked together from your code example:

\version "2.19.65"

\pointAndClickOff
\relative c' {
  \once \override NoteHead.output-attributes =
  #(lambda (grob)
     (let* ((acc (ly:grob-object grob 'accidental-grob))
            (acc-name (if (ly:grob? acc) (grob::name acc) "none"))
            ; we need a NoteColumn object for access to other grobs
            (nc (ly:grob-parent grob Y))
            (stem (ly:grob-object nc 'stem))
            (stem-name (if (ly:grob? stem) (grob::name stem) "none"))
            (pc (ly:item-get-column grob))
            (pc-name (if (ly:grob? pc) (grob::name pc) "none"))
            (elts (ly:grob-object pc 'elements)))
       (display elts) ; just so you see a grob array
       (list
        (cons 'id 'noteC)
        (cons 'accidental acc-name)
        (cons 'stem stem-name)
        (cons 'column pc-name))))

  c4 d e f |
}

%%%

Here is a link to something you might find useful.  It stores data
about every grob encountered.

https://www.mail-archive.com/address@hidden/msg117645.html

HTH,

David



reply via email to

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