2 time-description.cc -- implement Time_description
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "time-description.hh"
13 Time_description::str()const
15 String
s( "Time_description { ");
17 s
+=String( " (cadenza) ");
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";
27 Time_description::print() const
34 Time_description::OK() const
38 assert(whole_in_measure_
< whole_per_measure_
);
39 assert(Moment(0) <= whole_in_measure_
);
45 Time_description::set_cadenza(bool b
)
47 if (cadenza_b_
&& !b
) {
48 if (whole_in_measure_
) {
50 whole_in_measure_
= 0;
56 Time_description::Time_description()
58 whole_per_measure_
= 1;
60 one_beat_
= Moment(1,4);
67 Time_description::add(Moment dt
)
69 assert(dt
>= Rational(0));
71 whole_in_measure_
+= dt
;
73 while ( !cadenza_b_
&& whole_in_measure_
>= whole_per_measure_
) {
74 whole_in_measure_
-= whole_per_measure_
;
80 Time_description::set_meter(int l
, int o
)
83 one_beat_
= Rational(1)/Moment(o
);
84 whole_per_measure_
= Moment(l
) * one_beat_
;
86 error_t("Meterchange should be at start of measure", *this);
90 Time_description::setpartial(Moment p
)
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
;
100 Time_description::barleft()
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_
);
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_
);