]> git.donarmstrong.com Git - lilypond.git/blob - lily/moment.cc
release: 1.3.74
[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--2000 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 #include "ly-smobs.icc"
16
17 IMPLEMENT_UNSMOB(Moment,moment);
18 IMPLEMENT_SIMPLE_SMOBS(Moment);
19
20
21 SCM
22 Moment::mark_smob (SCM)
23 {
24   return SCM_EOL;
25 }
26
27
28 SCM
29 Moment::make_scm () const
30 {
31   Moment * m = new Moment (*this);
32   return m->smobbed_self();
33 }
34
35
36 int
37 Moment::print_smob (SCM s, SCM port, scm_print_state *)
38 {
39   Moment  *r = (Moment *) gh_cdr (s);
40      
41   scm_puts ("#<Mom ", port);
42   String str(r->str());
43   scm_puts ((char *)str.ch_C(), port);
44   scm_puts (" >", port);
45   
46   return 1;
47 }
48
49 SCM
50 make_rational (SCM n, SCM d)
51 {
52   Moment m (1,1);
53
54   if (SCM_INUMP (n) && SCM_INUMP(d))
55     {
56       m =  Moment (gh_scm2int (n), gh_scm2int (d));
57     }
58   else
59     {
60       ::error ("make-moment takes two integer arguments. Using 1/1");
61     }
62
63   return m.make_scm ();
64 }
65
66
67 void
68 init_moments ()
69 {
70   scm_make_gsubr ("make-moment", 2 , 0, 0,  (SCM(*)(...)) make_rational);
71 }
72
73 ADD_SCM_INIT_FUNC(moms,init_moments);
74
75 SCM
76 Moment::equal_p (SCM a, SCM b)
77 {
78   Moment *m1 = unsmob_moment (a);
79   Moment *m2 = unsmob_moment (b);
80       
81   return (*m1 == *m2) ? SCM_BOOL_T : SCM_BOOL_F;
82 }
83