]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-elem.cc
release: 0.0.64
[lilypond.git] / lily / staff-elem.cc
1 /*
2   staff-elem.cc -- implement Score_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 Score_elem::TeXstring() const
20 {
21     Molecule m(*output);
22     m.translate(offset_);       // ugh?
23     return m.TeXstring();
24 }
25
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_)
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 Score_elem::~Score_elem()
42 {
43     assert(status < DELETED);
44     delete output;
45     status = DELETED;
46     output = 0;
47 }
48
49 void
50 Score_elem::translate(Offset O)
51 {
52     offset_ += O;
53 }
54
55 Interval
56 Score_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 Score_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 Score_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 Score_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 Score_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 Score_elem::Score_elem()
120 {
121     pstaff_l_=0;
122     offset_ = Offset(0,0);
123     output = 0;
124     status = ORPHAN;
125 }
126
127
128 Paper_def*
129 Score_elem::paper()  const
130 {
131     assert(pstaff_l_);
132     return pstaff_l_->pscore_l_->paper_l_;
133 }
134
135 void
136 Score_elem::add_processing()
137 {
138     if (status >= VIRGIN)
139         return;
140     status = VIRGIN;
141     do_add_processing();
142 }
143
144 void
145 Score_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 Score_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 Score_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 Score_elem::do_post_processing()
190 {
191 }
192
193 void
194 Score_elem::do_pre_processing()
195 {
196 }
197 void
198 Score_elem::do_verticalcing()
199 {
200 }
201
202 void
203 Score_elem::do_add_processing()
204 {
205 }
206
207 void
208 Score_elem::substitute_dependency(Score_elem * old, Score_elem * newdep)
209 {
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;
217         }
218     }
219     if (!hebbes_b)
220         dependancy_l_arr_.push(newdep);
221 }
222
223 void
224 Score_elem::add_dependency(Score_elem * p)
225 {
226     for (int i=0; i < dependancy_l_arr_.size(); i ++)
227         if (dependancy_l_arr_[i] == p)
228             return;
229     
230     dependancy_l_arr_.push(p);
231     p->dependant_l_arr_.push(p);
232 }
233 IMPLEMENT_STATIC_NAME(Score_elem);
234
235 Molecule*
236 Score_elem::brew_molecule_p()const
237 {
238     Atom a(paper()->lookup_l()->fill(Box(Interval(0,0), Interval(0,0))));
239     return new Molecule (a);
240 }
241 Offset
242 Score_elem::offset() const
243 {
244     return offset_; 
245 }