2 duration.cc -- implement Duration, Plet,
4 source file of the LilyPond music typesetter
6 (c) 1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "lily-proto.hh"
16 #include "duration.hh"
17 #include "ly-smobs.icc"
22 Duration::compare (Duration
const &left
, Duration
const &right
)
24 return Rational::compare (left
.length_mom (), right
.length_mom ());
31 factor_
= Moment (1,1);
34 Duration::Duration (int l
, int d
)
38 factor_
= Moment (1,1);
42 Duration::compressed (Rational m
) const
50 Duration::length_mom () const
52 Rational
mom (1 << abs (durlog_i_
));
59 for (int d
= dots_i_
; d
; d
--)
71 Duration::str () const
73 String s
= to_str (durlog_i_
) + to_str ('.', dots_i_
);
74 if (factor_
!= Moment (1,1))
76 s
+= "*" + factor_
.str ();
82 IMPLEMENT_TYPE_P(Duration
, "duration?");
83 IMPLEMENT_UNSMOB(Duration
, duration
);
86 Duration::mark_smob (SCM
)
91 IMPLEMENT_SIMPLE_SMOBS(Duration
);
95 Duration::print_smob (SCM s
, SCM port
, scm_print_state
*)
97 Duration
*r
= (Duration
*) gh_cdr (s
);
99 scm_puts ("#<Duration ", port
);
100 scm_display (ly_str02scm (r
->str().ch_C()), port
);
101 scm_puts (" >", port
);
107 Duration::equal_p (SCM a
, SCM b
)
109 Duration
*p
= (Duration
*) gh_cdr (a
);
110 Duration
*q
= (Duration
*) gh_cdr (b
);
112 bool eq
= p
->dots_i_
== q
->dots_i_
113 && p
->durlog_i_
== q
->durlog_i_
114 && p
->factor_
== q
->factor_
;
116 return eq
? SCM_BOOL_T
: SCM_BOOL_F
;
119 MAKE_SCHEME_CALLBACK(Duration
, less_p
, 2);
121 Duration::less_p (SCM p1
, SCM p2
)
123 Duration
*a
= unsmob_duration (p1
);
124 Duration
*b
= unsmob_duration (p2
);
126 if (compare(*a
, *b
) < 0 )
134 make_duration (SCM l
, SCM d
)
136 Duration
p( gh_scm2int (l
), gh_scm2int (d
));
137 return p
.smobbed_copy ();
143 scm_make_gsubr ("make-duration", 2, 0, 0, (Scheme_function_unknown
)make_duration
);
146 ADD_SCM_INIT_FUNC(duration
, add_funcs
);
149 Duration::smobbed_copy ()const
151 Duration
* p
= new Duration (*this);
152 return p
->smobbed_self ();
156 Duration::duration_log () const
162 Duration::dot_count () const