lilypond-1.3.129
[lilypond.git] / src / timedescription.cc
blob59d1189b11b81acf2c7a9e3d8ad16e9a1bcde2d4
1 /*
2 timedescription.cc -- implement Time_description
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "timedescription.hh"
10 #include "debug.hh"
12 String
13 Time_description::str()const
15 String s( "Time_description { ");
16 if (cadenza_b_)
17 s+=String( " (cadenza) ");
18 s+= "at ";
19 s+=when_;
20 s+="\nmeter " + String(whole_per_measure_/one_beat_) +":" +
21 String(Rational(Rational(1)/one_beat_));
22 s+= "\nposition "+String( bars_i_) + ":"+ whole_in_measure_ +"\n}\n";
23 return s;
26 void
27 Time_description::print() const
29 #ifndef NPRINT
30 mtor << str();
31 #endif
33 void
34 Time_description::OK() const
36 #ifndef NDEBUG
37 if (!cadenza_b_)
38 assert(whole_in_measure_ < whole_per_measure_);
39 assert(0 <= whole_in_measure_);
40 assert(one_beat_);
41 #endif
44 void
45 Time_description::set_cadenza(bool b)
47 if (cadenza_b_ && !b) {
48 if (whole_in_measure_) {
49 bars_i_ ++;
50 whole_in_measure_ = 0;
53 cadenza_b_ = b ;
56 Time_description::Time_description()
58 whole_per_measure_ = 1;
59 whole_in_measure_ =0;
60 one_beat_ = Moment(1,4);
61 when_ = 0;
62 bars_i_ = 0;
63 cadenza_b_ = false;
66 void
67 Time_description::add(Moment dt)
69 assert(dt >= Rational(0));
70 when_ += dt;
71 whole_in_measure_ += dt;
73 while ( !cadenza_b_ && whole_in_measure_ >= whole_per_measure_ ) {
74 whole_in_measure_ -= whole_per_measure_;
75 bars_i_ ++;
79 void
80 Time_description::set_meter(int l, int o)
82 assert(o);
83 one_beat_ = Rational(1)/Moment(o);
84 whole_per_measure_ = Moment(l) * one_beat_;
85 if(whole_in_measure_)
86 error_t("Meterchange should be at start of measure", *this);
89 void
90 Time_description::setpartial(Moment p)
92 if (when_)
93 error_t ("Partial measure only allowed at beginning.", *this);
94 if (p<Rational(0)||p > whole_per_measure_)
95 error_t ("Partial measure has incorrect size", *this);
96 whole_in_measure_ = whole_per_measure_ - p;
99 Moment
100 Time_description::barleft()
102 assert(!cadenza_b_);
103 return whole_per_measure_-whole_in_measure_;
107 Time_description::compare(Time_description &t1, Time_description&t2)
109 int i = sign(t1.when_-t2.when_);
111 if (!i) {
112 assert(t1.bars_i_==t2.bars_i_);
113 assert(t1.one_beat_ == t2.one_beat_);
114 assert(t1.whole_in_measure_ == t2.whole_in_measure_);
115 assert(t1.whole_per_measure_ == t2.whole_per_measure_);
118 return i;