1 #include "staffcommands.hh"
3 #include "parseconstruct.hh"
6 Staff_commands_at::print() const
9 PCursor<Command*> i (*this);
10 mtor << "Commands at: " << when<<"\n";
17 Staff_commands_at::OK()const
19 PCursor<Command*> i (*this);
20 for (; i.ok() && (i+1).ok(); i++)
21 if (!i->isbreak() && !(i+1)->isbreak())
22 assert(i->priority >= (i+1)->priority);
25 Staff_commands_at::Staff_commands_at(Real r)
31 Staff_commands_at::is_breakable()
33 PCursor<Command*> i(*this);
42 Staff_commands_at::set_breakable()
44 assert(!is_breakable());
48 bottom().add(new Command(k));
49 k.code = BREAK_MIDDLE;
50 bottom().add(new Command(k));
52 bottom().add(new Command(k));
54 bottom().add(new Command(k));
58 Staff_commands_at::insert_between(Command victim, PCursor<Command*> firstc,
59 PCursor<Command*> last)
61 PCursor<Command*> c(firstc+1);
62 assert(firstc < last&&last.ok());
65 if (c->priority <= victim.priority) {
66 c.insert(new Command(victim));
71 last.insert(new Command(victim));
75 Staff_commands_at::add_command_to_break(Command pre, Command mid,Command post)
77 assert(is_breakable());
78 PCursor<Command*> c ( *this), f(c), l(c);
87 insert_between(pre, f, l);
92 insert_between(mid, f, l);
97 assert(l.ok() && l->code == BREAK_END);
99 insert_between(post, f, l);
103 Staff_commands_at::add(Command c)
105 bool encapsulate =false;
110 if (c.code == INTERPRET)
112 if (c.args[0] == "BAR") {
113 Command typeset; // kut met peren
114 typeset.code = TYPESET;
115 typeset.args = c.args;
116 typeset.priority = 100;
118 } else if (c.args[0] == "KEY") {
120 typeset.code = TYPESET;
121 typeset.args.add("KEY");
122 typeset.priority = 70;
124 } else if (c.args[0] == "CLEF") {
126 typeset.code = TYPESET;
128 typeset.priority = 90;
130 } else if (c.args[0] == "METER") {
132 typeset.code = TYPESET;
134 typeset.priority = 40;
141 if (c.code == TYPESET) {
142 encapsulate = is_breakable();
143 if (c.args[0] == "BAR") {
148 { /* every line a currentkey. */
151 kc.args.add( "CURRENTKEY");
155 { /* every line a currentclef. */
158 kc.args.add( "CURRENTCLEF");
162 }else if (c.args[0] == "METER" && is_breakable()) {
167 if( c.args[0] == "KEY" && is_breakable()) {
172 }else if (c.args[0] == "CURRENTKEY" && is_breakable() ){
176 if (c.args[0] == "CURRENTCLEF" && is_breakable() ){
180 if (c.args[0] == "CLEF" && is_breakable()) {
189 add_command_to_break(pre, mid, post);
191 bottom().add(new Command(c));
196 /****************************************************************/
199 Staff_commands::OK() const
202 for (PCursor<Staff_commands_at*> i(*this); i.ok() && (i+1).ok(); i++) {
203 assert(i->when <= (i+1)->when);
211 Staff_commands::print() const
214 for (PCursor<Staff_commands_at*> i(*this); i.ok() ; i++) {
221 Staff_commands::find(Real w)
223 PCursor<Staff_commands_at*> i(bottom());
224 for (; i.ok() ; i--) {
230 Staff_commands_at*p =new Staff_commands_at(w);
241 Staff_commands::add(Command c, Real when)
243 Staff_commands_at* p = find(when);
248 Staff_commands::clean(Real l)
250 PCursor<Staff_commands_at*> i(bottom());
251 for (; i->when > l ; i=bottom()) {
254 Staff_commands_at*p = find(l);
256 if (!p->is_breakable()) {