What about introducing a new grob property containing the _printed_
bar number and the measure position?
Unless, of course, there is already a way to retrieve the desired information.

With the attached patch, the input file

\version "2.19.82"
{
  \override Score.BarNumber.break-visibility = ##(#t #t #t)
  \override NoteHead.after-line-breaking =
  #(lambda (grob)
     (ly:message "Internal location: ~a" (grob::rhythmic-location grob))
     (ly:message "Printed location: ~a" (grob::printed-rhythmic-location grob)))
  c'1
  \set Score.currentBarNumber = 12
  c'1
}

has the following output:

[...]
Internal location: (1 . #<Mom 0>)
Printed location: (1 . #<Mom 0>)
Internal location: (2 . #<Mom 0>)
Printed location: (12 . #<Mom 0>)
[...]

Best wishes.
Davide
From 83eb13206528dbf5f397c845d4ef789a2ac0429c Mon Sep 17 00:00:00 2001
From: Davide Liessi <davide.lie...@gmail.com>
Date: Thu, 3 Oct 2019 20:45:23 +0200
Subject: [PATCH] Add printed-rhythmic-location grob property

The grob property rhythmic-location contains the internal
bar number and the measure position. However, the printed
bar number can be changed by setting Score.currentBarNumber.
The new grob property allows to retrieve the printed bar
number of the grob, which was not possible previously.

Also, it is clarified that bar numbers in rhythmic-location
are the internal ones.
---
 lily/paper-column-engraver.cc  |  7 +++++++
 lily/paper-column.cc           |  1 +
 scm/define-grob-properties.scm |  4 +++-
 scm/output-lib.scm             | 16 ++++++++++++++--
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/lily/paper-column-engraver.cc b/lily/paper-column-engraver.cc
index 6c7bd25891..e1296790ee 100644
--- a/lily/paper-column-engraver.cc
+++ b/lily/paper-column-engraver.cc
@@ -232,14 +232,21 @@ Paper_column_engraver::stop_translation_timestep ()
 
   SCM mpos = get_property ("measurePosition");
   SCM barnum = get_property ("internalBarNumber");
+  SCM curbarnum = get_property ("currentBarNumber");
   if (unsmob<Moment> (mpos)
       && scm_is_integer (barnum))
     {
       SCM where = scm_cons (barnum,
                             mpos);
+      SCM printedwhere = scm_cons (curbarnum,
+                            mpos);
 
       command_column_->set_property ("rhythmic-location", where);
       musical_column_->set_property ("rhythmic-location", where);
+      command_column_->set_property ("printed-rhythmic-location",
+                                     printedwhere);
+      musical_column_->set_property ("printed-rhythmic-location",
+                                     printedwhere);
     }
 
   for (vsize i = 0; i < items_.size (); i++)
diff --git a/lily/paper-column.cc b/lily/paper-column.cc
index bff4011a4b..3734fa967a 100644
--- a/lily/paper-column.cc
+++ b/lily/paper-column.cc
@@ -488,6 +488,7 @@ ADD_INTERFACE (Paper_column,
                "page-break-permission "
                "page-turn-penalty "
                "page-turn-permission "
+               "printed-rhythmic-location "
                "rhythmic-location "
                "shortest-playing-duration "
                "shortest-starter-duration "
diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm
index 6ccac5317c..bdf2f22a12 100644
--- a/scm/define-grob-properties.scm
+++ b/scm/define-grob-properties.scm
@@ -812,6 +812,8 @@ positions are requested, the closest one is taken.")
      (prefer-dotted-right ,boolean? "For note collisions, prefer to
 shift dotted up-note to the right, rather than shifting just the
 dot.")
+     (printed-rhythmic-location ,rhythmic-location? "Where (printed
+bar number, measure position) in the score.")
      (protrusion ,number? "In an arpeggio bracket, the length of the
 horizontal edges.")
 
@@ -839,7 +841,7 @@ The key is a string of the pattern to be replaced.  The value is a
 string of what should be displayed.  Useful for ligatures.")
      (restore-first ,boolean? "Print a natural before the
 accidental.")
-     (rhythmic-location ,rhythmic-location? "Where (bar number,
+     (rhythmic-location ,rhythmic-location? "Where (internal bar number,
 measure position) in the score.")
      (right-bound-info ,list? "An alist of properties for determining
 attachments of spanners to edges.")
diff --git a/scm/output-lib.scm b/scm/output-lib.scm
index 45beb7a834..9f22d5aeb8 100644
--- a/scm/output-lib.scm
+++ b/scm/output-lib.scm
@@ -31,8 +31,8 @@
   (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}."
+  "Return a pair consisting of the internal 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)
@@ -42,6 +42,18 @@
         (ly:grob-property col 'rhythmic-location)
         '())))
 
+(define-public (grob::printed-rhythmic-location grob)
+  "Return a pair consisting of the printed 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 'printed-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
-- 
2.11.0

_______________________________________________
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond

Reply via email to