2 time-description.cc -- implement Time_description
4 source file of the GNU 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
)
49 if (whole_in_measure_
)
51 bars_i_
++; // should do?
52 whole_in_measure_
= 0;
58 Time_description::Time_description()
61 whole_per_measure_
= 1;
63 one_beat_
= Moment (1,4);
65 bars_i_
= 1; // musician start counting at 1
70 Time_description::add (Moment dt
)
72 assert (dt
>= Rational (0));
74 whole_in_measure_
+= dt
;
76 while (!cadenza_b_
&& whole_in_measure_
>= whole_per_measure_
)
78 whole_in_measure_
-= whole_per_measure_
;
84 Time_description::set_meter (int l
, int o
)
87 one_beat_
= Rational (1)/Moment (o
);
88 whole_per_measure_
= Moment (l
) * one_beat_
;
92 Time_description::allow_meter_change_b()
94 return!(whole_in_measure_
);
98 retrieve error messages.
100 error messages if not possible, "" if possible
103 Time_description::try_set_partial_str (Moment p
) const
106 return ("Partial must be non-negative");
107 if (p
> whole_per_measure_
)
108 return ("Partial measure too large");
113 Time_description::setpartial (Moment p
)
115 whole_in_measure_
= whole_per_measure_
- p
;
119 Time_description::barleft() const
121 assert (!cadenza_b_
);
122 return whole_per_measure_
-whole_in_measure_
;
126 Time_description::compare (Time_description
const &t1
, Time_description
const&t2
)
128 int i
= sign (t1
.when_
-t2
.when_
);
132 assert (t1
.bars_i_
==t2
.bars_i_
);
133 assert (t1
.one_beat_
== t2
.one_beat_
);
134 assert (t1
.whole_in_measure_
== t2
.whole_in_measure_
);
135 assert (t1
.whole_per_measure_
== t2
.whole_per_measure_
);
142 Time_description::next_bar_moment() const
144 return when_
+ barleft();