]> git.donarmstrong.com Git - lilypond.git/blob - lily/item.cc
release: 0.1.7
[lilypond.git] / lily / item.cc
1 /*
2   item.cc -- implement Item
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-score.hh"
10 #include "debug.hh"
11 #include "item.hh"
12 #include "p-col.hh"
13 #include "elem-group.hh"
14
15 Item::Item()
16 {
17     breakable_b_ = false;
18     break_status_i_ = 0;
19     pcol_l_ = 0;
20     broken_to_a_[0] = broken_to_a_[1]=0;
21 }
22
23 IMPLEMENT_IS_TYPE_B1(Item, Score_elem);
24
25 void
26 Item::do_print() const
27 {
28 #ifndef NPRINT
29     mtor << "(unknown)";
30 #endif
31 }
32
33
34 Real 
35 Item::hpos_f()const
36 {
37     return pcol_l_->hpos_f_ + absolute_coordinate(X_AXIS);
38 }
39
40 Line_of_score *
41 Item::line_l()const
42 {
43     return pcol_l_->line_l_;
44 }
45
46 int
47 Item::break_status_i() const
48 {
49     return break_status_i_;
50 }
51
52 void
53 Item::copy_breakable_items()
54 {
55     if ( broken_to_a_[0] || broken_to_a_[1] )
56         return;
57     Item *new_copies[2];
58     for (int i=0; i < 2; i++) {
59         Item * item_p = clone()->item();
60         item_p->copy_dependencies(*this);
61         
62         item_p->break_status_i_ =  -1+ 2*i;
63         pscore_l_->typeset_item(item_p, pcol_l_);
64         item_p->handle_prebroken_dependencies();
65         new_copies[i] =item_p;
66     }
67     broken_to_a_= new_copies;
68 }
69
70 void
71 Item::do_breakable_col_processing()
72 {
73     if (!breakable_b_ || !pcol_l_->breakable_b())
74         return;
75
76     copy_breakable_items();
77     handle_prebroken_dependencies();
78
79     /*
80       Otherwise the broken items won't be pre_process()'ed.
81      */
82     add_dependency( broken_to_a_[0] );
83     add_dependency( broken_to_a_[1] );    
84
85 }
86
87 Item*
88 Item::find_prebroken_piece(Line_of_score*l) const
89 {
90     if (line_l() == l) 
91         return (Item*)this;
92     else if (broken_to_a_[0] && broken_to_a_[0]->line_l() == l)
93         return broken_to_a_[0];
94     else if (broken_to_a_[1] && broken_to_a_[1]->line_l() == l)
95         return broken_to_a_[1];
96
97     return 0;
98 }
99
100 Item*
101 Item::find_prebroken_piece(PCol*c)const
102 {
103     if (c == pcol_l_ )
104         return (Item *) this;   // ugh
105
106     if (c == pcol_l_->prebreak_p_)
107         return (Item *) broken_to_a_[0];
108     else if (c==pcol_l_->postbreak_p_)
109         return  (Item *)broken_to_a_[1];
110
111     assert(false);
112 }
113
114 void
115 Item::handle_prebroken_dependencies()
116 {
117     if ( breakable_b_ )
118         Score_elem::handle_prebroken_dependencies();
119 }