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