]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
release: 1.1.34
[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 "p-col.hh"
12 #include "p-score.hh"
13 #include "molecule.hh"
14 #include "paper-outputter.hh"
15
16
17
18 void
19 Spanner::do_print() const
20 {
21 #ifndef NPRINT
22   DOUT << "Between " << classname (spanned_drul_[LEFT])
23        << " and " << classname (spanned_drul_[RIGHT]) << '\n';
24   /*  if (broken_into_l_arr_.size())
25     {
26       DOUT << "with broken pieces:\n";
27       for (int i=0; i < broken_into_l_arr_.size (); i++)
28         broken_into_l_arr_[i]->print ();
29         }*/  
30 #endif
31 }
32
33 void
34 Spanner::break_into_pieces ()
35 {
36   if (broken_b ())
37     return; 
38          
39   Item * left = spanned_drul_[LEFT];
40   Item * right = spanned_drul_[RIGHT];
41   
42   if  (left == right)
43     {
44       warning (_ ("left spanpoint is right spanpoint\n"));
45       return;
46     }
47   
48   Link_array<Item> break_points = pscore_l_->broken_col_range (left,right);
49   Link_array<Spanner> broken_into_l_arr;
50
51   break_points.insert (left,0);
52   break_points.push (right);
53
54
55   for (int i=1; i < break_points.size(); i++) 
56     {
57       Breaking_information info;
58       info.bounds_[LEFT] = break_points[i-1];
59       info.bounds_[RIGHT] = break_points[i];
60       Direction d = LEFT;
61       do
62         {
63           Item *&pc_l = info.bounds_[d] ;
64           if (!pc_l->line_l())
65             pc_l =  pc_l->find_prebroken_piece(- d);
66
67           assert (pc_l);
68           if (!info.line_l_)
69             info.line_l_ = pc_l-> line_l ();
70           else
71             assert( info.line_l_ = pc_l->line_l ());
72           
73         }
74       while ((flip(&d))!= LEFT);
75       info.broken_spanner_l_ = 0;
76       broken_info_.push (info);
77     }
78 }
79
80 void
81 Spanner::set_my_columns()
82 {
83   Direction i = (Direction)1;
84   do 
85     {
86       if (!spanned_drul_[i]->line_l())
87         set_bounds(i,spanned_drul_[i]->find_prebroken_piece((Direction)-i));
88     } 
89   while (flip(&i) != 1);
90 }       
91
92
93 void
94 Spanner::set_bounds(Direction d, Item*i)
95 {
96   if (spanned_drul_[d])
97     spanned_drul_[d]->attached_span_l_arr_.substitute(this,0);
98   
99   spanned_drul_[d] =i;
100   if (i)
101     i->attached_span_l_arr_.push(this);
102
103   if  (spanned_drul_[Direction(-d)] == spanned_drul_[d]
104        && i)
105     warning (_f ("Spanner `%s\' with equal left and right spanpoints", classname (this)));
106 }
107
108 void
109 Spanner::do_break_processing()
110 {
111   if (!line_l())
112     break_into_pieces ();
113   else 
114     handle_broken_dependencies();
115 }
116
117 Spanner::Spanner ()
118 {
119   unbroken_original_l_ =0;
120   spanned_drul_[LEFT]=0;
121   spanned_drul_[RIGHT]=0;
122 }
123
124 Spanner::Spanner (Spanner const &s)
125   :Score_element (s)
126 {
127   spanned_drul_[LEFT] = spanned_drul_[RIGHT] =0;
128   unbroken_original_l_ = 0;
129 }
130
131 void
132 Spanner::output_processing () 
133 {
134   if (transparent_b_)
135     return ;
136   output_p_ = do_brew_molecule_p ();
137   Offset left_off (spanned_drul_[LEFT]->absolute_coordinate(X_AXIS), 0);
138   Offset o = absolute_offset() + left_off;
139   pscore_l_->outputter_l_->output_molecule (output_p_, o, classname (this));
140 }
141
142 Interval
143 Spanner::do_width() const
144 {  
145   Real l = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
146   Real r = spanned_drul_[RIGHT]->absolute_coordinate (X_AXIS);
147
148   if (r< l)
149     warning ("Spanner with negative length");
150         
151   return Interval (0, r-l);
152 }
153
154 Line_of_score *
155 Spanner::line_l() const
156 {
157   if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
158     return 0;
159   if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
160     return 0;
161   return spanned_drul_[LEFT]->line_l();
162 }
163
164
165 Spanner*
166 Spanner::find_broken_piece (Line_of_score*l) const
167 {
168   for (int i=0; i < broken_info_.size (); i++)
169     {
170       Spanner *me =(Spanner*) this;
171       Breaking_information &info  = me->broken_info_[i];
172       if (info.line_l_ == l)
173         {
174           if (!info.broken_spanner_l_)
175             {
176               Spanner *span_p = dynamic_cast<Spanner*>(clone ());
177               span_p -> unbroken_original_l_ =(Spanner*)this;
178               span_p->set_bounds(LEFT,info.bounds_[LEFT]);
179               span_p->set_bounds(RIGHT,info.bounds_[RIGHT]);
180               pscore_l_->typeset_element (span_p);
181
182               
183               info.broken_spanner_l_ = span_p;
184               /*              if (Axis_group_spanner *ags
185                   = dynamic_cast<Axis_group_spanner*> (span_p))
186                 {
187                 do something
188                 }
189               */
190               span_p->handle_broken_dependencies();
191
192             }
193           return info.broken_spanner_l_;
194         }
195     }
196
197   return 0;                                
198 }
199
200 bool
201 Spanner::broken_b() const
202 {
203   return broken_info_.size();
204 }
205
206
207
208
209 Array<Rod>
210 Spanner::get_rods () const
211 {
212   Array<Rod> r;
213   return r;
214 }
215
216 void
217 Spanner::do_space_processing ()
218 {
219   Array<Rod> rs (get_rods ());
220   for (int i=0; i < rs.size (); i++)
221     {
222       rs[i].add_to_cols ();
223     }
224 }