]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
release: 0.1.14
[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 #include "outputter.hh"
14
15 IMPLEMENT_IS_TYPE_B1(Spanner,Score_elem);
16
17 void
18 Spanner::do_print() const
19 {
20 #ifndef NPRINT
21   DOUT << "Between col ";
22   if (broken_into_l_arr_.size())
23     DOUT << "with broken pieces\n";
24 #endif
25 }
26
27 void
28 Spanner::break_into_pieces ()
29 {
30   if (broken_into_l_arr_.size())
31     return; 
32          
33   Item * left = spanned_drul_[LEFT];
34   Item * right = spanned_drul_[RIGHT];
35   
36   
37   Link_array<Item> break_cols = pscore_l_->broken_col_range (left,right);
38   Link_array<Spanner> broken_into_l_arr;
39
40   break_cols.insert (left,0);
41   break_cols.push (right);
42
43   for (int i=1; i < break_cols.size(); i++) 
44     {
45       Spanner* span_p = clone()->spanner ();
46       left = break_cols[i-1];
47       right = break_cols[i];
48       if (!right->line_l())
49         right = right->find_prebroken_piece(-1);
50       if (!left->line_l())
51         left = left->find_prebroken_piece(1);
52
53             assert (left&&right && left->line_l() == right->line_l());
54
55       span_p->set_bounds(LEFT,left);
56       span_p->set_bounds(RIGHT,right);
57         
58       pscore_l_->typeset_broken_spanner (span_p);
59       broken_into_l_arr.push (span_p);
60     }
61    
62   broken_into_l_arr_ = broken_into_l_arr;
63 }
64
65 void
66 Spanner::set_my_columns()
67 {
68   Direction i = (Direction)1;
69   do 
70     {
71       if (!spanned_drul_[i]->line_l())
72         set_bounds(i,spanned_drul_[i]->find_prebroken_piece(-i));
73     } 
74   while ((i*=-1) != 1);
75 }       
76
77
78 void
79 Spanner::set_bounds(Direction d, Item*i)
80 {
81     
82   if (spanned_drul_[d])
83     spanned_drul_[d]->attached_span_l_arr_.substitute(this,0);
84   
85   spanned_drul_[d] =i;
86   if (i)
87     i->attached_span_l_arr_.push(this);
88
89   assert (!spanned_drul_[d] ||
90           spanned_drul_[Direction(-d)] != spanned_drul_[d]);
91
92 }
93
94 void
95 Spanner::do_break_processing()
96 {
97   if (!line_l())
98     {
99       break_into_pieces ();
100       for (int i=0; i < broken_into_l_arr_.size(); i++)
101         broken_into_l_arr_[i]->handle_broken_dependencies();
102     }
103   else 
104     {
105       handle_broken_dependencies();
106     }
107 }
108
109
110 Spanner::Spanner()
111 {
112   spanned_drul_[LEFT]=0;
113   spanned_drul_[RIGHT]=0;
114 }
115
116 void
117 Spanner::do_brew_molecule () 
118 {
119   if (transparent_b_)
120     return ;
121   Molecule *output= brew_molecule_p ();
122   Offset left_off (spanned_drul_[LEFT]->absolute_coordinate(X_AXIS), 0);
123   Offset o = absolute_offset() + left_off;
124   pscore_l_->outputter_l_->output_molecule (output, o);
125 }
126
127 Interval
128 Spanner::do_width() const
129 {
130   Real l = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
131   Real r = spanned_drul_[RIGHT]->absolute_coordinate (X_AXIS);
132   assert (r>=l);
133         
134   return Interval (0, r-l);
135 }
136
137 Line_of_score *
138 Spanner::line_l() const
139 {
140   if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
141     return 0;
142   if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
143     return 0;
144   return spanned_drul_[LEFT]->line_l();
145 }
146
147
148 Spanner*
149 Spanner::find_broken_piece (Line_of_score*l) const
150 {
151   for (int i=0; i < broken_into_l_arr_.size(); i++)
152     if (broken_into_l_arr_[i]->line_l() == l)
153       return broken_into_l_arr_[i];
154   return 0;                                
155           
156 }
157
158 bool
159 Spanner::broken_b() const
160 {
161   return broken_into_l_arr_.size();
162 }
163
164 void
165 Spanner::do_unlink() 
166 {
167   if (spanned_drul_[LEFT]) 
168     {
169       spanned_drul_[LEFT]->attached_span_l_arr_.substitute (this,0);
170       spanned_drul_[LEFT] =0;
171     }
172   if (spanned_drul_[RIGHT]) 
173     {
174       spanned_drul_[RIGHT]->attached_span_l_arr_.substitute (this,0);
175       spanned_drul_[RIGHT] = 0;
176     }
177 }
178
179 void
180 Spanner::do_junk_links()
181 {
182   spanned_drul_[LEFT] = spanned_drul_[RIGHT] =0;
183 }