]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner.cc
release: 0.1.52
[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 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "debug.hh"
10 #include "spanner.hh"
11 #include "p-col.hh"
12 #include "p-score.hh"
13 #include "outputter.hh"
14
15 IMPLEMENT_IS_TYPE_B1(Spanner,Score_elem);
16
17 void
18 Spanner::do_print() const
19 {
20 #ifndef NPRINT
21   DOUT << "Between col ";
22   if (broken_into_l_arr_.size())
23     DOUT << "with broken pieces\n";
24 #endif
25 }
26
27 void
28 Spanner::break_into_pieces ()
29 {
30   if (broken_into_l_arr_.size())
31     return; 
32          
33   Item * left = spanned_drul_[LEFT];
34   Item * right = spanned_drul_[RIGHT];
35   
36   
37   Link_array<Item> break_cols = pscore_l_->broken_col_range (left,right);
38   Link_array<Spanner> broken_into_l_arr;
39
40   break_cols.insert (left,0);
41   break_cols.push (right);
42
43   for (int i=1; i < break_cols.size(); i++) 
44     {
45       Spanner* span_p = clone()->spanner ();
46       left = break_cols[i-1];
47       right = break_cols[i];
48       if (!right->line_l())
49         right = right->find_prebroken_piece(LEFT);
50       if (!left->line_l())
51         left = left->find_prebroken_piece(RIGHT);
52
53             assert (left&&right && left->line_l() == right->line_l());
54
55       span_p->set_bounds(LEFT,left);
56       span_p->set_bounds(RIGHT,right);
57         
58       pscore_l_->typeset_broken_spanner (span_p);
59       broken_into_l_arr.push (span_p);
60     }
61    
62   broken_into_l_arr_ = broken_into_l_arr;
63 }
64
65 void
66 Spanner::set_my_columns()
67 {
68   Direction i = (Direction)1;
69   do 
70     {
71       if (!spanned_drul_[i]->line_l())
72         set_bounds(i,spanned_drul_[i]->find_prebroken_piece((Direction)-i));
73     } 
74   while (flip(&i) != 1);
75 }       
76
77
78 void
79 Spanner::set_bounds(Direction d, Item*i)
80 {
81   if (spanned_drul_[d])
82     spanned_drul_[d]->attached_span_l_arr_.substitute(this,0);
83   
84   spanned_drul_[d] =i;
85   if (i)
86     i->attached_span_l_arr_.push(this);
87
88   if  (spanned_drul_[Direction(-d)] == spanned_drul_[d]
89        && i)
90     warning ("Spanner (" + String (name ()) + ") with equal left and right spanpoints.");
91 }
92
93 void
94 Spanner::do_break_processing()
95 {
96   if (!line_l())
97     {
98       break_into_pieces ();
99       for (int i=0; i < broken_into_l_arr_.size(); i++)
100         broken_into_l_arr_[i]->handle_broken_dependencies();
101     }
102   else 
103     {
104       handle_broken_dependencies();
105     }
106 }
107
108
109 Spanner::Spanner()
110 {
111   spanned_drul_[LEFT]=0;
112   spanned_drul_[RIGHT]=0;
113 }
114
115 void
116 Spanner::do_brew_molecule () 
117 {
118   if (transparent_b_)
119     return ;
120   Molecule *output= brew_molecule_p ();
121   Offset left_off (spanned_drul_[LEFT]->absolute_coordinate(X_AXIS), 0);
122   Offset o = absolute_offset() + left_off;
123   pscore_l_->outputter_l_->output_molecule (output, o);
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   assert (r>=l);
132         
133   return Interval (0, r-l);
134 }
135
136 Line_of_score *
137 Spanner::line_l() const
138 {
139   if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
140     return 0;
141   if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
142     return 0;
143   return spanned_drul_[LEFT]->line_l();
144 }
145
146
147 Spanner*
148 Spanner::find_broken_piece (Line_of_score*l) const
149 {
150   for (int i=0; i < broken_into_l_arr_.size(); i++)
151     if (broken_into_l_arr_[i]->line_l() == l)
152       return broken_into_l_arr_[i];
153   return 0;                                
154           
155 }
156
157 bool
158 Spanner::broken_b() const
159 {
160   return broken_into_l_arr_.size();
161 }
162
163 void
164 Spanner::do_unlink() 
165 {
166   set_bounds (LEFT, 0);
167   set_bounds (RIGHT, 0);
168 }
169
170 void
171 Spanner::do_junk_links()
172 {
173   spanned_drul_[LEFT] = spanned_drul_[RIGHT] =0;
174 }
175
176 Array<Rod>
177 Spanner::get_rods () const
178 {
179   Array<Rod> r;
180   return r;
181 }
182
183 void
184 Spanner::do_space_processing ()
185 {
186   Array<Rod> rs (get_rods ());
187   for (int i=0; i < rs.size (); i++)
188     {
189       rs[i].add_to_cols ();
190     }
191 }