]> git.donarmstrong.com Git - lilypond.git/blob - src/inputcursor.cc
release: 0.0.16
[lilypond.git] / src / inputcursor.cc
1 /*
2   it still sucks.
3   */
4
5 #include "inputcommands.hh"
6 #include "inputcommand.hh"
7 #include "debug.hh"
8 #include "staffcommands.hh"
9 #include "getcommand.hh"
10 #include "command.hh"
11
12 void
13 interpret_meter(Input_command *c, int &beats_per_meas, int& one_beat,
14                 Real& whole_per_measure)
15 {
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);
19 }
20
21 Real
22 Input_cursor::when()const
23 {
24     return (*this)->when; 
25 }
26
27 void
28 Input_cursor::print() const
29 {
30 #ifndef  NPRINT
31     mtor << "meter " << whole_per_measure
32          << " pos "<< bars << ":" << whole_in_measure <<'\n';
33 #endif
34 }
35         
36 void
37 Input_cursor::reset()
38 {
39     whole_per_measure = 1.0;    // ?
40     whole_in_measure =0.0;
41     bars = 0;
42     last=0;    
43 }
44
45 Input_cursor :: Input_cursor(PCursor<Input_command*>c)
46     :PCursor<Input_command*>(c)
47 {
48     reset();    
49 }
50
51 void
52 Input_cursor::sync()
53 {
54     assert(ok());
55     
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;  
60     }
61     if (whole_in_measure < 1e-5) // ugr
62         whole_in_measure = 0.0;
63 }
64
65 void
66 Input_cursor::operator++(int)
67 {    
68     last = when();
69     (*(PCursor<Input_command*> *) this) ++;
70
71     if (ok()) { 
72         sync();
73         if (ptr()->args[0] == "METER") {
74             int i,j;        
75             interpret_meter(ptr(), i, j, whole_per_measure);
76         }
77     }
78 }
79
80 void
81 Input_cursor::addbot(Input_command*c)
82 {
83     assert(!ok());    
84     add(c);
85 }
86
87
88 void
89 Input_cursor::add(Input_command*c)
90 {
91     PCursor<Input_command*> ::add(c);
92     (*this)++;
93 }
94
95 void
96 Input_cursor::last_command_here()
97 {
98     assert(ok());
99     PCursor<Input_command*> next = (*this)+1;
100     while (next.ok() && next->when == when()){
101         *this = next;
102         next = *this +1;
103         
104     }
105 }
106
107 void
108 Input_cursor::setpartial(Real p)
109 {
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());
114
115     whole_in_measure = whole_per_measure - p;   
116 }