]> git.donarmstrong.com Git - lilypond.git/blob - lily/moment.cc
release: 1.3.29
[lilypond.git] / lily / moment.cc
1 /*   
2   moment.cc --  implement Moment
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10
11 #include "lily-guile.hh"
12 #include "moment.hh"
13 #include "warn.hh"
14
15 SCM
16 Moment::mark_smob (SCM)
17 {
18   return SCM_EOL;
19 }
20
21
22 Moment::~Moment()
23 {
24   self_scm_ = SCM_EOL;
25 }
26
27 int
28 Moment::print_smob (SCM s, SCM port, scm_print_state *)
29 {
30   Moment  *r = (Moment *) gh_cdr (s);
31      
32   scm_puts ("#<Mom ", port);
33   String str(r->str());
34   scm_puts ((char *)str.ch_C(), port);
35   scm_puts (" >", port);
36   
37   return 1;
38 }
39
40 void
41 Moment::do_smobify_self ()
42 {
43 }
44
45 SCM
46 make_rational (SCM n, SCM d)
47 {
48   Moment *r;
49   SCM retval = SCM_EOL;
50   if (SCM_INUMP (n) && SCM_INUMP(d))
51     {
52       r= new Moment (gh_scm2int (n), gh_scm2int (d));
53     }
54   else
55     {
56       ::error ("make-moment takes two integer arguments.");
57       r = new Moment (1,1);
58     }
59
60   retval = r->smobify_self ();
61   scm_unprotect_object (r->self_scm_);
62   return retval ;  
63 }
64
65 #include "ly-smobs.icc"
66
67 IMPLEMENT_UNSMOB(Moment,moment);
68 IMPLEMENT_SMOBS(Moment);
69
70 void
71 init_moments ()
72 {
73   scm_make_gsubr ("make-moment", 2 , 0, 0,  (SCM(*)(...)) make_rational);
74 }
75
76 ADD_SCM_INIT_FUNC(moms,init_moments);
77
78 SCM
79 Moment::equal_p (SCM a, SCM b)
80 {
81   Moment *m1 = SMOB_TO_TYPE(Moment, a);
82   Moment *m2 = SMOB_TO_TYPE(Moment, b);
83       
84   return (*m1 == *m2) ? SCM_BOOL_T : SCM_BOOL_F;
85 }