]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur.cc
release: 0.0.68pre
[lilypond.git] / lily / slur.cc
1 /*
2   slur.cc -- implement  Slur
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 /*
10
11   TODO:
12   
13   think about crossing stems.
14   Begin and end should be treated as a Script.
15   
16  */
17 #include "slur.hh"
18 #include "scalar.hh"
19 #include "lookup.hh"
20 #include "paper-def.hh"
21 #include "note-column.hh"
22 #include "stem.hh"
23 #include "p-col.hh"
24 #include "molecule.hh"
25 #include "debug.hh"
26 #include "boxes.hh"
27
28
29
30 void
31 Slur::add(Note_column*n)
32 {
33     encompass_arr_.push(n);
34     add_dependency(n);
35 }
36
37 void
38 Slur::set_default_dir()
39 {
40     dir_i_ = -1;
41     for (int i=0; i < encompass_arr_.size(); i ++) {
42         if (encompass_arr_[i]->dir_i_ < 0) {
43             dir_i_ =1;
44             break;
45         }
46     }
47 }
48
49 void
50 Slur::do_pre_processing()
51 {
52     right_col_l_  = encompass_arr_.top()->pcol_l_;
53     left_col_l_ = encompass_arr_[0]->pcol_l_;    
54 }
55
56
57 void
58 Slur::do_substitute_dependency(Score_elem*o, Score_elem*n)
59 {
60     int i;
61     while((i = encompass_arr_.find_i((Note_column*)o->item())) >=0) {
62         if (n)
63             encompass_arr_[i] = (Note_column*)n->item();
64         else
65             encompass_arr_.del(i);
66     }
67 }
68
69
70 static int 
71 Note_column_compare(Note_column *const&n1 , Note_column* const&n2)
72 {
73     return n1->pcol_l_->rank_i() - n2->pcol_l_->rank_i();
74 }
75
76 void
77 Slur::do_post_processing()
78 {
79     encompass_arr_.sort(Note_column_compare);
80     if (!dir_i_)
81         set_default_dir();
82     Real inter_f = paper()->internote_f();
83     
84     if (encompass_arr_[0]->stem_l_) 
85         left_pos_i_ = rint(encompass_arr_[0]->stem_l_->height()[dir_i_]/inter_f);
86     else 
87         left_pos_i_ = rint ( encompass_arr_[0]->head_positions_interval()[dir_i_]);
88     
89     if (encompass_arr_.top()->stem_l_)
90         right_pos_i_ = rint(encompass_arr_.top()->stem_l_->height()[dir_i_]/inter_f);
91     else 
92         right_pos_i_ = rint (encompass_arr_.top()->head_positions_interval()[dir_i_]);
93
94     left_pos_i_ += dir_i_;
95     right_pos_i_ += dir_i_;
96 }
97 IMPLEMENT_STATIC_NAME(Slur);
98 IMPLEMENT_IS_TYPE_B1(Slur,Spanner);