]> git.donarmstrong.com Git - lilypond.git/blob - lily/item.cc
release: 0.1.9
[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   DOUT << "(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     {
60         Item * item_p = clone()->item ();
61         item_p->copy_dependencies (*this);
62         
63         item_p->break_status_i_ =  -1+ 2*i;
64         pscore_l_->typeset_item (item_p, pcol_l_);
65         item_p->handle_prebroken_dependencies();
66         new_copies[i] =item_p;
67     }
68   broken_to_a_= new_copies;
69 }
70
71 void
72 Item::do_breakable_col_processing()
73 {
74   if (!breakable_b_ || !pcol_l_->breakable_b())
75         return;
76
77   copy_breakable_items();
78   handle_prebroken_dependencies();
79
80   /*
81     Otherwise the broken items won't be pre_process()'ed.
82    */
83   add_dependency (broken_to_a_[0]);
84   add_dependency (broken_to_a_[1]);    
85
86 }
87
88 Item*
89 Item::find_prebroken_piece (Line_of_score*l) const
90 {
91   if (line_l() == l) 
92         return (Item*)this;
93   else if (broken_to_a_[0] && broken_to_a_[0]->line_l() == l)
94         return broken_to_a_[0];
95   else if (broken_to_a_[1] && broken_to_a_[1]->line_l() == l)
96         return broken_to_a_[1];
97
98   return 0;
99 }
100
101 Item*
102 Item::find_prebroken_piece (PCol*c)const
103 {
104   if (c == pcol_l_)
105         return (Item *) this;   // ugh
106
107   if (c == pcol_l_->prebreak_p_)
108         return (Item *) broken_to_a_[0];
109   else if (c==pcol_l_->postbreak_p_)
110         return  (Item *)broken_to_a_[1];
111
112   assert (false);
113 }
114
115 void
116 Item::handle_prebroken_dependencies()
117 {
118   if ( breakable_b_)
119         Score_elem::handle_prebroken_dependencies();
120 }