2 duration.cc -- implement Duration
4 source file of the LilyPond music typesetter
6 (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "duration.hh"
14 #include "lily-proto.hh"
16 #include "ly-smobs.icc"
19 Duration::compare (Duration const &left, Duration const &right)
21 return Rational::compare (left.get_length (), right.get_length ());
28 factor_ = Rational (1, 1);
31 Duration::Duration (int log, int d)
35 factor_ = Rational (1, 1);
39 Duration::compressed (Rational m) const
47 Duration::get_length () const
49 Rational mom (1 << abs (durlog_));
52 mom = Rational (1) / mom;
55 for (int i = 0; i < dots_; i++)
57 delta /= Rational (2);
65 Duration::to_string () const
70 s = "log = " + ::to_string (durlog_);
72 s = ::to_string (1 << durlog_);
74 s += ::to_string ('.', dots_);
75 if (factor_ != Moment (Rational (1, 1)))
76 s += "*" + factor_.to_string ();
81 IMPLEMENT_TYPE_P (Duration, "ly:duration?");
84 Duration::mark_smob (SCM)
89 IMPLEMENT_SIMPLE_SMOBS (Duration);
91 Duration::print_smob (SCM s, SCM port, scm_print_state *)
93 Duration *r = (Duration *) SCM_CELL_WORD_1 (s);
95 scm_puts ("#<Duration ", port);
96 scm_display (scm_makfrom0str (r->to_string ().to_str0 ()), port);
97 scm_puts (" >", port);
103 Duration::equal_p (SCM a , SCM b)
105 Duration *p = (Duration *) SCM_CELL_WORD_1 (a);
106 Duration *q = (Duration *) SCM_CELL_WORD_1 (b);
108 bool eq = p->dots_ == q->dots_
109 && p->durlog_ == q->durlog_
110 && p->factor_ == q->factor_;
112 return eq ? SCM_BOOL_T : SCM_BOOL_F;
117 Duration::duration_log () const
123 Duration::dot_count () const