lilypond-1.3.80
[lilypond.git] / lily / duration.cc
blob7eb75b54237dbcfeb5ec26f0f0f68887dd625007
1 /*
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>
9 */
11 #include <assert.h>
13 #include "lily-proto.hh"
14 #include "string.hh"
15 #include "moment.hh"
16 #include "duration.hh"
18 Duration::Duration ()
20 durlog_i_ = 0;
21 dots_i_ = 0;
22 tuplet_iso_i_ = 1;
23 tuplet_type_i_ = 1;
26 void
27 Duration::compress (Rational m)
29 tuplet_iso_i_ *= m.num_i ();
30 tuplet_type_i_ *= m.den_i ();
33 Rational
34 Duration::length_mom () const
36 Rational mom (1 << abs (durlog_i_));
38 if (durlog_i_> 0)
39 mom = Moment (1)/mom;
41 Rational delta = mom;
43 for (int d = dots_i_; d; d--)
45 delta /= Moment (2);
46 mom += delta;
49 return mom * Moment (tuplet_iso_i_, tuplet_type_i_);
52 void
53 Duration::set_plet (int i, int t)
55 tuplet_iso_i_ = i;
56 tuplet_type_i_ = t;
60 String
61 Duration::str () const
63 return to_str (durlog_i_) + to_str ('.', dots_i_);
67 bool
68 Duration::plet_b ()
70 return tuplet_iso_i_ != 1 || tuplet_type_i_ != 1;