]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4294: Functions to display rhythmic information of a grob
authorDavid Nalesnik <david.nalesnik@gmail.com>
Wed, 18 Feb 2015 17:33:51 +0000 (11:33 -0600)
committerDavid Nalesnik <david.nalesnik@gmail.com>
Sat, 28 Feb 2015 14:43:15 +0000 (08:43 -0600)
Convenient ways to return the musical position of a grob within
a score will be very helpful in debugging, among other uses.

This patch creates two Scheme functions which return the location
of a grob based on the associated paper column.  In the case of
spanners, this is the column of the left bound.

(1) grob::rhythmic-location returns a pair consisting of measure-number
and measure-position;

(2) grob::when returns a moment representing the global timestep.

scm/output-lib.scm

index 7f956a54d574549efbf360575efc782ad817fb67..96456b1b77fb436ae4a90b6b7ae851c30fa01678 100644 (file)
   "Return the name of the grob @var{grob} as a symbol."
   (assq-ref (ly:grob-property grob 'meta) 'name))
 
+(define-public (grob::rhythmic-location grob)
+  "Return a pair consisting of the measure number and moment within
+   the measure of grob @var{grob}."
+  (let* (; all grobs support either spanner- or item-interface
+         (item (if (grob::has-interface grob 'spanner-interface)
+                   (ly:spanner-bound grob LEFT)
+                   grob))
+         (col (ly:item-get-column item)))
+    (if (ly:grob? col)
+        (ly:grob-property col 'rhythmic-location)
+        '())))
+
+(define-public (grob::when grob)
+  "Return the global timestep (a moment) of grob @var{grob}."
+  (let* (; all grobs support either spanner- or item-interface
+         (item (if (grob::has-interface grob 'spanner-interface)
+                   (ly:spanner-bound grob LEFT)
+                   grob))
+         (col (ly:item-get-column item)))
+    (if (ly:grob? col)
+        (ly:grob-property col 'when)
+        '())))
+
 (define-public (make-stencil-boxer thickness padding callback)
   "Return function that adds a box around the grob passed as argument."
   (lambda (grob)