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