]> git.donarmstrong.com Git - lilypond.git/blob - lily/p-col.cc
release: 0.0.54
[lilypond.git] / lily / p-col.cc
1 /*
2   p-col.cc -- implement PCol
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "p-col.hh"
10 #include "p-score.hh"
11 #include "p-staff.hh"
12 #include "debug.hh"
13
14 Interval
15 PCol::width() const
16 {
17     Interval w;
18
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;
24 }
25
26 int
27 PCol::rank() const
28 {
29     assert(rank_i_ != -1);
30     return rank_i_;
31 }
32
33 void
34 PCol::set_rank(int i)
35 {
36     rank_i_ = i;
37     if (prebreak_p_)
38         prebreak_p_->rank_i_ = i;
39     if (postbreak_p_)
40         postbreak_p_->rank_i_ = i;
41 }
42
43 void
44 PCol::print() const
45 {
46 #ifndef NPRINT
47     mtor << "PCol {";
48
49     mtor << "rank: " << rank_i_ << '\n';
50
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';
60     }
61     mtor << "extent: " << width().str() << "\n";
62     mtor << "}\n";
63 #endif 
64 }
65
66 int
67 PCol::compare(PCol const &c1, PCol const &c2)
68 {
69     return c1.rank() - c2.rank();
70 }
71
72 void
73 PCol::OK() const
74 {
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);
80     }
81 #endif
82 }
83
84 void
85 PCol::set_breakable()
86 {
87     if (breakable_b())
88         return;
89
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_;
94 }
95
96 bool
97 PCol::breakable_b() const
98 {
99     return prebreak_p_||postbreak_p_;
100 }
101
102 PCol::PCol(PCol *parent)
103 {
104     daddy_l_ = parent;
105     prebreak_p_=0;
106     postbreak_p_=0;
107     line_l_=0;
108     hpos = -1.0;
109     pscore_l_ = 0;
110     rank_i_ = -1;
111 }
112
113 PCol::~PCol()
114 {
115     delete prebreak_p_;
116     delete postbreak_p_;        
117 }
118
119 void
120 PCol::add( Item *i)
121 {
122     its.bottom().add(i);
123     i->pcol_l_ = this; 
124 }
125
126 bool
127 PCol::used_b()const
128 {
129     return breakable_b() || its.size();
130 }