]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur-reg.cc
9498dd4c7c2b667a6492959c22819957a7e0db9d
[lilypond.git] / lily / slur-reg.cc
1 /*
2   slur-reg.cc -- implement Slur_register
3
4   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
6
7 #include "proto.hh"
8 #include "plist.hh"
9 #include "musical-request.hh"
10 #include "complex-walker.hh"
11 #include "slur-reg.hh"
12 #include "slur.hh"
13 #include "debug.hh"
14 #include "notehead.hh"
15
16 bool
17 Slur_register::try_request(Request *req_l)
18 {
19     if(!req_l->slur())
20         return false;
21
22     new_slur_req_l_arr_.push(req_l->slur());
23     return true;
24 }
25
26 void
27 Slur_register::acknowledge_element(Staff_elem_info info)
28 {
29     if (info.elem_l_->name() == Notehead::static_name()) { 
30         Notehead *head_p =(Notehead*) info.elem_l_ ;// ugh
31         for (int i = 0; i < slur_l_stack_.size(); i++)
32             slur_l_stack_[i]->add(head_p );
33         for (int i = 0; i < end_slur_l_arr_.size(); i++)
34             end_slur_l_arr_[i]->add(head_p);
35     }
36 }
37 /*
38   abracadabra
39   */
40 void
41 Slur_register::process_requests()
42 {
43     Array<Slur*> start_slur_l_arr_;
44     for (int i=0; i< new_slur_req_l_arr_.size(); i++) {
45         Slur_req* slur_req_l = new_slur_req_l_arr_[i];
46         // end slur: move the slur to other array
47         if (slur_req_l->spantype == Span_req::STOP) {
48             if (slur_l_stack_.empty())
49                 
50                       slur_req_l->warning("can't find slur to end");
51             else {
52                 end_slur_l_arr_.push(slur_l_stack_.pop());
53                 requests_arr_.pop();
54             }
55         } else  if (slur_req_l->spantype == Span_req::START) {
56             // push a new slur onto stack.
57             //(use temp. array to wait for all slur STOPs)
58             Slur * s_p =new Slur;
59             requests_arr_.push(slur_req_l);
60             start_slur_l_arr_.push(s_p);
61             announce_element(Staff_elem_info(s_p, slur_req_l));
62         }
63     }
64     for (int i=0; i < start_slur_l_arr_.size(); i++)
65         slur_l_stack_.push(start_slur_l_arr_[i]);
66 }
67
68 void
69 Slur_register::pre_move_processing()
70 {
71     for (int i = 0; i < end_slur_l_arr_.size(); i++) {
72         typeset_element(end_slur_l_arr_[i]);
73     }
74     end_slur_l_arr_.set_size(0);
75 }
76
77 void
78 Slur_register::post_move_processing()
79 {
80     new_slur_req_l_arr_.set_size(0);
81 }
82 Slur_register::~Slur_register()
83 {
84     for (int i=0; i < requests_arr_.size(); i++) {
85         requests_arr_[i]->warning("unterminated slur");
86     }
87 }
88 IMPLEMENT_STATIC_NAME(Slur_register);
89 ADD_THIS_REGISTER(Slur_register);