4 #include "textspanner.hh"
11 #include "simplestaff.hh"
12 #include "simplewalker.hh"
15 #include "notehead.hh"
19 #include "clefitem.hh"
21 #include "localkeyitem.hh"
22 #include "textitem.hh"
23 #include "lyricitem.hh"
26 parse_grouping(Array<Scalar> a, Moment one_beat)
29 for (int i= 0 ; i < a.size(); i++)
33 Array<Rhythmic_grouping*> children;
34 for (int i=0; i < r.size(); i++) {
37 here += one_beat * r[i];
39 new Rhythmic_grouping(MInterval(last, here), r[i] )
42 return Rhythmic_grouping(children);
46 Simple_walker::do_INTERPRET_command(Command*com)
48 Array<Scalar> args(com->args);
50 if (com->args[0] == "GROUPING") {
51 default_grouping = parse_grouping(args,
52 col()->tdescription_->one_beat);
53 }else if (com->args[0] == "NEWMEASURE") {
54 local_key_.reset(key_);
56 } else if (com->args[0] == "KEY") {
58 if (col()->when() > Moment(0)) {
60 oldkey_undo = new Array<int>( key_.oldkey_undo(args));
63 typesetkey = key_.read(args);
64 local_key_.reset(key_);
65 } else if (com->args[0] == "CLEF") {
68 WARN << " ignoring INTERPRET command: " << com->args[0]<< '\n';
73 Simple_walker::do_TYPESET_command(Command*com)
75 /* ignore these commands if non-default versions have been
77 if (com->args[0] == "CURRENTKEY")
81 com->args[0] = "KEY"; // urgh
83 if (com->args[0] == "CURRENTCLEF") {
87 if (com->args[0] == "BAR") {
89 if (processed_bar_priority > com->priority)
92 processed_bar_priority = com->priority;
95 Item* i = staff()->get_TYPESET_item(com);
99 if (com->args[0] == "KEY") {
100 ((Keyitem*) i)->read(clef_);
102 ((Keyitem*) i)->read(*oldkey_undo);
106 processed_key = true;
108 ((Keyitem*) i)->read(typesetkey); // ugh
111 if (com->args[0] == "CLEF"||com->args[0] == "CURRENTCLEF") {
112 processed_clef =true;
113 Clef_item*c=(Clef_item*)i;
115 c->change = (break_status != BREAK_POST - BREAK_PRE);
117 col()->typeset_item_directional(i, 1, break_status);
121 Simple_walker::do_local_key(Note_req*n,Notehead* head_p)
123 if ( local_key_.oct(n->octave).acc(n->name) != n->accidental) {
124 if (!local_key_item_) {
125 local_key_item_ = staff()->get_local_key_item();
126 local_key_item_->c0_position = clef_.c0_pos;
129 local_key_item_->add(n->octave, n->name, n->accidental, head_p);
130 local_key_.oct(n->octave).set(n->name, n->accidental);
135 Simple_walker::do_note(Note_info n)
137 Simple_column*c = col();
138 Simple_staff *s = staff();
141 Note_req * req = n.rq->note() ;
142 const Voice *v = req->elt_l_->voice_;
144 Notehead*n = s->get_notehead(req, clef_.c0_pos);
149 if (current_grouping) {
150 current_grouping->add_child(
151 c->tdescription_->whole_in_measure, req->duration());
154 int sidx =find_slur(v);
156 pending_slurs[sidx]->add(n);
161 }else if (n.rq->rest()) {
162 rhythmic = s->get_rest(n.rq->rest());
163 c->typeset_item(rhythmic);
165 for (int i= 0; i < n.scripts.size(); i ++)
166 c->typeset_item(new Script(n.scripts[i], rhythmic, 10, stem_)); // UGR
170 Simple_walker::process_requests()
172 Simple_column*c = col();
173 Simple_staff *s = staff();
175 if (c->beam_&& c->beam_->spantype == Span_req::START) {
177 error("Too many beams (t = "
178 +String(c->when())+")");
180 assert(!current_grouping);
181 current_grouping = new Rhythmic_grouping;
184 for (int i=0; i < c->slurs.size(); i++) {
185 Slur_req*sl = c->slurs[i];
187 if (sl->spantype == Span_req::START) {
188 if (find_slur(sl->elt_l_->voice_ )>=0)
189 error_t("Too many slurs in voice", *col()->tdescription_);
190 pending_slur_reqs.add(sl);
191 pending_slurs.add(new Slur);
196 c->typeset_item(new Text_item(c->text_, 10)); // UGR
200 // c->typeset_item(new Lyric_item(c->lreq_p_, 10)); // UGR
204 stem_ = s->get_stem(c->stem_->stem(), c->stem_requester_len);
207 for (int i = 0; i < c->notes.size(); i ++) {
208 do_note(c->notes[i]);
213 WARN <<"beamed note should have a stem (t = "
214 <<String(c->when())<<")\n";
221 c->typeset_item(stem_);
222 /* needed, otherwise placement of
223 local_key fucks up */
226 if (c->beam_&& c->beam_->spantype == Span_req::STOP) {
227 default_grouping.extend(current_grouping->interval());
228 beam_->set_grouping(default_grouping, *current_grouping);
229 pscore_->typeset_spanner(beam_, s->theline_l_);
231 if (c->beam_->nplet) {
232 Text_spanner* t = new Text_spanner(beam_);
233 t->spec.align_i_ = 0;
234 t->spec.text_str_ = c->beam_->nplet;
235 pscore_->typeset_spanner(t, s->theline_l_);
239 delete current_grouping;
242 for (int i = 0; i < noteheads.size(); i++) {
243 c->typeset_item(noteheads[i]);
245 noteheads.set_size(0);
247 if (local_key_item_) {
248 c->typeset_item_directional(local_key_item_, -1);
254 for (int i=0; i < c->slurs.size(); i++) {
255 Slur_req *sl = c->slurs[i];
257 if (sl->spantype == Span_req::STOP) {
258 int idx = find_slur(sl->elt_l_->voice_);
260 error_t("can't find slur to end; ", *c->tdescription_);
262 pscore_->typeset_spanner(pending_slurs[idx],
264 pending_slurs.del(idx);
265 pending_slur_reqs.del(idx);
271 Simple_walker::Simple_walker(Simple_staff*s)
272 : Staff_walker(s, s->theline_l_->pscore_l_)
277 current_grouping = 0;
278 Local_key_item * i = s->get_local_key_item();
288 Simple_walker::staff()
290 return (Simple_staff*) staff_;
296 return (Simple_column*) *(*this);
300 Simple_walker::reset()
302 processed_clef =false;
303 processed_key = false;
304 processed_bar_priority = 0;
308 Simple_walker::find_slur(const Voice *v)
310 for (int i=0; i < pending_slur_reqs.size(); i++) {
311 if (pending_slur_reqs[i]->elt_l_->voice_ == v)