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"
26 parse_grouping(Array
<Scalar
> const &a
)
29 Array
<Moment
> grouplen_arr
;
30 for (int i
= 0 ; i
< a
.size()/2; ) {
32 grouplen_arr
.push(Moment(1,(int) a
[i
++]));
36 Array
<Rhythmic_grouping
*> children
;
37 for (int i
=0; i
< r
.size(); i
++) {
40 here
+= grouplen_arr
[i
] * Rational(r
[i
]);
42 new Rhythmic_grouping(MInterval(last
, here
), r
[i
] ));
44 return Rhythmic_grouping(children
);
50 Simple_walker::do_INTERPRET_command(Command
*com
)
52 Array
<Scalar
> args(com
->args
);
54 if (com
->args
[0] == "GROUPING") {
55 default_grouping
= parse_grouping(args
);
56 }else if (com
->args
[0] == "NEWMEASURE") {
57 local_key_
.reset(key_
);
59 } else if (com
->args
[0] == "KEY") {
61 if (col()->when() > Moment(0)) {
63 oldkey_undo
= new Array
<int>( key_
.oldkey_undo(args
));
66 typesetkey
= key_
.read(args
);
67 local_key_
.reset(key_
);
68 } else if (com
->args
[0] == "CLEF") {
71 WARN
<< " ignoring INTERPRET command: " << com
->args
[0]<< '\n';
76 Simple_walker::do_TYPESET_command(Command
*com
)
78 /* ignore these commands if non-default versions have been
80 if (com
->args
[0] == "CURRENTKEY")
84 com
->args
[0] = "KEY"; // urgh
86 if (com
->args
[0] == "CURRENTCLEF") {
90 if (com
->args
[0] == "BAR") {
92 if (processed_bar_priority
> com
->priority
)
95 processed_bar_priority
= com
->priority
;
98 Item
* i
= staff()->get_TYPESET_item(com
);
102 if (com
->args
[0] == "KEY") {
103 ((Keyitem
*) i
)->read(clef_
);
105 ((Keyitem
*) i
)->read(*oldkey_undo
);
109 processed_key
= true;
111 ((Keyitem
*) i
)->read(typesetkey
); // ugh
114 if (com
->args
[0] == "CLEF"||com
->args
[0] == "CURRENTCLEF") {
115 processed_clef
=true;
116 Clef_item
*c
=(Clef_item
*)i
;
118 c
->change
= (break_status
!= BREAK_POST
- BREAK_PRE
);
120 col()->typeset_item_directional(i
, 1, break_status
);
124 Simple_walker::do_local_key(Note_req
*n
,Notehead
* head_p
)
126 if ( local_key_
.oct(n
->octave
).acc(n
->notename
) != n
->accidental
) {
127 if (!local_key_item_
) {
128 local_key_item_
= staff()->get_local_key_item();
129 local_key_item_
->c0_position
= clef_
.c0_pos
;
131 local_key_item_
->add(head_p
);
132 local_key_item_
->add(n
->octave
, n
->notename
, n
->accidental
);
133 local_key_
.oct(n
->octave
).set(n
->notename
, n
->accidental
);
138 Simple_walker::do_note(Note_info n
)
140 Simple_column
*c
= col();
141 Simple_staff
*s
= staff();
144 Note_req
* req
= n
.rq
->note() ;
145 const Voice
*v
= req
->elt_l_
->voice_l_
;
147 Notehead
*n
= s
->get_notehead(req
, clef_
.c0_pos
);
152 if (current_grouping
) {
153 current_grouping
->add_child(
154 c
->tdescription_
->whole_in_measure
, req
->duration());
157 int sidx
=find_slur(v
);
159 pending_slurs
[sidx
]->add(n
);
164 } else if (n
.rq
->rest()) {
165 rhythmic
= s
->get_rest(n
.rq
->rest());
166 c
->typeset_item(rhythmic
);
168 for (int i
= 0; i
< n
.scripts
.size(); i
++) {
169 Script
* s_p
=new Script(n
.scripts
[i
], 10);
170 s_p
->set_support(rhythmic
);
171 s_p
->set_stem(stem_
);
172 c
->typeset_item(s_p
); // UGR
177 Simple_walker::process_requests()
179 Simple_column
*c
= col();
180 Simple_staff
*s
= staff();
182 if (c
->beam_
&& c
->beam_
->spantype
== Span_req::START
) {
184 error("Too many beams (t = " +String(c
->when())+")");
186 assert(!current_grouping
);
187 current_grouping
= new Rhythmic_grouping
;
190 for (int i
=0; i
< c
->slurs
.size(); i
++) {
191 Slur_req
*sl
= c
->slurs
[i
];
193 if (sl
->spantype
== Span_req::START
) {
194 if (find_slur(sl
->elt_l_
->voice_l_
)>=0)
195 error( "Too many slurs in voice", sl
->defined_ch_c_l_m
);
196 pending_slur_reqs
.push(sl
);
197 pending_slurs
.push(new Slur
);
202 c
->typeset_item(new Text_item(c
->text_
, 10)); // UGR
206 stem_
= s
->get_stem(c
->stem_
->stem());
209 for (int i
= 0; i
< c
->notes
.size(); i
++) {
210 do_note(c
->notes
[i
]);
215 WARN
<<"beamed note should have a stem (t = "
216 <<String(c
->when())<<")\n";
223 c
->typeset_item(stem_
);
224 /* needed, otherwise placement of
225 local_key fucks up */
228 if (c
->beam_
&& c
->beam_
->spantype
== Span_req::STOP
) {
230 error( "No beam to end", c
->beam_
->defined_ch_c_l_m
);
232 default_grouping
.extend(current_grouping
->interval());
233 beam_
->set_grouping(default_grouping
, *current_grouping
);
234 pscore_l_
->typeset_spanner(beam_
, s
->theline_l_
);
236 if (c
->beam_
->nplet
) {
237 Text_spanner
* t
= new Text_spanner
;
238 t
->set_support(beam_
);
239 t
->spec
.align_i_
= 0;
240 t
->spec
.text_str_
= c
->beam_
->nplet
;
241 pscore_l_
->typeset_spanner(t
, s
->theline_l_
);
245 delete current_grouping
;
248 for (int i
= 0; i
< noteheads
.size(); i
++) {
249 c
->typeset_item(noteheads
[i
]);
251 noteheads
.set_size(0);
253 if (local_key_item_
) {
254 c
->typeset_item(local_key_item_
);
260 for (int i
=0; i
< c
->slurs
.size(); i
++) {
261 Slur_req
*sl
= c
->slurs
[i
];
263 if (sl
->spantype
== Span_req::STOP
) {
264 int idx
= find_slur(sl
->elt_l_
->voice_l_
);
266 error( "can't find slur end", sl
->defined_ch_c_l_m
);
268 pscore_l_
->typeset_spanner(pending_slurs
[idx
],
270 pending_slurs
.del(idx
);
271 pending_slur_reqs
.del(idx
);
276 Simple_walker::Simple_walker(Simple_walker
const&)
282 Simple_walker::~Simple_walker()
284 if (pending_slurs
.size())
285 WARN
<< "destructing " << pending_slurs
.size() << " Pending slurs ";
287 WARN
<< "destructing Beam\n";
289 WARN
<<"destructing Local_key_item\n";
291 WARN
<< "destructing Stem\n";
292 delete local_key_item_
;
298 Simple_walker::Simple_walker(Simple_staff
*s
)
299 : Staff_walker(s
, s
->theline_l_
->pscore_l_
)
304 current_grouping
= 0;
305 Local_key_item
* i
= s
->get_local_key_item();
315 Simple_walker::staff()
317 return (Simple_staff
*) staff_l_
;
323 return (Simple_column
*) *(*this);
327 Simple_walker::do_post_move()
329 processed_clef
=false;
330 processed_key
= false;
331 processed_bar_priority
= 0;
335 Simple_walker::find_slur(const Voice
*v
)
337 for (int i
=0; i
< pending_slur_reqs
.size(); i
++) {
338 if (pending_slur_reqs
[i
]->elt_l_
->voice_l_
== v
)