]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-elem.cc
release: 0.0.63
[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     assert(status < DELETED);
44     delete output;
45     status = DELETED;
46     output = 0;
47 }
48
49 void
50 Staff_elem::translate(Offset O)
51 {
52     offset_ += O;
53 }
54
55 Interval
56 Staff_elem::do_width() const 
57 {
58     Interval r;
59     
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;
67 }
68
69 Interval
70 Staff_elem::width() const
71 {
72     Interval r=do_width();
73
74     if (!r.empty_b()) // float exception on DEC Alpha
75         r+=offset_.x;
76
77     return r;
78 }
79 Interval
80 Staff_elem::do_height() const 
81 {
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;
90 }
91
92 Interval
93 Staff_elem::height() const
94 {
95     Interval r=do_height();
96
97     if (!r.empty_b())
98         r+=offset_.y;
99
100   
101     return r;
102 }
103
104 void
105 Staff_elem::print()const
106 {
107 #ifndef NPRINT
108     mtor << name() << "{\n";
109     do_print();
110     if (output)
111         output->print();
112     
113     mtor <<  "}\n";
114 #endif
115 }
116
117
118
119 Staff_elem::Staff_elem()
120 {
121     pstaff_l_=0;
122     offset_ = Offset(0,0);
123     output = 0;
124     status = ORPHAN;
125 }
126
127
128 Paper_def*
129 Staff_elem::paper()  const
130 {
131     assert(pstaff_l_);
132     return pstaff_l_->pscore_l_->paper_l_;
133 }
134
135 void
136 Staff_elem::add_processing()
137 {
138     if (status >= VIRGIN)
139         return;
140     status = VIRGIN;
141     do_add_processing();
142 }
143
144 void
145 Staff_elem::pre_processing()
146 {
147     if (status >= PRECALCED )
148         return;
149     assert(status != PRECALCING); // cyclic dependency
150     status = PRECALCING;
151
152     for (int i=0; i < dependancy_l_arr_.size(); i++)
153         if (dependancy_l_arr_[i])
154             dependancy_l_arr_[i]->pre_processing();
155
156     
157     do_pre_processing();
158     status = PRECALCED;
159 }
160 void
161 Staff_elem::post_processing()
162 {
163     if (status >= POSTCALCED)
164         return;
165     assert(status != POSTCALCING);// cyclic dependency
166     status=POSTCALCING; 
167
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;
173 }
174
175 void 
176 Staff_elem::molecule_processing()
177 {
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();
184
185     output= brew_molecule_p();
186 }
187
188 void
189 Staff_elem::do_post_processing()
190 {
191 }
192
193 void
194 Staff_elem::do_pre_processing()
195 {
196 }
197
198 void
199 Staff_elem::do_add_processing()
200 {
201 }
202
203 void
204 Staff_elem::substitute_dependency(Staff_elem * old, Staff_elem * newdep)
205 {
206     bool hebbes_b=false;
207     for (int i=0; i < dependancy_l_arr_.size(); i++) {
208         if (dependancy_l_arr_[i] == old){
209             dependancy_l_arr_[i] = newdep;
210             hebbes_b = true;
211         } else if (dependancy_l_arr_[i] == newdep) {
212             hebbes_b = true;
213         }
214     }
215     if (!hebbes_b)
216         dependancy_l_arr_.push(newdep);
217 }
218
219 void
220 Staff_elem::add_dependency(Staff_elem * p)
221 {
222     for (int i=0; i < dependancy_l_arr_.size(); i ++)
223         if (dependancy_l_arr_[i] == p)
224             return;
225     
226     dependancy_l_arr_.push(p);
227     p->dependant_l_arr_.push(p);
228 }
229 IMPLEMENT_STATIC_NAME(Staff_elem);
230
231 Molecule*
232 Staff_elem::brew_molecule_p()const
233 {
234     Atom a(paper()->lookup_l()->fill(Box(Interval(0,0), Interval(0,0))));
235     return new Molecule (a);
236 }
237 Offset
238 Staff_elem::offset() const
239 {
240     return offset_; 
241 }