]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2671: Provide functions ly:moment-main and ly:moment-grace
authorDavid Kastrup <dak@gnu.org>
Thu, 28 Jun 2012 23:48:11 +0000 (01:48 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 23 Jul 2012 05:56:17 +0000 (07:56 +0200)
Those will usually be more convenient than using ly:moment-*-numerator
and ly:moment-*-denominator.

Also, (/ (ly:moment-*-numerator ...) (ly:moment-*-denominator ...))
can't deal with infinite moment components.  This could theoretically
be amended by letting (ly:moment-*-denominator ...) resolve to
_inexact_ zero (in which case the division turns out ±inf.0), but that
is all rather hand-wavy and flimsy.  Being able to access the
components directly is more straightforward.

lily/moment-scheme.cc

index b9a7487d343129bb61b7590efc1131d9ec02c943..3347c4da23ae0c077b84819f98762b1f36e4d92f 100644 (file)
@@ -114,6 +114,15 @@ LY_DEFINE (ly_moment_mod, "ly:moment-mod",
   return (*ma % * mb).smobbed_copy ();
 }
 
+LY_DEFINE (ly_moment_grace, "ly:moment-grace",
+           1, 0, 0, (SCM mom),
+           "Extract grace timing as a rational number from @var{mom}.")
+{
+  LY_ASSERT_SMOB (Moment, mom, 1);
+
+  return ly_rational2scm (unsmob_moment (mom)->grace_part_);
+}
+
 LY_DEFINE (ly_moment_grace_numerator, "ly:moment-grace-numerator",
            1, 0, 0, (SCM mom),
            "Extract numerator from grace timing.")
@@ -134,6 +143,17 @@ LY_DEFINE (ly_moment_grace_denominator, "ly:moment-grace-denominator",
 
   return scm_from_int64 (ma->grace_part_.denominator ());
 }
+
+LY_DEFINE (ly_moment_main, "ly:moment-main",
+           1, 0, 0, (SCM mom),
+           "Extract main timing as a rational number from @var{mom}.")
+{
+  LY_ASSERT_SMOB (Moment, mom, 1);
+
+  return ly_rational2scm (unsmob_moment (mom)->main_part_);
+}
+
+
 LY_DEFINE (ly_moment_main_numerator, "ly:moment-main-numerator",
            1, 0, 0, (SCM mom),
            "Extract numerator from main timing.")