2 time-description.cc -- implement Time_description
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "time-description.hh"
13 Time_description::str () const
15 String s ("Time_description { ");
17 s += String ("(") + _("cadenza") + ")";
20 s +="\ntime_signature " + (whole_per_measure_/one_beat_).str () +":" +
21 (Moment (Moment (1)/one_beat_)).str ();
22 s += "\nposition " + to_str (bars_i_) + ":"+ whole_in_measure_.str () +"\n}\n";
27 Time_description::print() const
35 Time_description::OK() const
39 assert (whole_in_measure_ < whole_per_measure_);
40 assert (Moment (0) <= whole_in_measure_);
46 Time_description::set_cadenza (bool b)
50 if (whole_in_measure_)
52 bars_i_ ++; // should do?
53 whole_in_measure_ = 0;
59 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 >= Moment (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_time_signature (int l, int o)
87 one_beat_ = Moment (1)/Moment (o);
88 whole_per_measure_ = Moment (l) * one_beat_;
92 Time_description::allow_time_signature_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 measure 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::next_bar_moment() const
128 return when_ + barleft();