]> git.donarmstrong.com Git - lilypond.git/blob - pscore.cc
release: 0.0.5
[lilypond.git] / pscore.cc
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"
8
9 void
10 PScore::clean_cols()
11 {
12     for (PCursor<PCol *> c(cols); c.ok(); )
13         if (!c->used) {
14             c.del();
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 //    assert(!breakstat != 4 || c->breakable() );
31     if (breakstat == 0) {
32         typeset_item(i, c->prebreak, s);
33         return;
34     }
35
36     if (breakstat == 2) {
37         typeset_item(i, c->postbreak, s);
38         return;
39     }
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));
47         }
48     }
49     its.bottom().add(i);
50     s->add(i);
51     c->add(i);
52 }
53
54 void
55 PScore::add_line(svec<const PCol *> curline, svec<Real> config)
56 {    
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];
62     }
63 }
64
65 Idealspacing*
66 PScore::get_spacing(PCol*l, PCol*r)
67 {
68     assert(l!=r);
69     for (PCursor<Idealspacing*> ic (suz); ic.ok(); ic++) {
70         if (ic->left == l && ic->right == r){
71             return ic;
72         }
73     }
74     
75     Idealspacing*ip =new Idealspacing(l,r);
76     suz.bottom().add(ip);
77
78     return ip;
79 }
80
81 svec<const PCol *>
82 PScore::find_breaks() const
83 {
84     svec<const PCol *> retval;
85     for (PCursor<PCol *> c(cols); c.ok(); c++)
86         if (c->breakable())
87             retval.add(c);
88             
89     return retval;
90 }
91
92 void
93 PScore::add(PCol *p)
94 {
95     cols.bottom().add(p);
96 }
97
98 PScore::PScore()
99 {
100     linewidth = convert_dimen(15,"cm"); // default
101 }
102
103 void
104 PScore::output(Tex_stream &ts)
105 {
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";
113     }   
114 }
115
116 svec<Item*>
117 PScore::select_items(PStaff*ps , PCol*pc)
118 {
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);
124     }
125     return ret;
126 }
127
128 void
129 PScore::OK()const
130 {
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
137 }
138 void
139 PScore::print() const
140 {    
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();
146     
147     mtor << "\nideals: ";
148     for (PCursor<Idealspacing*> ic(suz); ic.ok(); ic++)
149         ic->print();
150     mtor << "}\n";
151 #endif 
152 }
153