]> git.donarmstrong.com Git - lilypond.git/blob - src/pcol.cc
release: 0.0.18
[lilypond.git] / src / pcol.cc
1 #include "pcol.hh"
2 #include "pscore.hh"
3 #include "pstaff.hh"
4 #include "debug.hh"
5
6 Interval
7 PCol::width() const
8 {
9     Interval w;
10
11     for (PCursor<const Item *> ic(its); ic.ok(); ic++)
12         w.unite(ic->width());
13     if (w.empty())
14         w.unite(Interval(0,0));
15     return w;
16 }
17 int
18 PCol::rank() const
19 {
20     if(!pscore_)
21         return -1;
22     PCursor<PCol*> me=pscore_->find_col( (PCol*)this);
23     if (!me.ok())
24         return -1;
25     PCursor<PCol*> bot(pscore_->cols.top());
26     return me - bot;
27 }
28
29 void
30 PCol::print() const
31 {
32 #ifndef NPRINT
33     mtor << "PCol {";
34
35     if (rank() >= 0)
36         mtor << "rank: " << rank() << '\n';
37
38     mtor << "# symbols: " << its.size() ;
39     if (breakable()){
40         mtor << "\npre,post: ";
41         prebreak->print();
42         postbreak->print();
43     } else if (daddy) {
44         mtor<<'\n' << ((this == daddy->prebreak) ? "prebreak" : "postbreak");
45     }
46     mtor << "extent: " << width().min << ", " << width().max << "\n";
47     mtor << "}\n";
48 #endif 
49 }
50
51 int
52 PCol::compare(const PCol &c1, const PCol &c2)
53 {
54     return c1.pscore_->compare_pcols((PCol*)&c1,(PCol*)&c2);
55 }
56
57 void
58 PCol::OK () const
59 {
60     if (prebreak || postbreak ) {
61         assert(prebreak&&postbreak);
62         assert(prebreak->daddy == this);
63         assert(postbreak->daddy == this);
64     }    
65 }
66
67 void
68 PCol::set_breakable()
69 {
70     if (breakable())
71         return;
72
73     prebreak = new PCol(this);
74     postbreak = new PCol(this);
75     prebreak->pscore_ = pscore_;
76     postbreak->pscore_ = pscore_;
77     
78  
79 }
80
81 bool
82 PCol::breakable() const
83 {
84     return prebreak||postbreak;
85 }
86
87 PCol::PCol(PCol *parent)
88 {
89     daddy = parent;
90     prebreak=0;
91     postbreak=0;
92     line=0;
93  
94     pscore_ = 0;
95 }
96
97 PCol::~PCol()
98 {
99     delete prebreak;
100     delete postbreak;   
101 }
102
103 void
104 PCol::add( Item *i)
105 {
106     its.bottom().add(i);
107     i->pcol_ = this;
108  
109 }
110
111 bool
112 PCol::used()const
113 {
114     return breakable() || its.size();
115 }