]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
patch::: 1.1.37.script1
[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
25   if (broken_b ())
26     DOUT << "Broken in " << to_str (broken_info_.size ()) << " pieces";
27 #endif
28 }
29
30 void
31 Spanner::break_into_pieces ()
32 {
33   if (broken_b ())
34     return; 
35          
36   Item * left = spanned_drul_[LEFT];
37   Item * right = spanned_drul_[RIGHT];
38   
39   if  (left == right)
40     {
41       warning (_ ("left spanpoint is right spanpoint\n"));
42       return;
43     }
44   
45   Link_array<Item> break_points = pscore_l_->broken_col_range (left,right);
46   Link_array<Spanner> broken_into_l_arr;
47
48   break_points.insert (left,0);
49   break_points.push (right);
50
51
52   for (int i=1; i < break_points.size(); i++) 
53     {
54       Breaking_information info;
55       info.bounds_[LEFT] = break_points[i-1];
56       info.bounds_[RIGHT] = break_points[i];
57       Direction d = LEFT;
58       do
59         {
60           Item *&pc_l = info.bounds_[d] ;
61           if (!pc_l->line_l())
62             pc_l =  pc_l->find_prebroken_piece(- d);
63
64           assert (pc_l);
65           if (!info.line_l_)
66             info.line_l_ = pc_l-> line_l ();
67           else
68             assert( info.line_l_ = pc_l->line_l ());
69           
70         }
71       while ((flip(&d))!= LEFT);
72       info.broken_spanner_l_ = 0;
73       broken_info_.push (info);
74     }
75 }
76
77 void
78 Spanner::set_my_columns()
79 {
80   Direction i = (Direction)1;
81   do 
82     {
83       if (!spanned_drul_[i]->line_l())
84         set_bounds(i,spanned_drul_[i]->find_prebroken_piece((Direction)-i));
85     } 
86   while (flip(&i) != 1);
87 }       
88
89
90 void
91 Spanner::set_bounds(Direction d, Item*i)
92 {
93   spanned_drul_[d] =i;
94   if (i)
95     {
96       i->used_b_ = true;
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 void
126 Spanner::output_processing () 
127 {
128   if (get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
129     return;
130
131   output_p_ = do_brew_molecule_p ();
132   Offset left_off (spanned_drul_[LEFT]->absolute_coordinate(X_AXIS), 0);
133   Offset o = absolute_offset() + left_off;
134   pscore_l_->outputter_l_->output_molecule (output_p_, o, classname (this));
135 }
136
137 Interval
138 Spanner::do_width() const
139 {  
140   Real l = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
141   Real r = spanned_drul_[RIGHT]->absolute_coordinate (X_AXIS);
142
143   if (r< l)
144     warning ("Spanner with negative length");
145         
146   return Interval (0, r-l);
147 }
148
149 Line_of_score *
150 Spanner::line_l() const
151 {
152   if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
153     return 0;
154   if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
155     return 0;
156   return spanned_drul_[LEFT]->line_l();
157 }
158
159
160 Spanner*
161 Spanner::find_broken_piece (Line_of_score*l) const
162 {
163   for (int i=0; i < broken_info_.size (); i++)
164     {
165       Spanner *me =(Spanner*) this;
166       Breaking_information &info  = me->broken_info_[i];
167       if (info.line_l_ == l)
168         {
169           if (!info.broken_spanner_l_)
170             {
171               Spanner *span_p = dynamic_cast<Spanner*>(clone ());
172               span_p->set_bounds(LEFT,info.bounds_[LEFT]);
173               span_p->set_bounds(RIGHT,info.bounds_[RIGHT]);
174               pscore_l_->typeset_element (span_p);
175
176               
177               info.broken_spanner_l_ = span_p;
178               span_p->handle_broken_dependencies();
179
180             }
181           return info.broken_spanner_l_;
182         }
183     }
184
185   return 0;                                
186 }
187
188 bool
189 Spanner::broken_b() const
190 {
191   return broken_info_.size();
192 }
193
194
195
196
197 Array<Rod>
198 Spanner::get_rods () const
199 {
200   Array<Rod> r;
201   return r;
202 }
203
204 void
205 Spanner::do_space_processing ()
206 {
207   Array<Rod> rs (get_rods ());
208   for (int i=0; i < rs.size (); i++)
209     {
210       rs[i].add_to_cols ();
211     }
212 }