2 duration.cc -- implement Duration
4 source file of the LilyPond music typesetter
6 (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "duration.hh"
13 #include "lily-proto.hh"
15 #include "ly-smobs.icc"
18 Duration::compare (Duration
const &left
, Duration
const &right
)
20 return Rational::compare (left
.get_length (), right
.get_length ());
27 factor_
= Rational (1, 1);
30 Duration::Duration (int log
, int d
)
34 factor_
= Rational (1, 1);
38 Duration::compressed (Rational m
) const
46 Duration::get_length () const
48 Rational
mom (1 << abs (durlog_
));
51 mom
= Rational (1) / mom
;
54 for (int i
= 0; i
< dots_
; i
++)
56 delta
/= Rational (2);
64 Duration::to_string () const
69 s
= "log = " + ::to_string (durlog_
);
71 s
= ::to_string (1 << durlog_
);
73 s
+= ::to_string ('.', dots_
);
74 if (factor_
!= Moment (Rational (1, 1)))
75 s
+= "*" + factor_
.to_string ();
79 IMPLEMENT_TYPE_P (Duration
, "ly:duration?");
82 Duration::mark_smob (SCM
)
87 IMPLEMENT_SIMPLE_SMOBS (Duration
);
89 Duration::print_smob (SCM s
, SCM port
, scm_print_state
*)
91 Duration
*r
= (Duration
*) SCM_CELL_WORD_1 (s
);
93 scm_puts ("#<Duration ", port
);
94 scm_display (scm_makfrom0str (r
->to_string ().to_str0 ()), port
);
95 scm_puts (" >", port
);
101 Duration::equal_p (SCM a
, SCM b
)
103 Duration
*p
= (Duration
*) SCM_CELL_WORD_1 (a
);
104 Duration
*q
= (Duration
*) SCM_CELL_WORD_1 (b
);
106 bool eq
= p
->dots_
== q
->dots_
107 && p
->durlog_
== q
->durlog_
108 && p
->factor_
== q
->factor_
;
110 return eq
? SCM_BOOL_T
: SCM_BOOL_F
;
114 Duration::duration_log () const
120 Duration::dot_count () const