]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/moment.cc
2002-07-13 Han-Wen <hanwen@cs.uu.nl>
[lilypond.git] / lily / moment.cc
index 1f7f62e77384cd74b5c1331537b2f5a2bbda5856..d44af366e2c294c8b9401b625eedd12253d248dd 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1999--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
@@ -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,7 +34,7 @@ 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 ("#<Mom ", port);
   String str (r->str ());
@@ -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)
@@ -196,10 +193,20 @@ Moment::str () const
 }
 
 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.str ();
+  return os;
+}
+#endif