2 duration.cc -- implement Duration, Plet,
4 source file of the LilyPond music typesetter
6 (c) 1997--2002 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_ = Rational (1,1);
34 Duration::Duration (int l, int d)
38 factor_ = Rational (1,1);
42 Duration::compressed (Rational m) const
50 Duration::length_mom () const
52 Rational mom (1 << abs (durlog_i_));
55 mom = Rational (1)/mom;
59 for (int d = dots_i_; d; d--)
61 delta /= Rational (2);
71 Duration::str () const
76 s = "log = " + to_str (durlog_i_);
78 s = to_str (1 << durlog_i_);
80 s += to_str ('.', dots_i_);
81 if (factor_ != Moment (Rational (1,1)))
83 s += "*" + factor_.str ();
89 IMPLEMENT_TYPE_P (Duration, "duration?");
92 Duration::mark_smob (SCM)
97 IMPLEMENT_SIMPLE_SMOBS (Duration);
101 Duration::print_smob (SCM s, SCM port, scm_print_state *)
103 Duration *r = (Duration *) ly_cdr (s);
105 scm_puts ("#<Duration ", port);
106 scm_display (ly_str02scm (r->str ().ch_C ()), port);
107 scm_puts (" >", port);
113 Duration::equal_p (SCM a , SCM b)
115 Duration *p = (Duration *) ly_cdr (a);
116 Duration *q = (Duration *) ly_cdr (b);
118 bool eq = p->dots_i_ == q->dots_i_
119 && p->durlog_i_ == q->durlog_i_
120 && p->factor_ == q->factor_;
122 return eq ? SCM_BOOL_T : SCM_BOOL_F;
125 MAKE_SCHEME_CALLBACK (Duration, less_p, 2);
127 Duration::less_p (SCM p1, SCM p2)
129 Duration *a = unsmob_duration (p1);
130 Duration *b = unsmob_duration (p2);
132 if (compare (*a, *b) < 0)
139 LY_DEFINE(make_duration,
140 "make-duration", 2, 0, 0, (SCM length, SCM dotcount),
142 @var{length} is the negative logarithm (base 2) of the duration:
143 1 is a half note, 2 is a quarter note, 3 is an eighth
144 note, etc. The number of dots after the note is given by
148 A duration is a musical duration, i.e. a length of time described by a
149 power of two (whole, half, quarter, etc.) and a number of augmentation
154 SCM_ASSERT_TYPE(gh_number_p(length), length, SCM_ARG1, __FUNCTION__, "integer");
155 SCM_ASSERT_TYPE(gh_number_p(dotcount), dotcount, SCM_ARG2, __FUNCTION__, "integer");
157 Duration p (gh_scm2int (length), gh_scm2int (dotcount));
158 return p.smobbed_copy ();
162 Duration::smobbed_copy ()const
164 Duration * p = new Duration (*this);
165 return p->smobbed_self ();
169 Duration::duration_log () const
175 Duration::dot_count () const