From: David Kastrup Date: Thu, 28 Jun 2012 23:48:11 +0000 (+0200) Subject: Issue 2671: Provide functions ly:moment-main and ly:moment-grace X-Git-Tag: release/2.15.42-1~39 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e0defe91bab17c90c9d2e290367d04b300ebe5bf;p=lilypond.git Issue 2671: Provide functions ly:moment-main and ly:moment-grace 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. --- diff --git a/lily/moment-scheme.cc b/lily/moment-scheme.cc index b9a7487d34..3347c4da23 100644 --- a/lily/moment-scheme.cc +++ b/lily/moment-scheme.cc @@ -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.")