X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmoment.cc;h=edd24f8cd698b18128083d06e50b63c77afef365;hb=664070d837cc4855091455892cb942cdcedeef0c;hp=b3d2fbcaa833848d30e1cd12321c895ab692f3c2;hpb=a6ee9dcd388111e842064a8d46ab06c4897a00d2;p=lilypond.git diff --git a/lily/moment.cc b/lily/moment.cc index b3d2fbcaa8..edd24f8cd6 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1999--2002 Han-Wen Nienhuys + (c) 1999--2004 Han-Wen Nienhuys */ @@ -14,7 +14,7 @@ #include "ly-smobs.icc" IMPLEMENT_SIMPLE_SMOBS (Moment); -IMPLEMENT_TYPE_P (Moment, "moment?"); +IMPLEMENT_TYPE_P (Moment, "ly:moment?"); SCM Moment::mark_smob (SCM) @@ -23,12 +23,6 @@ Moment::mark_smob (SCM) } -SCM -Moment::smobbed_copy () const -{ - Moment * m = new Moment (*this); - return m->smobbed_self (); -} int @@ -37,40 +31,100 @@ Moment::print_smob (SCM s, SCM port, scm_print_state *) Moment *r = (Moment *) ly_cdr (s); scm_puts ("#string (); + String str = r->to_string (); scm_puts ((char *)str.to_str0 (), port); - scm_puts (" >", port); + scm_puts (">", port); return 1; } /* TODO: add optional factor argument. - */ -LY_DEFINE (make_moment,"make-moment", 2,0,0, (SCM n, SCM d), - "create the rational number with main timing @var{n}/@var{d}. - - -Moment is a point in musical time. It is consists of a pair of -rationals (@var{m},@var{g}), where @var{m} is the timing for the main -notes, and @var{g} the timing for grace notes. In absence of grace -notes, @var{g} is zero. -") +*/ +LY_DEFINE (make_moment,"ly:make-moment", 2,2,0, (SCM n, SCM d, SCM gn, SCM gd), + "Create the rational number with main timing @var{n}/@var{d}, " + "and optional grace timin @var{gn}/@var{gd}.\n" + "\n" + "\n" + "Moment is a point in musical time. It is consists of a pair of\n" + "rationals (@var{m},@var{g}), where @var{m} is the timing for the main\n" + "notes, and @var{g} the timing for grace notes. In absence of grace\n" + "notes, @var{g} is zero.\n" + ) { - Moment m (Rational (1,1)); + SCM_ASSERT_TYPE (SCM_INUMP (n), n, SCM_ARG1, __FUNCTION__, "integer"); + SCM_ASSERT_TYPE (SCM_INUMP (d), d, SCM_ARG2, __FUNCTION__, "integer"); - if (SCM_INUMP (n) && SCM_INUMP (d)) + int grace_num = 0; + if (gn != SCM_UNDEFINED) { - m = Moment (Rational (gh_scm2int (n), gh_scm2int (d))); + SCM_ASSERT_TYPE (SCM_INUMP (gn), gn, SCM_ARG3, __FUNCTION__, "integer"); + grace_num = ly_scm2int (gn); } - else + + int grace_den = 1; + if (gd != SCM_UNDEFINED) { - ::error ("make-moment takes two integer arguments. Using 1/1"); + SCM_ASSERT_TYPE (SCM_INUMP (gd), gd, SCM_ARG4, __FUNCTION__, "integer"); + grace_den = ly_scm2int (gd); } - return m.smobbed_copy (); + return Moment (Rational (ly_scm2int (n), ly_scm2int (d)), + Rational (grace_num, grace_den)).smobbed_copy (); } +LY_DEFINE (add_moment,"ly:add-moment", 2,0,0, (SCM a, SCM b), + "Add two moments." + ) +{ + Moment * ma = unsmob_moment (a); + Moment * mb = unsmob_moment (b); + SCM_ASSERT_TYPE (ma, a, SCM_ARG1, __FUNCTION__, "moment"); + SCM_ASSERT_TYPE (mb, b, SCM_ARG2, __FUNCTION__, "moment"); + + return (*ma + *mb).smobbed_copy (); +} + + +LY_DEFINE (mul_moment,"ly:mul-moment", 2,0,0, (SCM a, SCM b), + "Multiply two moments." + ) +{ + Moment * ma = unsmob_moment (a); + Moment * mb = unsmob_moment (b); + SCM_ASSERT_TYPE (ma, a, SCM_ARG1, __FUNCTION__, "moment"); + SCM_ASSERT_TYPE (mb, b, SCM_ARG2, __FUNCTION__, "moment"); + + return (*ma * *mb).smobbed_copy (); +} + + + +LY_DEFINE (div_moment,"ly:div-moment", 2,0,0, (SCM a, SCM b), + "Divide two moments." + ) +{ + Moment * ma = unsmob_moment (a); + Moment * mb = unsmob_moment (b); + SCM_ASSERT_TYPE (ma, a, SCM_ARG1, __FUNCTION__, "moment"); + SCM_ASSERT_TYPE (mb, b, SCM_ARG2, __FUNCTION__, "moment"); + + return (*ma / *mb).smobbed_copy (); +} + +LY_DEFINE (ly_moment_less_p,"ly:moment