Re: Extracting symbol location

2017-06-05 Thread Lukas Tuggener
Dear David, Dear lilypond users

I have used an adapted version (see grace.ly) of the script David gave me
(see test-clefs-svg.ly) to extract the exact location of various symbols. I
recently tried to add support for grace notes.

The problem is, when i look at the output of (ly:grob-properties grob) i
see no reliable difference between a normal notehead and a notehead of a
grace note. The only thing is the size of the notehead and i assume using
this will be very unreliable due to different scalings.

Does anyone have a idea how to work around that?

Thanks a lot, best
Lukas


Output:

Normal Note:

)
(duration-log . 2) (stencil . #) (staff-position . -9) (cause .
#) (duration . #) (pitch . #) (origin . #))((display-methods #) (name . NoteEvent) (iterator-ctor . #) (types event note-event
rhythmic-event melodic-event)) >
) (length . #))((class note-event melodic-event rhythmic-event
music-event StreamEvent) (length . #) (duration . #) (pitch . #) (origin . #)) >
) (horizontal-skylines . # # >)
(vertical-skylines . #) (X-extent -0.0 . 1.304212))[Duration
16 ]">







Small Note:

) (duration-log . 2) (stencil .
#) (staff-position . -8) (cause . #)
(duration . #) (pitch . #) (origin . #))((display-methods #) (name .
NoteEvent) (iterator-ctor . #) (types event note-event
rhythmic-event melodic-event)) >
) (length . #))((class note-event melodic-event rhythmic-event
music-event StreamEvent) (length . #) (duration . #)
(pitch . #) (origin . #)) >
) (horizontal-skylines . # # >)
(vertical-skylines . #) (X-extent -0.0 .
0.917888611646328))[Duration 8 ]">





Lukas Tuggener  schrieb am Mo., 16. Jan. 2017 um
15:36 Uhr:

> Hi David,
> thanks a lot for the update, it really helped me out greatly.
>
> Thanks
> Lukas
>
> David Nalesnik  schrieb am Mo., 9. Jan. 2017 um
> 16:11 Uhr:
>
>> Lukas,
>>
>> On Mon, Jan 9, 2017 at 8:43 AM, David Nalesnik 
>> wrote:
>>
>> > The new output-attibutes property allows you to create multiple
>> > attributes, so why not adapt the labeling routines to return something
>> > like
>> >
>> > value of output-attributes = '((name . someGrob) (moment . whenIAm)
>> > (x-pos . xCoordinate) (y-pos . yCoordinate))
>>
>> A way to do this is attached.
>>
>> An excerpt from the SVG:
>>
>> > y-pos="-7.552">
>>
>> -David
>>
>
\version "2.19.46"

% angle brackets cause SVG error so reformat:
% # 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 "]"

% grob name + absolute moment + (system) coordinates should be enough for a unique id...
#(define (get-unique-id grob)
   (let ((sys (ly:grob-system grob)))
 (format #f "~a/~a,(~a,~a)"
   (grob::name grob)
   (reformat-moment (grob::when grob))
   (ly:grob-relative-coordinate grob sys X)
   (ly:grob-relative-coordinate grob sys Y

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
}\version "2.19.46"

% angle brackets cause SVG error so reformat:
% # 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 "]"


% Start Clef Helpers
#(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
% End Clef Helpers

% Help with alist
#(define (concat_alist lis)
(if (eq? (length lis) 0)
  "ZeroList"
  (if (eq? (length lis) 1)
  (string-append (string-append (number->string(car(list-ref lis 0))) "," )  (string-append (number->string(cdr(list-ref lis 0))) ",," ) )
  (string-append (string-append (string-append (number->string(car(list-ref lis 0)))

Re: Extracting symbol location

2017-01-16 Thread Lukas Tuggener
Hi David,
thanks a lot for the update, it really helped me out greatly.

Thanks
Lukas

David Nalesnik  schrieb am Mo., 9. Jan. 2017 um
16:11 Uhr:

> Lukas,
>
> On Mon, Jan 9, 2017 at 8:43 AM, David Nalesnik 
> wrote:
>
> > The new output-attibutes property allows you to create multiple
> > attributes, so why not adapt the labeling routines to return something
> > like
> >
> > value of output-attributes = '((name . someGrob) (moment . whenIAm)
> > (x-pos . xCoordinate) (y-pos . yCoordinate))
>
> A way to do this is attached.
>
> An excerpt from the SVG:
>
>  y-pos="-7.552">
>
> -David
>
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Extracting symbol location

2017-01-09 Thread Lukas Tuggener
Hi David

When I tried to use your very useful script on a fresh installation it
didnt work anymore. I suspect it is due to the change you already mentioned
in your first message:



*There's a patch being reviewed which replaces the 'id property
with'output-properties and this will need to be updated
accordingly(https://sourceforge.net/p/testlilyissues/issues/4974/
).*


I tried to uptdate the script, but didnt get it to work so far. I assume
the updated assignIDs function should look something like this:

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

For any hint where I went wrong i would be very grateful.

Regards
Lukas

David Nalesnik  schrieb am Di., 27. Sep. 2016 um
22:33 Uhr:

> Hi Urs,
>
> On Tue, Sep 27, 2016 at 3:58 AM, Urs Liska  wrote:
> >
> >
> > Am 26.09.2016 um 20:13 schrieb David Nalesnik:
> >> The link you cite mentions looking at SVG output, and I suppose that
> >> would be the best way.  I can't think of another method to get the
> >> actual print positions of objects.
> >>
> >
> > Hm, but at some point LilyPond *has* to know where objects are placed,
> > isn't it?
> > Isn't there anything like a parent hierarchy that could be walked up
> > like a breadcrumb navigation that eventually leads to coordinates
> > relative to a page corner?
>
> Don't know how helpful this is, but I see the command-line option
> -dbackend=scm which dumps the stencil output of a file as a Scheme
> expression.  It includes entries for "grob-cause".
>
> I've tried to create a function which takes a score argument and
> produces a corresponding stencil expression to work with, but I'm
> having no luck.
>
> It would be nice to do something like this:
>
>  \version "2.19.46"
>
> #(use-modules (scm page))
>
> #(define (of paper-book)
>(for-each
> (lambda (page)
>   (display (ly:stencil-expr page))
>   (newline))
> (map page-stencil (ly:paper-book-pages paper-book
>
> but I can't get the Paper_book object needed.
>
> ly:book-process does create a Paper_book, but it isn't returned...
>
> >
> > (Of course this is closely related to my question
> > http://lists.gnu.org/archive/html/lilypond-user/2016-09/msg00655.html)
> >
>
> Seems like a tall order, but who knows!
>
> David
>
> ___
> lilypond-user mailing list
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user
>
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Extracting symbol location

2016-09-27 Thread Lukas Tuggener
Hey David,

thank you so much! I am fairly sure that i'll be able to extend this file
in a similar fashion to cope with other types of simbols...

regards
Lukas

David Nalesnik  schrieb am Di., 27. Sep. 2016 um
17:35 Uhr:

> On Tue, Sep 27, 2016 at 10:33 AM, David Nalesnik
>  wrote:
>
> >  In the attachment...
>
> And now for the file...
>
> David
>
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Extracting symbol location

2016-09-27 Thread Lukas Tuggener
Tanks to this \assignIDs function and the information in the svg its pretty
easy to find the correct location of a given symbol.

The problem im stuck with right now is creating meaningful labels. The way
the ID is constructed right now is Name+Momentum?+RelativeLocation. And i
am not able to tell eg. bass and treble clefs apart.

Is it possible to dump more information about the grob this id tag? Such
that it is unique to what symbol is printed.

I am totally new to lilypond, sorry if I spam you with trivial questions.
If you could point me to the relevant parts of the doc it would already
help.

cheers
Lukas

Urs Liska  schrieb am Di., 27. Sep. 2016 um 10:59 Uhr:

>
>
> Am 26.09.2016 um 20:13 schrieb David Nalesnik:
> > The link you cite mentions looking at SVG output, and I suppose that
> > would be the best way.  I can't think of another method to get the
> > actual print positions of objects.
> >
>
> Hm, but at some point LilyPond *has* to know where objects are placed,
> isn't it?
> Isn't there anything like a parent hierarchy that could be walked up
> like a breadcrumb navigation that eventually leads to coordinates
> relative to a page corner?
>
> (Of course this is closely related to my question
> http://lists.gnu.org/archive/html/lilypond-user/2016-09/msg00655.html)
>
> Urs
>
> ___
> lilypond-user mailing list
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user
>


test-clefs-svg.ly
Description: Binary data
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Extracting symbol location

2016-09-27 Thread Lukas Tuggener
Hi David

Many thanks, this will help me greatly, when parsing the .svg files.
Upcoming patches will not be an issue, because i will have to run this just
once.

Thanks again and have a good day
Lukas


David Nalesnik  schrieb am Mo., 26. Sep. 2016 um
20:13 Uhr:

> Hi Lukas,
>
> On Fri, Sep 23, 2016 at 5:06 AM, Lukas Tuggener 
> wrote:
> > Dear All
> >
> > To create labeled training data for a machine learning project, I need to
> > extract the location at which symbols are printed. Is it possible to
> extract
> > coordinates for every symbol? Methods which reveal the position of one
> > symbol at a time would also already help a lot (e.g. control which symbol
> > will be printed at the exact center)
> >
> > I am aware that similar questions have been asked have been asked in the
> > past. But those are pretty old, so I am hoping that there has been some
> > development in this area.
> > (http://lists.gnu.org/archive/html/lilypond-user/2007-05/msg00142.html)
> >
>
> The link you cite mentions looking at SVG output, and I suppose that
> would be the best way.  I can't think of another method to get the
> actual print positions of objects.
>
> I can't help with processing the SVG output to get the information you
> want (a bounding box for each element?), but the attached file might
> help with preparing an interpretable file.
>
> Objects aren't assigned a unique id by default.  The attached tries to
> do this.  Hopefully, the information included (grob name, moment,
> horizontal and vertical coordinates) is sufficient.  The coordinates
> used in the ID aren't the print position -- they are relative to the
> system on which the grob is found, for one thing.  I include them to
> distinguish between the note heads in a chord, which obviously occur
> at the same time (moment).
>
> There's a patch being reviewed which replaces the 'id property with
> 'output-properties and this will need to be updated accordingly
> (https://sourceforge.net/p/testlilyissues/issues/4974/).
>
> Hope this helps,
> David
>
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Extracting symbol location

2016-09-23 Thread Lukas Tuggener
Dear All

To create labeled training data for a machine learning project, I need to
extract the location at which symbols are printed. Is it possible to
extract coordinates for every symbol? Methods which reveal the position of
one symbol at a time would also already help a lot (e.g. control which
symbol will be printed at the exact center)

I am aware that similar questions have been asked have been asked in the
past. But those are pretty old, so I am hoping that there has been some
development in this area.  (
http://lists.gnu.org/archive/html/lilypond-user/2007-05/msg00142.html)

Thank you very much.
Regards
Lukas
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user