lilypond-1.1.13
[lilypond.git] / src / moment.cc
blob19f8571335409ea08b6fbd9441bbd19db906ebf2
1 #include "moment.hh"
2 #include "debug.hh"
4 void
5 Moment::print() const
6 {
7 mtor << " at "<<when<<'\n';
8 mtor << "meeter " << whole_per_measure << "/" << 1/one_beat
9 << "\nposition "<< bars << ":" << whole_in_measure <<'\n';
11 void
12 Moment::OK() const
14 assert(whole_in_measure < whole_per_measure && 0 <= whole_in_measure);
15 assert(one_beat);
17 Moment::Moment(Real dt, Moment const *prev)
19 if (prev) {
20 assert(dt >0);
21 *this = *prev;
22 when += + dt;
23 whole_in_measure += dt;
24 while ( whole_in_measure >= whole_per_measure ) {
25 whole_in_measure -= whole_per_measure;
26 bars ++;
28 } else { // default 4/4
29 whole_per_measure = 1;
30 whole_in_measure =0;
31 one_beat = 0.25;
32 when = 0.0;
33 bars = 0;
37 void
38 Moment::set_meter(int l, int o)
40 assert(o);
41 one_beat = 1/Real(o);
42 whole_per_measure = Real(l) * one_beat;
45 void
46 Moment::setpartial(Real p)
48 if (when)
49 error_t ("Partial measure only allowed at beginning.", when);
50 if (p<0||p > whole_per_measure)
51 error_t ("Partial measure has incorrect size", when);
52 whole_in_measure = whole_per_measure - p;
54 Real
55 Moment::barleft()
57 return whole_per_measure-whole_in_measure;