]> git.donarmstrong.com Git - lilypond.git/blob - pscore.cc
release: 0.0.6
[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 }
54
55 void
56 PScore::add_line(svec<const PCol *> curline, svec<Real> config)
57 {    
58     Line_of_score *p = new Line_of_score(curline,this);
59     lines.bottom().add(p);      
60     for (int i=0; i < curline.sz(); i++){
61         PCol *c=(PCol *)curline[i]; // so, this isn't really const.
62         c->hpos= config[i];
63     }
64 }
65
66 Idealspacing*
67 PScore::get_spacing(PCol*l, PCol*r)
68 {
69     assert(l!=r);
70     for (PCursor<Idealspacing*> ic (suz); ic.ok(); ic++) {
71         if (ic->left == l && ic->right == r){
72             return ic;
73         }
74     }
75     
76     Idealspacing*ip =new Idealspacing(l,r);
77     suz.bottom().add(ip);
78
79     return ip;
80 }
81
82 svec<const PCol *>
83 PScore::find_breaks() const
84 {
85     svec<const PCol *> retval;
86     for (PCursor<PCol *> c(cols); c.ok(); c++)
87         if (c->breakable())
88             retval.add(c);
89             
90     return retval;
91 }
92
93 void
94 PScore::add(PCol *p)
95 {
96     cols.bottom().add(p);
97 }
98
99 PScore::PScore( Paperdef*p)
100 {
101     paper_ = p;
102 }
103
104 void
105 PScore::output(Tex_stream &ts)
106 {
107     int l=1;
108
109     for (PCursor<Line_of_score*> lic(lines); lic.ok(); lic++) {
110         ts << "% line of score no. " << l++ <<"\n";
111         ts << lic->TeXstring();
112         if ((lic+1).ok())
113             ts << "\\interscoreline\n";
114     }   
115 }
116
117 svec<Item*>
118 PScore::select_items(PStaff*ps , PCol*pc)
119 {
120     svec<Item*> ret;
121     assert(ps && pc);
122     for (PCursor<const Item*> ic(pc->its); ic.ok(); ic++){
123         if (ic->pstaff_ == ps)
124             ret.add((Item*)(const Item*)ic);
125     }
126     return ret;
127 }
128
129 void
130 PScore::OK()const
131 {
132 #ifdef NDEBUG
133     for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
134         cc->OK();
135     for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
136         ic->OK();
137 #endif
138 }
139
140 void
141 PScore::print() const
142 {    
143 #ifndef NPRINT
144     mtor << "PScore { paper ";
145     paper_->print();
146     mtor << "\ncolumns: ";
147     for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
148         cc->print();
149     
150     mtor << "\nideals: ";
151     for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
152         ic->print();
153     mtor << "}\n";
154 #endif 
155 }
156