[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Function to display the rhythmic location of a grob (issue 197690044 by
From: |
david . nalesnik |
Subject: |
Function to display the rhythmic location of a grob (issue 197690044 by address@hidden) |
Date: |
Wed, 18 Feb 2015 17:53:44 +0000 |
Reviewers: ,
Message:
Please review. Thanks!
Description:
Function to display the rhythmic location of a grob
A convenient way to return the musical position of a grob within
a score will be very helpful in debugging, among other uses.
This patch creates a function ly:grob-rhythmic-location which
returns location as a list with the following structure:
(global-timestep (measure-number . measure-position))
Please review this at https://codereview.appspot.com/197690044/
Affected files (+33, -0 lines):
M lily/grob-scheme.cc
Index: lily/grob-scheme.cc
diff --git a/lily/grob-scheme.cc b/lily/grob-scheme.cc
index
238a0af7518189024210bda07cc9ee70aa515c40..1a1692962967208915492d9b39ce3b9a6ef506b7
100644
--- a/lily/grob-scheme.cc
+++ b/lily/grob-scheme.cc
@@ -21,9 +21,12 @@
#include "font-interface.hh"
#include "grob-array.hh"
#include "item.hh"
+#include "moment.hh"
#include "output-def.hh"
+#include "paper-column.hh"
#include "paper-score.hh"
#include "simple-closure.hh"
+#include "spanner.hh"
#include "system.hh"
#include "unpure-pure-container.hh"
#include "warn.hh" // error ()
@@ -482,3 +485,33 @@ LY_DEFINE
(ly_grob_get_vertical_axis_group_index, "ly:grob-get-vertical-axis-gro
return scm_from_int (Grob::get_vertical_axis_group_index (gr));
}
+
+LY_DEFINE (ly_grob_rhythmic_location, "ly:grob-rhythmic-location",
+ 1, 0, 0, (SCM g),
+ "Return the rhythmic position of grob @var{g} as a list."
+ " The @code{car} of the list is the global timestep, a"
+ " moment. The @code{cadr} is a pair consisting of the"
+ " measure number and the position (moment) within"
+ " the measure.")
+{
+ LY_ASSERT_SMOB (Grob, g, 1);
+ Grob *me = Grob::unsmob (g);
+
+ Paper_column *col = 0;
+
+ if (Spanner *sp = dynamic_cast<Spanner *>(me))
+ {
+ if (Item *left_bound = sp->get_bound (LEFT))
+ col = left_bound->get_column ();
+ }
+ else if (Item *it = dynamic_cast<Item *>(me))
+ col = it->get_column ();
+
+ if (!col) return 0;
+
+ Moment when = Paper_column::when_mom (col);
+
+ SCM rhythmic_location = col->get_property ("rhythmic-location");
+
+ return scm_list_2 (when.smobbed_copy (), rhythmic_location);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Function to display the rhythmic location of a grob (issue 197690044 by address@hidden),
david . nalesnik <=