]> git.donarmstrong.com Git - lilypond.git/blob - lily/item.cc
release: 0.1.1
[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     pcol_l_ = 0;
18     broken_to_a_[0]
19         = broken_to_a_[1]=0;
20 }
21
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::copy_breakable_items()
63 {
64     for (int i=0; i < 2; i++) {
65         Item * item_p = clone()->item();
66         item_p->copy_dependencies(*this);
67         /* add our pre and postbreaks blondly to our own y_group
68            Let Vertical_group_spanner figure out the mess.
69          */
70         if  ( y_group_l_ )
71             y_group_l_->add_element( item_p );
72         pscore_l_->typeset_item(item_p, pcol_l_, -1+ 2*i);
73         item_p->handle_prebroken_dependencies();
74         broken_to_a_[i] = item_p;
75     }
76 }
77
78 void
79 Item::do_breakable_col_processing()
80 {
81     PCol * c = pcol_l_;
82     if (!c->breakable_b())
83         return;
84     
85     copy_breakable_items();
86     handle_prebroken_dependencies();
87 }
88
89 Item*
90 Item::find_prebroken_piece(Line_of_score*l) const
91 {
92     if (line_l() == l) 
93         return (Item*)this;
94     else if (broken_to_a_[0] && broken_to_a_[0]->line_l() == l)
95         return broken_to_a_[0];
96     else if (broken_to_a_[1] && broken_to_a_[1]->line_l() == l)
97         return broken_to_a_[1];
98
99     return 0;
100 }
101
102 Item*
103 Item::find_prebroken_piece(PCol*c)const
104 {
105     if (c == pcol_l_ )
106         return (Item *) this;   // ugh
107
108     if (c == pcol_l_->prebreak_p_)
109         return (Item *) broken_to_a_[0];
110     else if (c==pcol_l_->postbreak_p_)
111         return  (Item *)broken_to_a_[1];
112
113     assert(false);
114 }
115
116 void
117 Item::handle_prebroken_dependencies()
118 {
119     if ( pcol_l_->breakable_b() || pcol_l_->daddy_l_ )
120         Score_elem::handle_prebroken_dependencies();
121 }