6 #include "simplestaff.hh"
7 #include "simplewalker.hh"
10 #include "notehead.hh"
14 #include "clefitem.hh"
17 #include "localkeyitem.hh"
20 parse_grouping(svec<Scalar> a)
22 Rhythmic_grouping ret;
26 for (int i= 0 ; i < a.sz(); i++)
29 for (int i=0; i < r.sz(); i++) {
30 ret.divisions.add(here);
32 here += one_beat * r[i];
33 Rhythmic_grouping *child =new Rhythmic_grouping(Interval(last, here));
35 ret.children.add(child);
37 ret.divisions.add(here);
41 Simple_walker::do_INTERPRET_command(Command*com)
43 svec<Scalar> args(com->args);
45 if (com->args[0] == "GROUPING") {
46 default_grouping = parse_grouping(args);
47 }else if (com->args[0] == "BAR") {
48 local_key_.reset(key_);
49 current_grouping = default_grouping;
50 } else if (com->args[0] == "KEY") {
54 oldkey_undo = new svec<int>( key_.oldkey_undo(args));
57 typesetkey = key_.read(args);
58 local_key_.reset(key_);
59 } else if (com->args[0] == "CLEF") {
62 WARN << " ignoring INTERPRET command: " << com->args[0]<< '\n';
67 Simple_walker::do_TYPESET_command(Command*com)
69 /* ignore these commands if non-default versions have been
71 if (com->args[0] == "CURRENTKEY")
77 if (com->args[0] == "CURRENTCLEF") {
83 Item* i = staff()->get_TYPESET_item(com);
87 if (com->args[0] == "KEY") {
89 ((Keyitem*) i)->read(*oldkey_undo);
94 ((Keyitem*) i)->read(typesetkey); // ugh
97 if (com->args[0] == "CLEF"||com->args[0] == "CURRENTCLEF") {
99 Clef_item*c=(Clef_item*)i;
101 c->change = (break_status != BREAK_POST - BREAK_PRE);
103 col()->typeset_item_directional(i, 1, break_status);
107 Simple_walker::do_local_key(Note_req*n)
109 if ( local_key_.oct(n->octave).acc(n->name) != n->accidental) {
110 if (!local_key_item_) {
111 local_key_item_ = staff()->get_local_key_item();
112 local_key_item_->c0_position = clef_.c0_pos;
115 local_key_item_->add(n->octave, n->name, n->accidental);
116 local_key_.oct(n->octave).set(n->name, n->accidental);
121 Simple_walker::do_note(Rhythmic_req*rq)
123 Simple_column*c = col();
124 Simple_staff *s = staff();
127 Note_req * req = rq->note() ;
128 const Voice *v = req->elt->voice_;
130 Notehead*n = s->get_notehead(req, clef_.c0_pos);
133 int sidx =find_slur(v);
135 pending_slurs[sidx]->add(n);
143 c->typeset_item( s->get_rest(rq->rest()) );
148 Simple_walker::process_requests()
150 Simple_column*c = col();
151 Simple_staff *s = staff();
152 if (c->beam_&& c->beam_->spantype == Span_req::START) {
154 error("Too many beams (t = "
155 +String(c->when())+")");
158 for (int i=0; i < c->slurs.sz(); i++) {
159 Slur_req*sl = c->slurs[i];
161 if (sl->spantype == Span_req::START) {
162 if (find_slur(sl->elt->voice_ )>=0)
163 error("Too many slurs in voice");
164 pending_slur_reqs.add(sl);
165 pending_slurs.add(new Slur);
170 stem_ = s->get_stem(c->stem_->stem(), c->stem_requester_len);
173 for (int i = 0; i < c->notes.sz(); i ++) {
174 do_note(c->notes[i]);
179 error("beamed note should have a stem (t = "
180 +String(c->when())+")");
184 c->typeset_item(stem_);
185 /* needed, otherwise placement of
186 local_key fucks up */
187 // stem_->set_default_extents();
188 // can somebody explain myself?
190 if (c->beam_&& c->beam_->spantype == Span_req::STOP) {
191 pscore_->typeset_spanner(beam_, s->theline);
194 for (int i = 0; i < noteheads.sz(); i++) {
195 c->typeset_item(noteheads[i]);
197 noteheads.set_size(0);
199 if (local_key_item_) {
200 c->typeset_item_directional(local_key_item_, -1);
206 for (int i=0; i < c->slurs.sz(); i++) {
207 Slur_req*sl = c->slurs[i];
209 if (sl->spantype == Span_req::STOP) {
210 int idx = find_slur(sl->elt->voice_);
212 error("can't find slur to end");
214 pscore_->typeset_spanner(pending_slurs[idx],
216 pending_slurs.del(idx);
217 pending_slur_reqs.del(idx);
223 Simple_walker::Simple_walker(Simple_staff*s)
224 : Staff_walker(s, s->theline->pscore_)
230 Local_key_item * i = s->get_local_key_item();
240 Simple_walker::staff()
242 return (Simple_staff*) staff_;
248 return (Simple_column*) *(*this);
252 Simple_walker::reset()
254 processed_clef =false;
255 processed_key = false;
259 Simple_walker::find_slur(const Voice *v)
261 for (int i=0; i < pending_slur_reqs.sz(); i++) {
262 if (pending_slur_reqs[i]->elt->voice_ == v)