lilypond-0.0.4
[lilypond.git] / pscore.cc
blob44a87c0dd4d4416ca4912e06f6283b00a2093f16
1 // utility functions for PScore
2 #include "debug.hh"
3 #include "dimen.hh"
4 #include "line.hh"
5 #include "pscore.hh"
6 #include "tstream.hh"
8 void
9 PScore::clean_cols()
11 for (PCursor<PCol *> c(cols); c.ok(); )
12 if (!c->used) {
13 c.del();
14 mtor << "removing pcol\n";
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 if (breakstat == 1 ) {
31 typeset_item(i, c->prebreak, s, 0);
32 } if (breakstat == 3)
33 typeset_item(i, c->prebreak, s, 0 );
34 else{
35 its.bottom().add(i);
36 s->add(i);
37 c->add(i);
41 void
42 PScore::add_line(svec<const PCol *> curline, svec<Real> config)
44 Line_of_score *p = new Line_of_score(curline,this);
45 lines.bottom().add(p);
46 for (int i=0; i < curline.sz(); i++){
47 PCol *c=(PCol *)curline[i]; // so, this isn't really const.
48 c->hpos= config[i];
52 Idealspacing*
53 PScore::get_spacing(PCol*l, PCol*r)
55 assert(l!=r);
56 for (PCursor<Idealspacing*> ic (suz); ic.ok(); ic++) {
57 if (ic->left == l && ic->right == r){
58 return ic;
62 Idealspacing*ip =new Idealspacing(l,r);
63 suz.bottom().add(ip);
65 return ip;
68 svec<const PCol *>
69 PScore::find_breaks() const
71 svec<const PCol *> retval;
72 for (PCursor<PCol *> c(cols); c.ok(); c++)
73 if (c->breakable)
74 retval.add(c);
76 return retval;
79 void
80 PScore::add(PCol *p)
82 cols.bottom().add(p);
85 PScore::PScore()
87 linewidth = convert_dimen(15,"cm");
90 void
91 PScore::output(Tex_stream &ts)
93 int l=1;
94 ts << "% linewidth " << print_dimen(linewidth )+"\n";
95 for (PCursor<Line_of_score*> lic(lines); lic.ok(); lic++) {
96 ts << "% line of score no. " << l++ <<"\n";
97 ts << lic->TeXstring();
98 if ((lic+1).ok())
99 ts << "\\interscoreline\n";
103 svec<Item*>
104 PScore::select_items(PStaff*ps , PCol*pc)
106 svec<Item*> ret;
107 assert(ps && pc);
108 for (PCursor<const Item*> ic(pc->its); ic.ok(); ic++){
109 if (ic->pstaff_ == ps)
110 ret.add((Item*)(const Item*)ic);
112 return ret;
115 void
116 PScore::OK()const
118 for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
119 cc->OK();
120 for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
121 ic->OK();
124 void
125 PScore::print() const
128 #ifndef NPRINT
129 mtor << "PScore { width "<<print_dimen(linewidth);
130 mtor << "\ncolumns: ";
131 for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
132 cc->print();
134 mtor << "\nideals: ";
135 for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
136 ic->print();
137 mtor << "}\n";
138 #endif