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