lilypond-user
[Top][All Lists]
Advanced

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

Re: Accessing "timecode" of notes or bars


From: Thomas Morley
Subject: Re: Accessing "timecode" of notes or bars
Date: Sun, 20 Apr 2014 18:05:40 +0200

2014-04-20 16:50 GMT+02:00 Boris Lau <address@hidden>:
> Sorry, there was an error in my posted snipped. Here is the correct version:
>
> \version "2.16.2"
>
> #(define (note-number grob)
>  (string-concatenate
>   (list
>    "NoteHead/"
>    (number->string
>     (ly:pitch-semitones
>
>      (ly:event-property (ly:grob-property grob 'cause) 'pitch))))))
>
> \relative c' {
>   \time 4/4
>
> \override NoteHead #'id = #note-number
>     c d e
> }
>
> Please compile with lilypond -dbackend=svg test_id.ly
>
> As expected, each notehead in the output is assigned with an id value, e.g.,
> NoteHead/0, where the number indicates the pitch.
> Now I want to replace the pitch with its position in time expressed in bars
> and beats. Is this possible?
>
> Best, Boris
>
>
>
> On 20.04.14 16:24, Thomas Morley wrote:
>>
>> please give us the link or provide a compilable snippet.
>> Otherwise I doubt you will get much help.
>
>
> --
> Boris Lau
> -> Web:   http://www.borislau.de
> -> Phone: +49 761 1529078 | SMS: +49 174 9436758
> -> Mail:  Kartäuserstr. 124, D-79104 Freiburg, Germany

Hi again,

maybe an idea:

\version "2.16.2"

#(use-modules (ice-9 pretty-print))

#(define grob-name
  (lambda (x)
    (if (ly:grob? x)
        (assq-ref (ly:grob-property x 'meta) 'name)
        (ly:error "~a is not a grob" x))))


#(define (look-up-for-parent name-symbol axis grob)
"
 Return the parent of @var{grob}, specified by it's @var{name-symbol} in
 axis @var{axis}.
 If not found, look up for the next parent.
"
 (let* ((parent (ly:grob-parent grob axis)))
 (cond
   ((not (ly:grob? parent))
    (ly:error
       (_"Perhaps typing error for \"~a\" or \"~a\" is not in the parent-tree.")
       name-symbol name-symbol))
   ((not (equal? name-symbol (grob-name parent)))
    (look-up-for-parent name-symbol axis parent))
   (else parent))))

#(define (note-info grob)
  (pretty-print
    (ly:grob-property
      (look-up-for-parent 'PaperColumn X grob)
      'rhythmic-location)))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5

\relative c' {
  \time 4/4

\override NoteHead #'id = #note-info
    c d e
}

Tested only with pdf-output!

Cheers,
  Harm



reply via email to

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