lilypond-0.0.32
[lilypond.git] / src / staffcommands.cc
blob517e7d1dd7c0e04416a11c8ff5b3fd47aa9c57b9
1 #include "staffcommands.hh"
2 #include "debug.hh"
3 #include "parseconstruct.hh"
4 #include "getcommand.hh"
6 Moment
7 Staff_commands_at::when()
9 return tdescription_.when;
12 void
13 Staff_commands_at::print() const
15 #ifndef NPRINT
16 iter_top(*this,i);
17 mtor << "Commands at: " ;
18 tdescription_.print();
20 for (; i.ok(); i++)
21 i->print();
22 #endif
24 void
25 Staff_commands_at::OK()const
27 #ifndef NDEBUG
28 iter_top(*this,i);
29 for (; i.ok() && (i+1).ok(); i++)
30 if (!i->isbreak() && !(i+1)->isbreak())
31 assert(i->priority >= (i+1)->priority);
32 #endif
35 Staff_commands_at::Staff_commands_at(Time_description m)
36 :tdescription_(m)
41 bool
42 Staff_commands_at::is_breakable()
44 iter_top(*this,i);
45 for (; i.ok(); i++) {
46 if (i->isbreak())
47 return true;
49 return false;
52 void
53 Staff_commands_at::set_breakable()
55 if (is_breakable()) return;
57 Command k;
58 k.code = BREAK_PRE;
59 bottom().add(new Command(k));
60 k.code = BREAK_MIDDLE;
61 bottom().add(new Command(k));
62 k.code = BREAK_POST;
63 bottom().add(new Command(k));
64 k.code = BREAK_END;
65 bottom().add(new Command(k));
68 void
69 Staff_commands_at::insert_between(Command victim, PCursor<Command*> firstc,
70 PCursor<Command*> last)
72 PCursor<Command*> c(firstc+1);
73 // assert(firstc < last&&last.ok());
74 assert(firstc->code < last->code && last.ok());
76 // while (c < last) {
77 while (c->code < last->code ) {
78 if (c->priority <= victim.priority) {
79 c.insert(new Command(victim));
80 return;
82 c++;
84 last.insert(new Command(victim));
87 void
88 Staff_commands_at::add_command_to_break(Command pre, Command mid,Command post)
90 assert(is_breakable());
91 iter_top(*this,c), f(c), l(c);
93 while (!c->isbreak())
94 c++;
95 f = c++;
96 while (!c->isbreak())
97 c++;
98 l = c++;
100 insert_between(pre, f, l);
101 f = l;
102 while (!c->isbreak())
103 c++;
104 l = c++;
105 insert_between(mid, f, l);
106 f = l;
107 while (!c->isbreak())
108 c++;
109 l = c++;
110 assert(l.ok() && l->code == BREAK_END);
112 insert_between(post, f, l);
117 should move this stuff into inputlanguage.
119 void
120 Staff_commands_at::add(Command c)
122 bool encapsulate =false;
123 Command pre;
124 Command mid;
125 Command post;
127 if (c.code == INTERPRET)
128 { // UGH
129 Command typeset; // kut met peren
130 typeset.code = TYPESET;
131 typeset.args = c.args;
132 if (c.args[0] == "NEWMEASURE") {
133 add(get_defaultbar_command());
134 } else if (c.args[0] == "BAR") {
135 add(typeset);
136 c.code= NOP; // no INTERPRET (BAR) commands
137 } else if (c.args[0] == "KEY") {
138 typeset.priority = 70;
139 add(typeset);
140 } else if (c.args[0] == "CLEF") {
141 typeset.priority = 90;
142 add(typeset);
143 } else if (c.args[0] == "METER") {
144 typeset.priority = 40;
145 add(typeset);
146 return;
150 // kut en peer
151 if (c.code == TYPESET) {
152 encapsulate = is_breakable();
153 if (c.args[0] == "BAR") {
154 set_breakable();
155 encapsulate = true;
156 split_bar_command(pre,mid,post, c.args[1]);
158 { /* every line a currentkey. */
159 Command kc;
160 kc.code =TYPESET;
161 kc.args.push( "CURRENTKEY");
162 kc.priority = 60;
163 add(kc);
165 { /* every line a currentclef. */
166 Command kc;
167 kc.code =TYPESET;
168 kc.args.push( "CURRENTCLEF");
169 kc.priority = 80;
170 add(kc);
173 if (is_breakable()) {
174 if (c.args[0] == "METER") {
175 mid = c;
176 pre = c;
177 post =c;
178 }else if( c.args[0] == "KEY") {
180 mid = c;
181 pre = c;
182 post = c;
183 }else if (c.args[0] == "CURRENTKEY" ){
184 post = c;
186 }else
187 if (c.args[0] == "CURRENTCLEF" ){
188 post = c;
190 }else if (c.args[0] == "CLEF") {
192 post = c;
193 pre = c;
194 mid = c;
199 if (encapsulate)
200 add_command_to_break(pre, mid, post);
201 else {
202 if (c.priority>0)
203 top().insert(new Command(c));
204 else
205 bottom().add(new Command(c));