]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-elem.cc
release: 0.0.46.jcn1
[lilypond.git] / lily / staff-elem.cc
1 #include "p-score.hh"
2 #include "symbol.hh"
3 #include "p-staff.hh"
4 #include "molecule.hh"
5 #include "staff-elem.hh"
6 #include "debug.hh"
7
8 String
9 Staff_elem::TeXstring() const
10 {
11     Molecule m(*output);
12     m.translate(offset_);       // ugh?
13     return m.TeXstring();
14 }
15
16 Staff_elem::Staff_elem(Staff_elem const&s)
17       :dependancy_l_arr_(s.dependancy_l_arr_),
18         dependant_l_arr_(s.dependant_l_arr_)
19 {
20     status = s.status;
21     assert(!s.output);
22     output = 0;
23     pstaff_l_ = s.pstaff_l_;
24     offset_ = Offset(0,0);
25 }
26 /**
27   TODO:
28   If deleted, then remove dependant_l_arr_ depency!
29   */
30 Staff_elem::~Staff_elem()
31 {
32    delete output;
33 }
34
35 void
36 Staff_elem::translate(Offset O)
37 {
38     offset_ += O;
39 }
40 Interval
41 Staff_elem::width() const
42 {
43     Interval r;
44
45     if (!output){
46         Molecule*m      = brew_molecule_p();
47         r = m->extent().x;
48         delete m;
49     } else
50         r = output->extent().x;
51   
52     if (!r.empty_b()) // float exception on DEC Alpha
53         r+=offset_.x;
54
55     return r;
56 }
57 Interval
58 Staff_elem::height() const
59 {
60     Interval r;
61
62     if (!output){
63         Molecule*m      = brew_molecule_p();
64         r = m->extent().y;
65         delete m;
66     } else
67         r = output->extent().y;
68     
69     if (!r.empty_b())
70         r+=offset_.y;
71
72   
73     return r;
74 }
75
76 void
77 Staff_elem::print()const
78 {
79 #ifndef NPRINT
80     mtor << name() << "{\n";
81     do_print();
82     if (output)
83         output->print();
84     
85     mtor <<  "}\n";
86 #endif
87 }
88
89
90
91 Staff_elem::Staff_elem()
92 {
93     pstaff_l_=0;
94     offset_ = Offset(0,0);
95     output = 0;
96     status = ORPHAN;
97 }
98
99
100 Paper_def*
101 Staff_elem::paper()  const
102 {
103     assert(pstaff_l_);
104     return pstaff_l_->pscore_l_->paper_l_;
105 }
106
107 void
108 Staff_elem::add_processing()
109 {
110     if (status >= VIRGIN)
111         return;
112     status = VIRGIN;
113     do_add_processing();
114 }
115
116 void
117 Staff_elem::pre_processing()
118 {
119     if (status >= PRECALCED )
120         return;
121     assert(status != PRECALCING); // cyclic dependency
122     status = PRECALCING;
123
124     for (int i=0; i < dependancy_l_arr_.size(); i++)
125         if (dependancy_l_arr_[i])
126             dependancy_l_arr_[i]->pre_processing();
127
128     
129     do_pre_processing();
130     status = PRECALCED;
131 }
132 void
133 Staff_elem::post_processing()
134 {
135     if (status >= POSTCALCED)
136         return;
137     assert(status != POSTCALCING);// cyclic dependency
138     status=POSTCALCING; 
139
140     for (int i=0; i < dependancy_l_arr_.size(); i++)
141         if (dependancy_l_arr_[i])
142             dependancy_l_arr_[i]->post_processing();
143     do_post_processing();
144     status=POSTCALCED;
145 }
146
147 void 
148 Staff_elem::molecule_processing()
149 {
150     if (status >= OUTPUT)
151         return;
152     status = OUTPUT;            // do it only once.
153     for (int i=0; i < dependancy_l_arr_.size(); i++)
154         if (dependancy_l_arr_[i])
155             dependancy_l_arr_[i]->molecule_processing();
156
157     output= brew_molecule_p();
158 }
159
160 void
161 Staff_elem::do_post_processing()
162 {
163 }
164
165 void
166 Staff_elem::do_pre_processing()
167 {
168 }
169
170 void
171 Staff_elem::do_add_processing()
172 {
173 }
174
175 void
176 Staff_elem::substitute_dependency(Staff_elem * old, Staff_elem * newdep)
177 {
178     bool hebbes_b=false;
179     for (int i=0; i < dependancy_l_arr_.size(); i++) {
180         if (dependancy_l_arr_[i] == old){
181             dependancy_l_arr_[i] = newdep;
182             hebbes_b = true;
183         } else if (dependancy_l_arr_[i] == newdep) {
184             hebbes_b = true;
185         }
186     }
187     if (!hebbes_b)
188         dependancy_l_arr_.push(newdep);
189 }
190
191 void
192 Staff_elem::add_dependency(Staff_elem * p)
193 {
194     for (int i=0; i < dependancy_l_arr_.size(); i ++)
195         if (dependancy_l_arr_[i] == p)
196             return;
197     
198     dependancy_l_arr_.push(p);
199     p->dependant_l_arr_.push(p);
200 }
201 IMPLEMENT_STATIC_NAME(Staff_elem);