]> git.donarmstrong.com Git - lilypond.git/blob - pscore.cc
44a87c0dd4d4416ca4912e06f6283b00a2093f16
[lilypond.git] / pscore.cc
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"
7
8 void
9 PScore::clean_cols()
10 {
11     for (PCursor<PCol *> c(cols); c.ok(); )
12         if (!c->used) {
13             c.del();
14             mtor << "removing pcol\n";
15         } else
16             c++;
17 }
18
19
20 void
21 PScore::add(PStaff *s)
22 {
23     staffs.bottom().add(s);    
24 }
25
26 void
27 PScore::typeset_item(Item *i, PCol *c, PStaff *s, int breakstat)
28 {
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);
38     }
39 }
40
41 void
42 PScore::add_line(svec<const PCol *> curline, svec<Real> config)
43 {    
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];
49     }
50 }
51
52 Idealspacing*
53 PScore::get_spacing(PCol*l, PCol*r)
54 {
55     assert(l!=r);
56     for (PCursor<Idealspacing*> ic (suz); ic.ok(); ic++) {
57         if (ic->left == l && ic->right == r){
58             return ic;
59         }
60     }
61     
62     Idealspacing*ip =new Idealspacing(l,r);
63     suz.bottom().add(ip);
64
65     return ip;
66 }
67
68 svec<const PCol *>
69 PScore::find_breaks() const
70 {
71     svec<const PCol *> retval;
72     for (PCursor<PCol *> c(cols); c.ok(); c++)
73         if (c->breakable)
74             retval.add(c);
75             
76     return retval;
77 }
78
79 void
80 PScore::add(PCol *p)
81 {
82     cols.bottom().add(p);
83 }
84
85 PScore::PScore()
86 {
87     linewidth = convert_dimen(15,"cm");
88 }
89
90 void
91 PScore::output(Tex_stream &ts)
92 {
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";
100     }   
101 }
102
103 svec<Item*>
104 PScore::select_items(PStaff*ps , PCol*pc)
105 {
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);
111     }
112     return ret;
113 }
114
115 void
116 PScore::OK()const
117 {
118     for (PCursor<PCol*> cc(cols); cc.ok(); cc++)
119         cc->OK();
120     for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
121         ic->OK();
122     
123 }
124 void
125 PScore::print() const
126 {
127     
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();
133     
134     mtor << "\nideals: ";
135     for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
136         ic->print();
137     mtor << "}\n";
138    #endif 
139 }
140