]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
release: 1.1.42
[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_coordinate (X_AXIS), absolute_coordinate (Y_AXIS));
134   o += left_off;
135   pscore_l_->outputter_l_->output_molecule (output_p_, o, classname (this));
136 }
137
138 Interval
139 Spanner::do_width() const
140 {  
141   Real l = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
142   Real r = spanned_drul_[RIGHT]->absolute_coordinate (X_AXIS);
143
144   if (r< l)
145     warning ("Spanner with negative length");
146         
147   return Interval (0, r-l);
148 }
149
150 Line_of_score *
151 Spanner::line_l() const
152 {
153   if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
154     return 0;
155   if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
156     return 0;
157   return spanned_drul_[LEFT]->line_l();
158 }
159
160
161 Spanner*
162 Spanner::find_broken_piece (Line_of_score*l) const
163 {
164   for (int i=0; i < broken_info_.size (); i++)
165     {
166       Spanner *me =(Spanner*) this;
167       Breaking_information &info  = me->broken_info_[i];
168       if (info.line_l_ == l)
169         {
170           if (!info.broken_spanner_l_)
171             {
172               Spanner *span_p = dynamic_cast<Spanner*>(clone ());
173               span_p->set_bounds(LEFT,info.bounds_[LEFT]);
174               span_p->set_bounds(RIGHT,info.bounds_[RIGHT]);
175               pscore_l_->typeset_element (span_p);
176
177               
178               info.broken_spanner_l_ = span_p;
179               span_p->handle_broken_dependencies();
180
181             }
182           return info.broken_spanner_l_;
183         }
184     }
185
186   return 0;                                
187 }
188
189 bool
190 Spanner::broken_b() const
191 {
192   return broken_info_.size();
193 }
194
195
196
197
198 Array<Rod>
199 Spanner::get_rods () const
200 {
201   Array<Rod> r;
202   return r;
203 }
204
205 void
206 Spanner::do_space_processing ()
207 {
208   Array<Rod> rs (get_rods ());
209   for (int i=0; i < rs.size (); i++)
210     {
211       rs[i].add_to_cols ();
212     }
213 }