lilypond-1.3.145
[lilypond.git] / src / staffelem.cc
blob1b5e592762cc6099a89cd2e50d88b8f231823aab
1 #include "pscore.hh"
2 #include "symbol.hh"
3 #include "pstaff.hh"
4 #include "molecule.hh"
5 #include "staffelem.hh"
6 #include "debug.hh"
8 String
9 Staff_elem::TeXstring() const
11 Molecule m(*output);
12 m.translate(offset_); // ugh?
13 return m.TeXstring();
16 Staff_elem::Staff_elem(Staff_elem const&s)
17 : dependants(s.dependants),
18 dependencies(s.dependencies)
20 status = s.status;
21 assert(!s.output);
22 output = 0;
23 pstaff_l_ = s.pstaff_l_;
24 offset_ = Offset(0,0);
26 /**
27 TODO:
28 If deleted, then remove dependants depency!
30 Staff_elem::~Staff_elem()
32 delete output;
35 void
36 Staff_elem::translate(Offset O)
38 offset_ += O;
40 Interval
41 Staff_elem::width() const
43 Interval r;
45 if (!output){
46 Molecule*m = brew_molecule_p();
47 r = m->extent().x;
48 delete m;
49 } else
50 r = output->extent().x;
52 if (!r.empty()) // float exception on DEC Alpha
53 r+=offset_.x;
55 return r;
57 Interval
58 Staff_elem::height() const
60 Interval r;
62 if (!output){
63 Molecule*m = brew_molecule_p();
64 r = m->extent().y;
65 delete m;
66 } else
67 r = output->extent().y;
69 if (!r.empty())
70 r+=offset_.y;
73 return r;
76 void
77 Staff_elem::print()const
79 #ifndef NPRINT
80 mtor << name() << "{\n";
81 do_print();
82 if (output)
83 output->print();
85 mtor << "}\n";
86 #endif
89 NAME_METHOD(Staff_elem);
91 Staff_elem::Staff_elem()
93 pstaff_l_=0;
94 offset_ = Offset(0,0);
95 output = 0;
96 status = ORPHAN;
100 Paperdef*
101 Staff_elem::paper() const
103 assert(pstaff_l_);
104 return pstaff_l_->pscore_l_->paper_l_;
107 void
108 Staff_elem::add_processing()
110 if (status >= VIRGIN)
111 return;
112 status = VIRGIN;
113 do_add_processing();
116 void
117 Staff_elem::pre_processing()
119 if (status >= PRECALCED )
120 return;
121 assert(status != PRECALCING); // cyclic dependency
122 status = PRECALCING;
124 for (int i=0; i < dependencies.size(); i++)
125 if (dependencies[i])
126 dependencies[i]->pre_processing();
129 do_pre_processing();
130 status = PRECALCED;
132 void
133 Staff_elem::post_processing()
135 if (status >= POSTCALCED)
136 return;
137 assert(status != POSTCALCING);// cyclic dependency
138 status=POSTCALCING;
140 for (int i=0; i < dependencies.size(); i++)
141 if (dependencies[i])
142 dependencies[i]->post_processing();
143 do_post_processing();
144 status=POSTCALCED;
147 void
148 Staff_elem::molecule_processing()
150 if (status >= OUTPUT)
151 return;
152 status = OUTPUT; // do it only once.
153 for (int i=0; i < dependencies.size(); i++)
154 if (dependencies[i])
155 dependencies[i]->molecule_processing();
157 output= brew_molecule_p();
160 void
161 Staff_elem::do_post_processing()
165 void
166 Staff_elem::do_pre_processing()
170 void
171 Staff_elem::do_add_processing()
175 void
176 Staff_elem::substitute_dependency(Staff_elem * old, Staff_elem * newdep)
178 bool hebbes_b=false;
179 for (int i=0; i < dependencies.size(); i++) {
180 if (dependencies[i] == old){
181 dependencies[i] = newdep;
182 hebbes_b = true;
183 } else if (dependencies[i] == newdep) {
184 hebbes_b = true;
187 if (!hebbes_b)
188 dependencies.push(newdep);
191 void
192 Staff_elem::add_depedency(Staff_elem * p)
194 for (int i=0; i < dependencies.size(); i ++)
195 if (dependencies[i] == p)
196 return;
198 dependencies.push(p);
199 p->dependants.push(p);