lilypond-1.3.8
[lilypond.git] / src / inputcursor.cc
blob4dc5f9310fefeafb1113a9d7037a412a7cc66ff2
1 /*
2 it still sucks.
3 */
5 #include "inputcommands.hh"
6 #include "inputcommand.hh"
7 #include "debug.hh"
8 #include "staffcommands.hh"
9 #include "getcommand.hh"
10 #include "command.hh"
12 void
13 interpret_meter(Input_command *c, int &beats_per_meas, int& one_beat,
14 Real& whole_per_measure)
16 beats_per_meas = c->args[1].value();
17 one_beat = c->args[2].value();
18 whole_per_measure = beats_per_meas/Real(one_beat);
21 Real
22 Input_cursor::when()const
24 return (*this)->when;
27 void
28 Input_cursor::print() const
30 #ifndef NPRINT
31 mtor << "meter " << whole_per_measure
32 << " pos "<< bars << ":" << whole_in_measure <<'\n';
33 #endif
36 void
37 Input_cursor::reset()
39 whole_per_measure = 1.0; // ?
40 whole_in_measure =0.0;
41 bars = 0;
42 last=0;
45 Input_cursor :: Input_cursor(PCursor<Input_command*>c)
46 :PCursor<Input_command*>(c)
48 reset();
51 void
52 Input_cursor::sync()
54 assert(ok());
56 whole_in_measure += when() - last;
57 while (whole_per_measure > 0 && whole_in_measure >= whole_per_measure) {
58 bars ++;
59 whole_in_measure -= whole_per_measure;
61 if (whole_in_measure < 1e-5) // ugr
62 whole_in_measure = 0.0;
65 void
66 Input_cursor::operator++(int)
68 last = when();
69 (*(PCursor<Input_command*> *) this) ++;
71 if (ok()) {
72 sync();
73 if (ptr()->args[0] == "METER") {
74 int i,j;
75 interpret_meter(ptr(), i, j, whole_per_measure);
80 void
81 Input_cursor::addbot(Input_command*c)
83 assert(!ok());
84 add(c);
88 void
89 Input_cursor::add(Input_command*c)
91 PCursor<Input_command*> ::add(c);
92 (*this)++;
95 void
96 Input_cursor::last_command_here()
98 assert(ok());
99 PCursor<Input_command*> next = (*this)+1;
100 while (next.ok() && next->when == when()){
101 *this = next;
102 next = *this +1;
107 void
108 Input_cursor::setpartial(Real p)
110 if (when())
111 error_t ("Partial measure only allowed at beginning.", when() );
112 if (p<0||p > whole_per_measure)
113 error_t ("Partial measure has incorrect size", when());
115 whole_in_measure = whole_per_measure - p;