lilypond-1.3.28
[lilypond.git] / lily / staff-elem.cc
blobec4f851922a3fe1e1c4401cf93d315ed15bc061d
1 /*
2 staff-elem.cc -- implement Score_elem
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "paper-def.hh"
10 #include "lookup.hh"
11 #include "p-score.hh"
12 #include "symbol.hh"
13 #include "p-staff.hh"
14 #include "molecule.hh"
15 #include "staff-elem.hh"
16 #include "debug.hh"
18 String
19 Score_elem::TeXstring() const
21 Molecule m(*output);
22 m.translate(offset_); // ugh?
23 return m.TeXstring();
26 Score_elem::Score_elem(Score_elem const&s)
27 :dependancy_l_arr_(s.dependancy_l_arr_),
28 dependant_l_arr_(s.dependant_l_arr_)
30 status = s.status;
31 assert(!s.output);
32 output = 0;
33 pstaff_l_ = s.pstaff_l_;
34 offset_ = Offset(0,0);
37 /**
38 TODO:
39 If deleted, then remove dependant_l_arr_ depency!
41 Score_elem::~Score_elem()
43 assert(status < DELETED);
44 delete output;
45 status = DELETED;
46 output = 0;
49 void
50 Score_elem::translate(Offset O)
52 offset_ += O;
55 Interval
56 Score_elem::do_width() const
58 Interval r;
60 if (!output){
61 Molecule*m = brew_molecule_p();
62 r = m->extent().x;
63 delete m;
64 } else
65 r = output->extent().x;
66 return r;
69 Interval
70 Score_elem::width() const
72 Interval r=do_width();
74 if (!r.empty_b()) // float exception on DEC Alpha
75 r+=offset_.x;
77 return r;
79 Interval
80 Score_elem::do_height() const
82 Interval r;
83 if (!output){
84 Molecule*m = brew_molecule_p();
85 r = m->extent().y;
86 delete m;
87 } else
88 r = output->extent().y;
89 return r;
92 Interval
93 Score_elem::height() const
95 Interval r=do_height();
97 if (!r.empty_b())
98 r+=offset_.y;
101 return r;
104 void
105 Score_elem::print()const
107 #ifndef NPRINT
108 mtor << name() << "{\n";
109 do_print();
110 if (output)
111 output->print();
113 mtor << "}\n";
114 #endif
119 Score_elem::Score_elem()
121 pstaff_l_=0;
122 offset_ = Offset(0,0);
123 output = 0;
124 status = ORPHAN;
128 Paper_def*
129 Score_elem::paper() const
131 assert(pstaff_l_);
132 return pstaff_l_->pscore_l_->paper_l_;
135 void
136 Score_elem::add_processing()
138 if (status >= VIRGIN)
139 return;
140 status = VIRGIN;
141 do_add_processing();
144 void
145 Score_elem::pre_processing()
147 if (status >= PRECALCED )
148 return;
149 assert(status != PRECALCING); // cyclic dependency
150 status = PRECALCING;
152 for (int i=0; i < dependancy_l_arr_.size(); i++)
153 if (dependancy_l_arr_[i])
154 dependancy_l_arr_[i]->pre_processing();
157 do_pre_processing();
158 status = PRECALCED;
160 void
161 Score_elem::post_processing()
163 if (status >= POSTCALCED)
164 return;
165 assert(status != POSTCALCING);// cyclic dependency
166 status=POSTCALCING;
168 for (int i=0; i < dependancy_l_arr_.size(); i++)
169 if (dependancy_l_arr_[i])
170 dependancy_l_arr_[i]->post_processing();
171 do_post_processing();
172 status=POSTCALCED;
175 void
176 Score_elem::molecule_processing()
178 if (status >= OUTPUT)
179 return;
180 status = OUTPUT; // do it only once.
181 for (int i=0; i < dependancy_l_arr_.size(); i++)
182 if (dependancy_l_arr_[i])
183 dependancy_l_arr_[i]->molecule_processing();
185 output= brew_molecule_p();
188 void
189 Score_elem::do_post_processing()
193 void
194 Score_elem::do_pre_processing()
197 void
198 Score_elem::do_verticalcing()
202 void
203 Score_elem::do_add_processing()
207 void
208 Score_elem::substitute_dependency(Score_elem * old, Score_elem * newdep)
210 bool hebbes_b=false;
211 for (int i=0; i < dependancy_l_arr_.size(); i++) {
212 if (dependancy_l_arr_[i] == old){
213 dependancy_l_arr_[i] = newdep;
214 hebbes_b = true;
215 } else if (dependancy_l_arr_[i] == newdep) {
216 hebbes_b = true;
219 if (!hebbes_b)
220 dependancy_l_arr_.push(newdep);
223 void
224 Score_elem::add_dependency(Score_elem * p)
226 for (int i=0; i < dependancy_l_arr_.size(); i ++)
227 if (dependancy_l_arr_[i] == p)
228 return;
230 dependancy_l_arr_.push(p);
231 p->dependant_l_arr_.push(p);
233 IMPLEMENT_STATIC_NAME(Score_elem);
235 Molecule*
236 Score_elem::brew_molecule_p()const
238 Atom a(paper()->lookup_l()->fill(Box(Interval(0,0), Interval(0,0))));
239 return new Molecule (a);
241 Offset
242 Score_elem::offset() const
244 return offset_;