]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-elem.cc
191f072de227b0bba4840f630ea9ed4fd4773e35
[lilypond.git] / lily / staff-elem.cc
1 /*
2   staff-elem.cc -- implement Staff_elem
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
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"
17
18 String
19 Staff_elem::TeXstring() const
20 {
21     Molecule m(*output);
22     m.translate(offset_);       // ugh?
23     return m.TeXstring();
24 }
25
26 Staff_elem::Staff_elem(Staff_elem const&s)
27       :dependancy_l_arr_(s.dependancy_l_arr_),
28         dependant_l_arr_(s.dependant_l_arr_)
29 {
30     status = s.status;
31     assert(!s.output);
32     output = 0;
33     pstaff_l_ = s.pstaff_l_;
34     offset_ = Offset(0,0);
35 }
36
37 /**
38   TODO:
39   If deleted, then remove dependant_l_arr_ depency!
40   */
41 Staff_elem::~Staff_elem()
42 {
43    delete output;
44 }
45
46 void
47 Staff_elem::translate(Offset O)
48 {
49     offset_ += O;
50 }
51
52 Interval
53 Staff_elem::do_width() const return r;
54 {
55     
56     if (!output){
57         Molecule*m = brew_molecule_p();
58         r = m->extent().x;
59         delete m;
60     } else
61         r = output->extent().x;
62 }
63 Interval
64 Staff_elem::width() const
65 {
66     Interval r=do_width();
67
68     if (!r.empty_b()) // float exception on DEC Alpha
69         r+=offset_.x;
70
71     return r;
72 }
73 Interval
74 Staff_elem::do_height() const return r
75 {
76     if (!output){
77         Molecule*m      = brew_molecule_p();
78         r = m->extent().y;
79         delete m;
80     } else
81         r = output->extent().y;
82 }
83
84 Interval
85 Staff_elem::height() const
86 {
87     Interval r=do_height();
88
89     if (!r.empty_b())
90         r+=offset_.y;
91
92   
93     return r;
94 }
95
96 void
97 Staff_elem::print()const
98 {
99 #ifndef NPRINT
100     mtor << name() << "{\n";
101     do_print();
102     if (output)
103         output->print();
104     
105     mtor <<  "}\n";
106 #endif
107 }
108
109
110
111 Staff_elem::Staff_elem()
112 {
113     pstaff_l_=0;
114     offset_ = Offset(0,0);
115     output = 0;
116     status = ORPHAN;
117 }
118
119
120 Paper_def*
121 Staff_elem::paper()  const
122 {
123     assert(pstaff_l_);
124     return pstaff_l_->pscore_l_->paper_l_;
125 }
126
127 void
128 Staff_elem::add_processing()
129 {
130     if (status >= VIRGIN)
131         return;
132     status = VIRGIN;
133     do_add_processing();
134 }
135
136 void
137 Staff_elem::pre_processing()
138 {
139     if (status >= PRECALCED )
140         return;
141     assert(status != PRECALCING); // cyclic dependency
142     status = PRECALCING;
143
144     for (int i=0; i < dependancy_l_arr_.size(); i++)
145         if (dependancy_l_arr_[i])
146             dependancy_l_arr_[i]->pre_processing();
147
148     
149     do_pre_processing();
150     status = PRECALCED;
151 }
152 void
153 Staff_elem::post_processing()
154 {
155     if (status >= POSTCALCED)
156         return;
157     assert(status != POSTCALCING);// cyclic dependency
158     status=POSTCALCING; 
159
160     for (int i=0; i < dependancy_l_arr_.size(); i++)
161         if (dependancy_l_arr_[i])
162             dependancy_l_arr_[i]->post_processing();
163     do_post_processing();
164     status=POSTCALCED;
165 }
166
167 void 
168 Staff_elem::molecule_processing()
169 {
170     if (status >= OUTPUT)
171         return;
172     status = OUTPUT;            // do it only once.
173     for (int i=0; i < dependancy_l_arr_.size(); i++)
174         if (dependancy_l_arr_[i])
175             dependancy_l_arr_[i]->molecule_processing();
176
177     output= brew_molecule_p();
178 }
179
180 void
181 Staff_elem::do_post_processing()
182 {
183 }
184
185 void
186 Staff_elem::do_pre_processing()
187 {
188 }
189
190 void
191 Staff_elem::do_add_processing()
192 {
193 }
194
195 void
196 Staff_elem::substitute_dependency(Staff_elem * old, Staff_elem * newdep)
197 {
198     bool hebbes_b=false;
199     for (int i=0; i < dependancy_l_arr_.size(); i++) {
200         if (dependancy_l_arr_[i] == old){
201             dependancy_l_arr_[i] = newdep;
202             hebbes_b = true;
203         } else if (dependancy_l_arr_[i] == newdep) {
204             hebbes_b = true;
205         }
206     }
207     if (!hebbes_b)
208         dependancy_l_arr_.push(newdep);
209 }
210
211 void
212 Staff_elem::add_dependency(Staff_elem * p)
213 {
214     for (int i=0; i < dependancy_l_arr_.size(); i ++)
215         if (dependancy_l_arr_[i] == p)
216             return;
217     
218     dependancy_l_arr_.push(p);
219     p->dependant_l_arr_.push(p);
220 }
221 IMPLEMENT_STATIC_NAME(Staff_elem);
222
223 Molecule*
224 Staff_elem::brew_molecule_p()const
225 {
226     Atom a(paper()->lookup_l()->fill(Box(Interval(0,0), Interval(0,0))));
227     return new Molecule (a);
228 }
229 Offset
230 Staff_elem::offset() const
231 {
232     return offset_; 
233 }