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