X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fmoment.cc;h=b3d2fbcaa833848d30e1cd12321c895ab692f3c2;hb=6b9bfd374643d1eed1ea158777d796c57a2bcd3a;hp=5a3ff5f8fc238924fcd20f4dd7dd976d6b7d4afa;hpb=6bf1606d827527f02953add0988a4fbbf0dc0c4e;p=lilypond.git diff --git a/lily/moment.cc b/lily/moment.cc index 5a3ff5f8fc..b3d2fbcaa8 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1999--2001 Han-Wen Nienhuys + (c) 1999--2002 Han-Wen Nienhuys */ @@ -13,7 +13,6 @@ #include "warn.hh" #include "ly-smobs.icc" -IMPLEMENT_UNSMOB (Moment,moment); IMPLEMENT_SIMPLE_SMOBS (Moment); IMPLEMENT_TYPE_P (Moment, "moment?"); @@ -35,11 +34,11 @@ Moment::smobbed_copy () const int Moment::print_smob (SCM s, SCM port, scm_print_state *) { - Moment *r = (Moment *) gh_cdr (s); + Moment *r = (Moment *) ly_cdr (s); scm_puts ("#str ()); - scm_puts ((char *)str.ch_C (), port); + String str = r->string (); + scm_puts ((char *)str.to_str0 (), port); scm_puts (" >", port); return 1; @@ -48,14 +47,21 @@ Moment::print_smob (SCM s, SCM port, scm_print_state *) /* TODO: add optional factor argument. */ -SCM -make_rational (SCM n, SCM d) +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. +") { - Moment m (1,1); + Moment m (Rational (1,1)); if (SCM_INUMP (n) && SCM_INUMP (d)) { - m = Moment (gh_scm2int (n), gh_scm2int (d)); + m = Moment (Rational (gh_scm2int (n), gh_scm2int (d))); } else { @@ -65,15 +71,6 @@ make_rational (SCM n, SCM d) return m.smobbed_copy (); } - -void -init_moments () -{ - scm_c_define_gsubr ("make-moment", 2 , 0, 0, (Scheme_function_unknown) make_rational); -} - -ADD_SCM_INIT_FUNC (moms,init_moments); - SCM Moment::equal_p (SCM a, SCM b) { @@ -112,10 +109,10 @@ Moment::Moment (int m) grace_part_ = Rational( 0); } -Moment::Moment (int m, int n) +Moment::Moment (Rational m, Rational g) { - main_part_ = Rational (m,n); - grace_part_ = Rational (0); + main_part_ = m; + grace_part_ = g; } Moment::Moment (Rational m) @@ -171,8 +168,8 @@ Moment::den () const { return main_part_.den (); } int Moment::num () const { return main_part_.num (); } - -Moment::operator bool () +bool +Moment::to_bool () const { return main_part_ || grace_part_; } @@ -185,21 +182,31 @@ Moment::set_infinite (int k) String -Moment::str () const +Moment::string () const { - String s = main_part_.str (); + String s = main_part_.string (); if (grace_part_) { - s += "G" + grace_part_.str (); + s += "G" + grace_part_.string (); } return s; } Moment -Moment::operator - ( ) const +Moment::operator - () const { Moment m; - m.grace_part_ = -grace_part_; - m.main_part_ = -main_part_; + m.grace_part_ = - grace_part_; + m. main_part_ = - main_part_ ; return m; } + + +#ifdef STREAM_SUPPORT +std::ostream & +operator << (std::ostream &os, Moment const &m) +{ + os << m.string (); + return os; +} +#endif