]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur.cc
release: 0.0.65
[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 void
57 Slur::do_break_at(PCol*l, PCol*r) 
58 {
59     assert(l->line_l_ == r->line_l_);
60
61     Array<Note_column*> old_encompass_arr = encompass_arr_;
62     encompass_arr_.set_size(0);
63     for (int i =0; i < old_encompass_arr.size(); i++) {
64         if (old_encompass_arr[i]->pcol_l_->line_l_==l->line_l_)
65             encompass_arr_.push(old_encompass_arr[i]);
66     }
67 }
68
69 void
70 Slur::do_substitute_dependency(Score_elem*o, Score_elem*n)
71 {
72     int i;
73     while((i = encompass_arr_.find_i((Note_column*)o->item())) >=0) {
74         if (n)
75             encompass_arr_[i] = (Note_column*)n->item();
76         else
77             encompass_arr_.del(i);
78     }
79 }
80
81
82 void
83 Slur::do_post_processing()
84 {
85     if (!dir_i_)
86         set_default_dir();
87     Real inter_f = paper()->internote_f();
88     if (encompass_arr_[0]->stem_l_)
89         left_pos_i_ = rint(encompass_arr_[0]->stem_l_->height()[dir_i_]/inter_f);
90     else
91         left_pos_i_ = 0;
92     if (encompass_arr_.top()->stem_l_)
93         right_pos_i_ = rint(encompass_arr_.top()->stem_l_->height()[dir_i_]/inter_f);
94     else
95         right_pos_i_ = 0;
96
97     left_pos_i_ += dir_i_;
98     right_pos_i_ += dir_i_;
99 }
100 IMPLEMENT_STATIC_NAME(Slur);