]> git.donarmstrong.com Git - lilypond.git/blob - lily/p-col.cc
release: 0.0.68pre
[lilypond.git] / lily / p-col.cc
1 /*
2   p-col.cc -- implement PCol
3
4   source file of the GNU 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
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 void
27 PCol::clean_breakable_items()
28 {
29     if (!line_l_) {
30         for(iter(its.top(), j); j.ok(); ) {
31             j->unlink();
32             j.del();
33         }
34     }
35     if (prebreak_p_) prebreak_p_->clean_breakable_items();
36     if (postbreak_p_) postbreak_p_->clean_breakable_items();
37 }
38
39 int
40 PCol::rank_i() const
41 {
42     assert(rank_i_ != -1);
43     return rank_i_;
44 }
45
46 void
47 PCol::set_rank(int i)
48 {
49     rank_i_ = i;
50     if (prebreak_p_)
51         prebreak_p_->rank_i_ = i;
52     if (postbreak_p_)
53         postbreak_p_->rank_i_ = i;
54 }
55
56 void
57 PCol::print() const
58 {
59 #ifndef NPRINT
60     mtor << "PCol {";
61
62     mtor << "rank: " << rank_i_ << '\n';
63
64     mtor << "# symbols: " << its.size() ;
65     if (breakable_b()){
66         mtor << "\npre,post: ";
67         prebreak_p_->print();
68         postbreak_p_->print();
69     } else if (daddy_l_) {
70         mtor<<'\n' << ((this == daddy_l_->prebreak_p_) ?
71                        "prebreak" : "postbreak");
72         mtor << '\n';
73     }
74     mtor << "extent: " << width().str() << "\n";
75     mtor << "}\n";
76 #endif 
77 }
78
79 int
80 PCol::compare(PCol const &c1, PCol const &c2)
81 {
82     return c1.rank_i() - c2.rank_i();
83 }
84
85 void
86 PCol::OK() const
87 {
88 #ifndef NDEBUG
89     if (prebreak_p_ || postbreak_p_ ) {
90         assert(prebreak_p_&&postbreak_p_);
91         assert(prebreak_p_->daddy_l_ == this);
92         assert(postbreak_p_->daddy_l_ == this);
93     }
94 #endif
95 }
96
97 void
98 PCol::set_breakable()
99 {
100     if (breakable_b())
101         return;
102
103     prebreak_p_ = new PCol(this);
104     postbreak_p_ = new PCol(this);
105     prebreak_p_->pscore_l_ = pscore_l_;
106     postbreak_p_->pscore_l_ = pscore_l_;
107 }
108
109 bool
110 PCol::breakpoint_b() const
111 {
112     return !line_l_;
113 }
114
115 bool
116 PCol::breakable_b() const
117 {
118     return prebreak_p_||postbreak_p_;
119 }
120
121 PCol::PCol(PCol *parent)
122 {
123     error_mark_b_ = false;
124     daddy_l_ = parent;
125     prebreak_p_=0;
126     postbreak_p_=0;
127     line_l_=0;
128     hpos = -1.0;
129     pscore_l_ = 0;
130     rank_i_ = -1;
131 }
132
133 PCol::~PCol()
134 {
135     delete prebreak_p_;
136     delete postbreak_p_;        
137 }
138
139 void
140 PCol::add( Item *i)
141 {
142     its.bottom().add(i);
143     i->pcol_l_ = this; 
144 }
145
146 bool
147 PCol::used_b()const
148 {
149     return breakable_b() || its.size();
150 }