lilypond-0.0.50
[lilypond.git] / lily / p-col.cc
blobc47a4b2d275d446374b28e4883a28aeef3295594
1 /*
2 p-col.cc -- implement PCol
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "p-col.hh"
10 #include "p-score.hh"
11 #include "p-staff.hh"
12 #include "debug.hh"
14 Interval
15 PCol::width() const
17 Interval w;
19 for (iter_top(its,i); i.ok(); i++)
20 w.unite(i->width());
21 if (w.empty_b())
22 w.unite(Interval(0,0));
23 return w;
26 int
27 PCol::rank() const
29 assert(rank_i_ != -1);
30 return rank_i_;
33 void
34 PCol::set_rank(int i)
36 rank_i_ = i;
37 if (prebreak_p_)
38 prebreak_p_->rank_i_ = i;
39 if (postbreak_p_)
40 postbreak_p_->rank_i_ = i;
43 void
44 PCol::print() const
46 #ifndef NPRINT
47 mtor << "PCol {";
49 mtor << "rank: " << rank_i_ << '\n';
51 mtor << "# symbols: " << its.size() ;
52 if (breakable_b()){
53 mtor << "\npre,post: ";
54 prebreak_p_->print();
55 postbreak_p_->print();
56 } else if (daddy_l_) {
57 mtor<<'\n' << ((this == daddy_l_->prebreak_p_) ?
58 "prebreak" : "postbreak");
59 mtor << '\n';
61 mtor << "extent: " << width().str() << "\n";
62 mtor << "}\n";
63 #endif
66 int
67 PCol::compare(PCol const &c1, PCol const &c2)
69 return c1.rank() - c2.rank();
72 void
73 PCol::OK() const
75 #ifndef NDEBUG
76 if (prebreak_p_ || postbreak_p_ ) {
77 assert(prebreak_p_&&postbreak_p_);
78 assert(prebreak_p_->daddy_l_ == this);
79 assert(postbreak_p_->daddy_l_ == this);
81 #endif
84 void
85 PCol::set_breakable()
87 if (breakable_b())
88 return;
90 prebreak_p_ = new PCol(this);
91 postbreak_p_ = new PCol(this);
92 prebreak_p_->pscore_l_ = pscore_l_;
93 postbreak_p_->pscore_l_ = pscore_l_;
96 bool
97 PCol::breakable_b() const
99 return prebreak_p_||postbreak_p_;
102 PCol::PCol(PCol *parent)
104 daddy_l_ = parent;
105 prebreak_p_=0;
106 postbreak_p_=0;
107 line_l_=0;
108 hpos = -1.0;
109 pscore_l_ = 0;
112 PCol::~PCol()
114 delete prebreak_p_;
115 delete postbreak_p_;
118 void
119 PCol::add( Item *i)
121 its.bottom().add(i);
122 i->pcol_l_ = this;
125 bool
126 PCol::used_b()const
128 return breakable_b() || its.size();