]> git.donarmstrong.com Git - lilypond.git/blob - src/pscore.cc
release: 0.0.9
[lilypond.git] / src / pscore.cc
1 // utility functions for PScore
2 #include "debug.hh"
3 #include "spanner.hh"
4 #include "paper.hh"
5 #include "molecule.hh"
6 #include "dimen.hh"
7 #include "scoreline.hh"
8 #include "pscore.hh"
9 #include "tstream.hh"
10
11
12 void
13 PScore::clean_cols()
14 {
15     for (PCursor<PCol *> c(cols); c.ok(); )
16         if (!c->used) {
17             c.del();
18         } else
19             c++;
20 }
21
22
23 void
24 PScore::add(PStaff *s)
25 {
26     assert(s->pscore_ == this);
27     staffs.bottom().add(s);
28 }
29
30 void
31 PScore::typeset_item(Item *i, PCol *c, PStaff *s, int breakstat)
32 {
33     assert(c && i && s);
34 //    assert(!breakstat != 4 || c->breakable() );
35     if (breakstat == 0) {
36         typeset_item(i, c->prebreak, s);
37         return;
38     }
39
40     if (breakstat == 2) {
41         typeset_item(i, c->postbreak, s);
42         return;
43     }
44
45
46     its.bottom().add(i);
47     s->add(i);
48     c->add(i);
49
50     /* first do this, because i->width() may follow the 0-pointer */
51     i->preprocess();
52
53
54     if (c->daddy && c == c->daddy->prebreak) { // makeshift.
55         
56         Interval iv (i->width());
57         if (!iv.empty()) {
58             svec<Item*> col_its (select_items(s, c));
59             for (int j =0; j < col_its.sz(); j++)
60                 col_its[j]->translate(Offset(-iv.length(),0));
61             i->translate (Offset(-iv.max, 0));
62         }
63     }
64     
65 }
66
67 void
68 PScore::typeset_spanner(Spanner*sp, PStaff*ps)
69 {
70     sp->preprocess();
71     sp->pstaff_ = ps;
72     spanners.bottom().add(sp);
73     ps->spans.bottom().add(sp);
74     sp->left->starters.bottom().add(sp);
75     sp->right->stoppers.bottom().add(sp);
76 }
77
78
79 void
80 PScore::add_line(svec<const PCol *> curline, svec<Real> config)
81 {    
82     Line_of_score *p = new Line_of_score(curline,this);
83     lines.bottom().add(p);      
84     for (int i=0; i < curline.sz(); i++){
85         PCol *c=(PCol *)curline[i]; // so, this isn't really const.
86         c->hpos= config[i];
87     }
88 }
89
90 Idealspacing*
91 PScore::get_spacing(PCol*l, PCol*r)
92 {
93     assert(l!=r);
94     for (PCursor<Idealspacing*> ic (suz); ic.ok(); ic++) {
95         if (ic->left == l && ic->right == r){
96             return ic;
97         }
98     }
99     
100     Idealspacing*ip =new Idealspacing(l,r);
101     suz.bottom().add(ip);
102
103     return ip;
104 }
105
106
107 /*
108   return all breakable columns
109  */
110 svec<const PCol *>
111 PScore::find_breaks() const
112 {
113     svec<const PCol *> retval;
114     for (PCursor<PCol *> c(cols); c.ok(); c++)
115         if (c->breakable())
116             retval.add(c);
117
118     return retval;
119 }
120
121 void
122 PScore::add(PCol *p)
123 {
124     cols.bottom().add(p);
125 }
126
127 PScore::PScore( Paperdef*p)
128 {
129     paper_ = p;
130 }
131
132 void
133 PScore::output(Tex_stream &ts)
134 {
135     int l=1;
136
137     for (PCursor<Line_of_score*> lic(lines); lic.ok(); lic++) {
138         ts << "% line of score no. " << l++ <<"\n";
139         ts << lic->TeXstring();
140         if ((lic+1).ok())
141             ts << "\\interscoreline\n";
142     }   
143 }
144
145
146 svec<Item*>
147 PScore::select_items(PStaff*ps , PCol*pc)
148 {
149     svec<Item*> ret;
150     assert(ps && pc);
151     for (PCursor<const Item*> ic(pc->its); ic.ok(); ic++){
152         if (ic->pstaff_ == ps)
153             ret.add((Item*)(const Item*)ic);
154     }
155     return ret;
156 }
157
158 void
159 PScore::OK()const
160 {
161 #ifdef NDEBUG
162     for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
163         cc->OK();
164     for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
165         ic->OK();
166 #endif
167 }
168
169 void
170 PScore::print() const
171 {    
172 #ifndef NPRINT
173     mtor << "PScore { ";
174     paper_->print();
175     mtor << "\ncolumns: ";
176     for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
177         cc->print();
178     
179     mtor << "\nideals: ";
180     for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
181         ic->print();
182     mtor << "}\n";
183 #endif 
184 }
185
186 void
187 PScore::preprocess()
188 {
189 #if 0
190     for (PCursor<Item*> ic(its); ic.ok(); ic++){
191         ic->preprocess();
192     }
193 #endif 
194 }
195
196 void
197 PScore::postprocess()
198 {
199     for (PCursor<Spanner*> ic(spanners); ic.ok(); ic++) {
200         ic->process();
201     }
202     for (PCursor<Item*> ic(its); ic.ok(); ic++){
203         ic->postprocess();
204     }
205 }