]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
release: 1.1.35
[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   spanned_drul_[d] =i;
97   if (i)
98     {
99       i->used_b_ = true;
100     }
101   
102   if  (spanned_drul_[Direction(-d)] == spanned_drul_[d]
103        && i)
104     warning (_f ("Spanner `%s\' with equal left and right spanpoints", classname (this)));
105 }
106
107 void
108 Spanner::do_break_processing()
109 {
110   if (!line_l())
111     break_into_pieces ();
112   else 
113     handle_broken_dependencies();
114 }
115
116 Spanner::Spanner ()
117 {
118   spanned_drul_[LEFT]=0;
119   spanned_drul_[RIGHT]=0;
120 }
121
122 Spanner::Spanner (Spanner const &s)
123   :Score_element (s)
124 {
125   spanned_drul_[LEFT] = spanned_drul_[RIGHT] =0;
126 }
127
128 void
129 Spanner::output_processing () 
130 {
131   if (get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
132     return;
133
134   output_p_ = do_brew_molecule_p ();
135   Offset left_off (spanned_drul_[LEFT]->absolute_coordinate(X_AXIS), 0);
136   Offset o = absolute_offset() + left_off;
137   pscore_l_->outputter_l_->output_molecule (output_p_, o, classname (this));
138 }
139
140 Interval
141 Spanner::do_width() const
142 {  
143   Real l = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
144   Real r = spanned_drul_[RIGHT]->absolute_coordinate (X_AXIS);
145
146   if (r< l)
147     warning ("Spanner with negative length");
148         
149   return Interval (0, r-l);
150 }
151
152 Line_of_score *
153 Spanner::line_l() const
154 {
155   if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
156     return 0;
157   if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
158     return 0;
159   return spanned_drul_[LEFT]->line_l();
160 }
161
162
163 Spanner*
164 Spanner::find_broken_piece (Line_of_score*l) const
165 {
166   for (int i=0; i < broken_info_.size (); i++)
167     {
168       Spanner *me =(Spanner*) this;
169       Breaking_information &info  = me->broken_info_[i];
170       if (info.line_l_ == l)
171         {
172           if (!info.broken_spanner_l_)
173             {
174               Spanner *span_p = dynamic_cast<Spanner*>(clone ());
175               span_p->set_bounds(LEFT,info.bounds_[LEFT]);
176               span_p->set_bounds(RIGHT,info.bounds_[RIGHT]);
177               pscore_l_->typeset_element (span_p);
178
179               
180               info.broken_spanner_l_ = span_p;
181               /*              if (Axis_group_spanner *ags
182                   = dynamic_cast<Axis_group_spanner*> (span_p))
183                 {
184                 do something
185                 }
186               */
187               span_p->handle_broken_dependencies();
188
189             }
190           return info.broken_spanner_l_;
191         }
192     }
193
194   return 0;                                
195 }
196
197 bool
198 Spanner::broken_b() const
199 {
200   return broken_info_.size();
201 }
202
203
204
205
206 Array<Rod>
207 Spanner::get_rods () const
208 {
209   Array<Rod> r;
210   return r;
211 }
212
213 void
214 Spanner::do_space_processing ()
215 {
216   Array<Rod> rs (get_rods ());
217   for (int i=0; i < rs.size (); i++)
218     {
219       rs[i].add_to_cols ();
220     }
221 }