]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
release: 0.0.66
[lilypond.git] / lily / spanner.cc
1 /*
2   spanner.cc -- implement Spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "debug.hh"
10 #include "spanner.hh"
11 #include "p-col.hh"
12 #include "p-score.hh"
13
14 IMPLEMENT_STATIC_NAME(Spanner);
15
16 void
17 Spanner::do_print()const
18 {
19     if (broken_into_l_arr_.size())
20         mtor << "with broken pieces\n";
21 }
22
23 void
24 Spanner::break_into_pieces()
25 {
26     PCol * left = left_col_l_;
27     PCol * right = right_col_l_;
28     if(left->daddy_l_) left = left->daddy_l_;
29     if(right->daddy_l_) right = right->daddy_l_;
30     
31     
32     Link_array<PCol> break_cols = pscore_l_->broken_col_range(left,right);
33     Link_array<Spanner> broken_into_l_arr;
34
35     break_cols.insert(left,0);
36     break_cols.push(right);
37
38     for (int i=1; i < break_cols.size(); i++) {
39         Spanner* span_p = clone();
40         left = break_cols[i-1];
41         right = break_cols[i];
42         if (!right->line_l_)
43             right = right->prebreak_p_;
44         if (!left->line_l_)
45             left = left->postbreak_p_;
46
47         assert(left&&right && left->line_l_ == right->line_l_);
48
49         span_p->left_col_l_  = left;
50         span_p->right_col_l_ = right;
51         
52         pscore_l_->typeset_broken_spanner(span_p);
53         broken_into_l_arr.push( span_p );
54     }
55     
56     broken_into_l_arr_ = broken_into_l_arr;
57 }
58
59 void
60 Spanner::do_break_processing()
61 {
62     if (!left_col_l_->line_l_)
63         left_col_l_ = left_col_l_->postbreak_p_;
64     if (!right_col_l_->line_l_)
65         right_col_l_ = right_col_l_->prebreak_p_;
66      
67     
68     if (!line_l()) {
69         break_into_pieces();
70         for (int i=0; i < broken_into_l_arr_.size(); i++)
71             broken_into_l_arr_[i]->handle_broken_dependencies();
72     } else { 
73         handle_broken_dependencies();
74     }
75 }
76
77
78 Spanner::Spanner()
79 {
80     left_col_l_ = right_col_l_ = 0;
81 }
82
83
84 Interval
85 Spanner::do_width()const
86 {
87     Real r = right_col_l_->hpos;
88     Real l = left_col_l_->hpos;
89     assert(*left_col_l_ < *right_col_l_);
90     assert(r>=l);
91         
92     return Interval(0, r-l);
93 }
94
95 Line_of_score *
96 Spanner::line_l()const
97 {
98     if ( left_col_l_->line_l_ != right_col_l_->line_l_)
99         return 0;
100     return left_col_l_->line_l_;
101 }
102
103
104 Spanner*
105 Spanner::find_broken_piece(Line_of_score*l)const
106 {
107     for (int i=0; i < broken_into_l_arr_.size(); i++)
108         if(broken_into_l_arr_[i]->line_l() == l)
109             return broken_into_l_arr_[i];
110     return 0;                              
111           
112 }
113
114 bool
115 Spanner::broken_b()const
116 {
117     return broken_into_l_arr_.size();
118 }