]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
release: 1.1.58
[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--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "debug.hh"
10 #include "spanner.hh"
11 #include "paper-column.hh"
12 #include "paper-score.hh"
13 #include "molecule.hh"
14 #include "paper-outputter.hh"
15
16 void
17 Spanner::do_print() const
18 {
19 #ifndef NPRINT
20   DOUT << "Between " << classname (spanned_drul_[LEFT])
21        << " and " << classname (spanned_drul_[RIGHT]) << '\n';
22
23   if (broken_b ())
24     DOUT << "Broken in " << to_str (broken_info_.size ()) << " pieces";
25 #endif
26 }
27
28 void
29 Spanner::break_into_pieces ()
30 {
31   if (broken_b ())
32     return; 
33          
34   Item * left = spanned_drul_[LEFT];
35   Item * right = spanned_drul_[RIGHT];
36   
37   if  (left == right)
38     {
39       warning (_ ("left spanpoint is right spanpoint\n"));
40       return;
41     }
42   
43   Link_array<Item> break_points = pscore_l_->broken_col_range (left,right);
44
45   break_points.insert (left,0);
46   break_points.push (right);
47
48   for (int i=1; i < break_points.size(); i++) 
49     {
50       Breaking_information info;
51       info.bounds_[LEFT] = break_points[i-1];
52       info.bounds_[RIGHT] = break_points[i];
53       Direction d = LEFT;
54       do
55         {
56           Item *&pc_l = info.bounds_[d] ;
57           if (!pc_l->line_l())
58             pc_l =  pc_l->find_prebroken_piece(- d);
59
60           assert (pc_l);
61           if (!info.line_l_)
62             info.line_l_ = pc_l-> line_l ();
63           else
64             assert( info.line_l_ = pc_l->line_l ());
65           
66         }
67       while ((flip(&d))!= LEFT);
68       info.broken_spanner_l_ = 0;
69       broken_info_.push (info);
70     }
71 }
72
73 void
74 Spanner::set_my_columns()
75 {
76   Direction i = (Direction)1;
77   do 
78     {
79       if (!spanned_drul_[i]->line_l())
80         set_bounds(i,spanned_drul_[i]->find_prebroken_piece((Direction)-i));
81     } 
82   while (flip(&i) != 1);
83 }       
84
85 void
86 Spanner::set_bounds(Direction d, Item*i)
87 {
88   spanned_drul_[d] =i;
89   if (i)
90     {
91       i->used_b_ = true;
92     }
93
94   if (d== LEFT)
95     {
96       dim_cache_[X_AXIS]->parent_l_ = i->dim_cache_[X_AXIS];
97     }
98   
99   if  (spanned_drul_[Direction(-d)] == spanned_drul_[d]
100        && i)
101     warning (_f ("Spanner `%s\' with equal left and right spanpoints", classname (this)));
102 }
103
104 void
105 Spanner::do_break_processing()
106 {
107   if (!line_l())
108     break_into_pieces ();
109   else 
110     handle_broken_dependencies();
111 }
112
113 Spanner::Spanner ()
114 {
115   spanned_drul_[LEFT]=0;
116   spanned_drul_[RIGHT]=0;
117 }
118
119 Spanner::Spanner (Spanner const &s)
120   : Score_element (s)
121 {
122   spanned_drul_[LEFT] = spanned_drul_[RIGHT] =0;
123 }
124
125
126 Interval
127 Spanner::do_width() const
128 {  
129   Real l = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
130   Real r = spanned_drul_[RIGHT]->absolute_coordinate (X_AXIS);
131
132   if (r< l)
133     warning ("Spanner with negative length");
134         
135   return Interval (0, r-l);
136 }
137
138 Line_of_score *
139 Spanner::line_l() const
140 {
141   if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
142     return 0;
143   if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
144     return 0;
145   return spanned_drul_[LEFT]->line_l();
146 }
147
148
149 Spanner*
150 Spanner::find_broken_piece (Line_of_score*l) const
151 {
152   for (int i=0; i < broken_info_.size (); i++)
153     {
154       Spanner *me =(Spanner*) this;
155       Breaking_information &info  = me->broken_info_[i];
156       if (info.line_l_ == l)
157         {
158           if (!info.broken_spanner_l_)
159             {
160               Spanner *span_p = dynamic_cast<Spanner*>(clone ());
161               span_p->set_bounds(LEFT,info.bounds_[LEFT]);
162               span_p->set_bounds(RIGHT,info.bounds_[RIGHT]);
163               pscore_l_->typeset_element (span_p);
164               
165               info.broken_spanner_l_ = span_p;
166               span_p->handle_broken_dependencies();
167
168             }
169           return info.broken_spanner_l_;
170         }
171     }
172
173   return 0;                                
174 }
175
176 bool
177 Spanner::broken_b() const
178 {
179   return broken_info_.size();
180 }
181
182 Array<Rod>
183 Spanner::get_rods () const
184 {
185   Array<Rod> r;
186   return r;
187 }
188
189 Array<Spring>
190 Spanner::get_springs () const
191 {
192   Array<Spring> s;
193   return s;    
194 }
195
196 void
197 Spanner::do_space_processing ()
198 {
199   Array<Rod> rs (get_rods ());
200   for (int i=0; i < rs.size (); i++)
201     {
202       rs[i].add_to_cols ();
203     }
204
205   Array<Spring> ss (get_springs ());
206   for (int i=0; i < ss.size (); i++)
207     {
208       ss[i].add_to_cols ();
209     }
210 }
211
212 void
213 Spanner::handle_broken_dependents ()
214 {
215 #if 0 // need to remove delayd breaking.
216   if (original_l_ && !original_l_->line_l ())
217     {
218       
219       /* we're the broken pieces of a spanner.
220          Check if our Y-leaning point is sane.
221        */
222       Dimension_cache *d = dim_cache_[Y_AXIS]->parent_l_;
223       if (d)
224         return;
225
226       Score_element *  ref_elt = dynamic_cast<Score_element*>(d->element_l());
227       Spanner *ref_span = dynamic_cast<Spanner*> (ref_elt);      
228       if (!ref_elt->line_l () && ref_span)
229         {
230           Spanner *broken_refpoint =  ref_span->find_broken_piece (line_l ());
231           if (broken_refpoint)
232             dim_cache_[Y_AXIS]->parent_l_ = broken_refpoint->dim_cache_[Y_AXIS];
233           else
234             programming_error ("Spanner y -refpoint lost.");
235         }
236     }
237 #endif
238 }