]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur-reg.cc
release: 0.0.44
[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 void
17 Slur_register::set_feature(Features i)
18 {
19     dir_i_ = i.direction_i_;
20 }
21
22 Slur_register::Slur_register()
23 {
24     set_feature(Features::dir(0));
25 }
26
27 bool
28 Slur_register::try_request(Request *req_l)
29 {
30     if(!req_l->slur())
31         return false;
32
33     new_slur_req_l_arr_.push(req_l->slur());
34     return true;
35 }
36
37 void
38 Slur_register::acknowledge_element(Staff_elem_info info)
39 {
40     if (info.elem_p_->name() == Notehead::static_name()) { 
41         Notehead *head_p =(Notehead*) info.elem_p_ ;// ugh
42         for (int i = 0; i < slur_l_stack_.size(); i++)
43             slur_l_stack_[i]->add(head_p );
44         for (int i = 0; i < end_slur_l_arr_.size(); i++)
45             end_slur_l_arr_[i]->add(head_p);
46     }
47 }
48 /*
49   abracadabra
50   */
51 void
52 Slur_register::process_requests()
53 {
54     Array<Slur*> start_slur_l_arr_;
55     for (int i=0; i< new_slur_req_l_arr_.size(); i++) {
56         Slur_req* slur_req_l = new_slur_req_l_arr_[i];
57         // end slur: move the slur to other array
58         if (slur_req_l->spantype == Span_req::STOP) {
59             if (slur_l_stack_.empty())
60                 warning("can't find slur to end",
61                       slur_req_l->defined_ch_C_);
62             else {
63                 end_slur_l_arr_.push(slur_l_stack_.pop());
64                 requests_arr_.pop();
65             }
66         } else  if (slur_req_l->spantype == Span_req::START) {
67             // push a new slur onto stack.
68             //(use temp. array to wait for all slur STOPs)
69             Slur * s_p =new Slur;
70             requests_arr_.push(slur_req_l);
71             start_slur_l_arr_.push(s_p);
72             announce_element(Staff_elem_info(s_p, slur_req_l));
73         }
74     }
75     for (int i=0; i < start_slur_l_arr_.size(); i++)
76         slur_l_stack_.push(start_slur_l_arr_[i]);
77 }
78
79 void
80 Slur_register::pre_move_processing()
81 {
82     for (int i = 0; i < end_slur_l_arr_.size(); i++) {
83         if (dir_i_) 
84             end_slur_l_arr_[i]->dir_i_ = dir_i_;
85         typeset_element(end_slur_l_arr_[i]);
86     }
87     end_slur_l_arr_.set_size(0);
88 }
89
90 void
91 Slur_register::post_move_processing()
92 {
93     new_slur_req_l_arr_.set_size(0);
94 }
95 Slur_register::~Slur_register()
96 {
97     for (int i=0; i < requests_arr_.size(); i++) {
98         warning("unterminated slur", requests_arr_[i]->defined_ch_C_);
99     }
100 }