]> git.donarmstrong.com Git - lilypond.git/blob - lily/item.cc
78db9884e97fadeb4f5fb11877a222066c5cda81
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.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 #include "spanner.hh"
15
16 Item::Item ()
17 {
18   unbroken_original_l_ =0;
19   break_priority_i_ = 0;
20   breakable_b_ = false;
21   break_status_dir_ = CENTER;
22   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT]=0;
23 }
24
25 IMPLEMENT_IS_TYPE_B1(Item, Score_element);
26
27 void
28 Item::do_print() const
29 {
30 #ifndef NPRINT
31   DOUT << "breakable_b_: " << breakable_b_ << 
32     " break_status_dir_: " << break_status_dir_;
33 #endif
34 }
35
36
37 Real 
38 Item::hpos_f() const
39 {
40   return absolute_coordinate (X_AXIS);
41 }
42
43 Line_of_score *
44 Item::line_l() const
45 {
46   Graphical_axis_group *ga = axis_group_l_a_[X_AXIS];
47   
48   if (!ga)
49     return 0;
50   
51   assert (ga->access_Score_element());
52   return ga->access_Score_element ()-> line_l ();
53 }
54
55 Direction
56 Item::break_status_dir() const
57 {
58   return break_status_dir_;
59 }
60
61 void
62 Item::copy_breakable_items()
63 {
64   if (broken_to_drul_[LEFT] || broken_to_drul_[RIGHT])
65     return;
66   Drul_array<Item *> new_copies;
67   Direction  i=LEFT;
68   do 
69     {
70       Item * item_p = clone()->access_Item ();
71
72       item_p->break_status_dir_ =  i;
73       pscore_l_->typeset_element (item_p);
74       item_p->handle_prebroken_dependencies();
75       new_copies[i] =item_p;
76     }
77   while (flip(&i) != LEFT);
78   broken_to_drul_= new_copies;
79 }
80
81 void
82 Item::do_breakable_col_processing()
83 {
84   if (!breakable_b_)
85     return;
86
87   if (!column_l ()->breakable_b_)
88     return;
89
90   copy_breakable_items();
91   handle_prebroken_dependencies();
92
93   /*
94     Otherwise the broken items won't be pre_process()'ed.
95   */
96   add_dependency (broken_to_drul_[LEFT]);
97   add_dependency (broken_to_drul_[RIGHT]);    
98 }
99
100 Item*
101 Item::find_prebroken_piece (Line_of_score*l) const
102 {
103   if (line_l() == l) 
104     return (Item*)this;
105   else if (broken_to_drul_[LEFT] && broken_to_drul_[LEFT]->line_l() == l)
106     return broken_to_drul_[LEFT];
107   else if (broken_to_drul_[RIGHT] && broken_to_drul_[RIGHT]->line_l() == l)
108     return broken_to_drul_[RIGHT];
109
110   return 0;
111 }
112
113 Item*
114 Item::find_prebroken_piece (Direction breakstatus) const
115 {
116   if (!breakstatus)
117     return (Item *) this;       // ugh
118   else
119     return (Item*) broken_to_drul_[breakstatus];
120 }
121
122 void
123 Item::handle_prebroken_dependencies()
124 {
125   if (breakable_b_)
126     Score_element::handle_prebroken_dependencies();
127 }
128
129 int
130 Item::left_right_compare(Item const *l, Item const *r)
131 {
132   while (!l->is_type_b (Paper_column::static_name ()))
133     l = l->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
134   while (!r->is_type_b (Paper_column::static_name ()))
135     r = r->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
136
137   Paper_column *p1 = (Paper_column*)l;
138   Paper_column* p2 = (Paper_column*)r;
139   return p1->rank_i () - p2->rank_i ();
140 }
141
142
143 bool
144 Item::linked_b() const
145 {
146   return Score_element::linked_b() || attached_span_l_arr_.size();
147 }
148
149 void
150 Item::do_junk_links()
151 {
152   attached_span_l_arr_.set_size(0);
153 }
154
155 void
156 Item::do_unlink()
157 {
158   Link_array<Spanner> attached=attached_span_l_arr_;
159   for (int i=0; i < attached.size (); i++)
160     {
161       Spanner *s= attached[i];
162
163       Direction d= LEFT;
164       do {
165         if (s->spanned_drul_[d] == this)
166           s->set_bounds (d, 0);
167         if (unbroken_original_l_
168             && unbroken_original_l_-> broken_to_drul_[d] == this)
169           unbroken_original_l_->broken_to_drul_[d] = 0;
170       } while (flip (&d) != LEFT);
171     }
172   assert (!attached_span_l_arr_.size ());
173   unbroken_original_l_ =0;
174 }
175
176 Paper_column *
177 Item::column_l () const
178 {
179   return axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ()->column_l ();
180 }
181
182 Item::Item (Item const &s)
183   : Score_element (s)
184 {
185   unbroken_original_l_ = &s;
186   /* do not copy attached_span_l_arr_ */
187   breakable_b_ = s.breakable_b_;
188   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] =0;
189   break_status_dir_ = s.break_status_dir_;
190   break_priority_i_ = s.break_priority_i_;
191 }
192
193 Item *
194 Item::access_Item ()
195 {
196   return this; 
197 }