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