source file of the LilyPond music typesetter
- copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
+ Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
+#include <assert.h>
#include "proto.hh"
#include "plist.hh"
#include "string.hh"
#include "moment.hh"
#include "duration.hh"
#include "duration-convert.hh"
+#include "duration-iter.hh"
// statics Duration
int Duration::division_1_i_s = 384 * 4;
-Duration::Duration( int type_i, int dots_i = 0)
+Duration::Duration ()
{
-// this breaks mi2mu quite effectively
-// assert(duration_type_b(type_i));
- type_i_ = type_i;
- dots_i_ = dots_i;
- ticks_i_ = 0;
+ durlog_i_ = 0;
+ dots_i_ = 0;
+ ticks_i_ = 0;
}
bool
-Duration::duration_type_b(int t)
-{
- int bit_i=0;
- while (t > 0)
- {
- int rem = t % 2;
- t /= 2;
- bit_i += (rem == 1);
- }
- return bit_i == 1;
-}
-
-// ugh, what's this?
-// i should be called "mom()", ... or at least "length_mom()"
-Moment
-Duration::length() const
+Duration::duration_type_b (int t)
{
- return Duration_convert::dur2_mom(*this);
+ /*
+ ugh. Assuming behavior of conversion funcs on broken input.
+ */
+ return t == Duration_convert::type2_i (Duration_convert::i2_type (t));
}
void
-Duration::set_plet(int i, int t)
+Duration::compress (Moment m)
{
- plet_.iso_i_ = i;
- plet_.type_i_ = t;
+ plet_.iso_i_ *= m.num_i ();
+ plet_.type_i_ *= m.den_i ();
}
-void
-Duration::set_ticks( int ticks_i )
+// ugh, what's this?
+// i should be called "mom ()", ... or at least "length_mom ()"
+Moment
+Duration::length () const
{
- assert( !type_i_ );
- assert( !dots_i_ );
- ticks_i_ = ticks_i;
+ return Duration_convert::dur2_mom (*this);
}
-String
-Duration::str()const
+void
+Duration::set_plet (int i, int t)
{
- return Duration_convert::dur2_str(*this);
+ plet_.iso_i_ = i;
+ plet_.type_i_ = t;
}
-Plet::Plet()
+/*
+void
+Duration::set_plet (Duration d)
{
- type_i_ = 1;
- iso_i_ = 1;
+ plet_.iso_i_ = d.plet_.iso_i_;
+ plet_.type_i_ = d.plet_.type_i_;
}
+*/
-Plet::Plet( int iso_i, int type_i )
+void
+Duration::set_ticks (int ticks_i)
{
- iso_i_ = iso_i;
- type_i_ = type_i;
+ assert (durlog_i_ <10);
+ assert (!dots_i_);
+ ticks_i_ = ticks_i;
}
-Moment
-Plet::mom()const
+String
+Duration::str () const
{
- return Moment( iso_i_, type_i_ );
+ return Duration_convert::dur2_str (*this);
}
-bool
-Duration::plet_b()
-{
- return !plet_.unit_b();
-}
bool
-Plet::unit_b()const
+Duration::plet_b ()
{
- return type_i_ == 1 && iso_i_ == 1;
+ return !plet_.unit_b ();
}