lilypond-0.0.5
[lilypond.git] / pscore.cc
blob773554375c8e2d280f1337c07575352531a58d68
1 // utility functions for PScore
2 #include "debug.hh"
3 #include "molecule.hh"
4 #include "dimen.hh"
5 #include "line.hh"
6 #include "pscore.hh"
7 #include "tstream.hh"
9 void
10 PScore::clean_cols()
12 for (PCursor<PCol *> c(cols); c.ok(); )
13 if (!c->used) {
14 c.del();
15 } else
16 c++;
20 void
21 PScore::add(PStaff *s)
23 staffs.bottom().add(s);
26 void
27 PScore::typeset_item(Item *i, PCol *c, PStaff *s, int breakstat)
29 assert(c && i && s);
30 // assert(!breakstat != 4 || c->breakable() );
31 if (breakstat == 0) {
32 typeset_item(i, c->prebreak, s);
33 return;
36 if (breakstat == 2) {
37 typeset_item(i, c->postbreak, s);
38 return;
40 if (c->daddy && c == c->daddy->prebreak) { // makeshift.
41 Interval iv (i->width());
42 if (!iv.empty()) {
43 svec<Item*> col_its (select_items(s, c));
44 for (int j =0; j < col_its.sz(); j++)
45 col_its[j]->output->translate(Offset(-iv.length(),0));
46 i->output->translate (Offset(-iv.max, 0));
49 its.bottom().add(i);
50 s->add(i);
51 c->add(i);
54 void
55 PScore::add_line(svec<const PCol *> curline, svec<Real> config)
57 Line_of_score *p = new Line_of_score(curline,this);
58 lines.bottom().add(p);
59 for (int i=0; i < curline.sz(); i++){
60 PCol *c=(PCol *)curline[i]; // so, this isn't really const.
61 c->hpos= config[i];
65 Idealspacing*
66 PScore::get_spacing(PCol*l, PCol*r)
68 assert(l!=r);
69 for (PCursor<Idealspacing*> ic (suz); ic.ok(); ic++) {
70 if (ic->left == l && ic->right == r){
71 return ic;
75 Idealspacing*ip =new Idealspacing(l,r);
76 suz.bottom().add(ip);
78 return ip;
81 svec<const PCol *>
82 PScore::find_breaks() const
84 svec<const PCol *> retval;
85 for (PCursor<PCol *> c(cols); c.ok(); c++)
86 if (c->breakable())
87 retval.add(c);
89 return retval;
92 void
93 PScore::add(PCol *p)
95 cols.bottom().add(p);
98 PScore::PScore()
100 linewidth = convert_dimen(15,"cm"); // default
103 void
104 PScore::output(Tex_stream &ts)
106 int l=1;
107 ts << "% linewidth " << print_dimen(linewidth )+"\n";
108 for (PCursor<Line_of_score*> lic(lines); lic.ok(); lic++) {
109 ts << "% line of score no. " << l++ <<"\n";
110 ts << lic->TeXstring();
111 if ((lic+1).ok())
112 ts << "\\interscoreline\n";
116 svec<Item*>
117 PScore::select_items(PStaff*ps , PCol*pc)
119 svec<Item*> ret;
120 assert(ps && pc);
121 for (PCursor<const Item*> ic(pc->its); ic.ok(); ic++){
122 if (ic->pstaff_ == ps)
123 ret.add((Item*)(const Item*)ic);
125 return ret;
128 void
129 PScore::OK()const
131 #ifdef NDEBUG
132 for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
133 cc->OK();
134 for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
135 ic->OK();
136 #endif
138 void
139 PScore::print() const
141 #ifndef NPRINT
142 mtor << "PScore { width "<<print_dimen(linewidth);
143 mtor << "\ncolumns: ";
144 for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
145 cc->print();
147 mtor << "\nideals: ";
148 for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
149 ic->print();
150 mtor << "}\n";
151 #endif