From d740612bb41672446873e307ba3b7c605be9b2f6 Mon Sep 17 00:00:00 2001 From: David Nalesnik Date: Wed, 18 Feb 2015 11:33:51 -0600 Subject: [PATCH] Issue 4294: Functions to display rhythmic information of a grob 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 7f956a54d5..96456b1b77 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -30,6 +30,29 @@ "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) -- 2.39.2