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