2 rest-collision.cc -- implement Rest_collision
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
10 #include "rest-collision.hh"
11 #include "rest-column.hh"
12 #include "note-column.hh"
14 #include "note-head.hh"
15 #include "collision.hh"
16 #include "paper-def.hh"
18 IMPLEMENT_STATIC_NAME(Rest_collision);
19 IMPLEMENT_IS_TYPE_B1(Rest_collision,Item);
22 Rest_collision::add(Note_column *nc_l)
25 ncol_l_arr_.push(nc_l);
29 Rest_collision::add(Rest_column *rc_l)
32 rest_l_arr_.push(rc_l);
36 Rest_collision::add(Collision * c_l)
39 for (int i=0; i < c_l->clash_l_arr_.size(); i ++)
40 ncol_l_arr_.push(c_l->clash_l_arr_[i]);
44 Rest_collision::do_post_processing()
47 handle rest under beam (do_post: beams are calculated now)
50 i-d like to have access to the beam itself,
51 iso only the (half-initialised?) stem
53 what about combination of collisions and rest under beam
56 // no rests to collide
57 if (!rest_l_arr_.size())
60 Stem* stem_l = rest_l_arr_[0]->stem_l_;
64 if (!(stem_l->beams_left_i_ || stem_l->beams_right_i_))
67 int dir_i = rest_l_arr_[0]->dir_i_;
71 int stem_length_i = 7 - 2;
72 // ugh, Stem::stem_start vs Stem::stem_end
73 int pos = (stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
74 #else // nogo: stem_start not set for rests?
75 int pos = (stem_l->stem_start_f() - midpos) + dir_i * 2;
77 rest_l_arr_[0]->translate_heads(pos);
81 Rest_collision::do_pre_processing()
84 handle rest-rest and rest-note collisions
87 decide not to print rest if too crowded?
90 // no rests to collide
91 if (!rest_l_arr_.size())
94 // no partners to collide with
95 if (rest_l_arr_.size() + ncol_l_arr_.size() < 2 )
98 // meisjes met meisjes
99 if (!ncol_l_arr_.size()) {
100 int dy = rest_l_arr_.size() > 2 ? 6 : 4;
102 rest_l_arr_[0]->translate_heads(rest_l_arr_[0]->dir_i_ *dy);
103 // top is last element...
104 rest_l_arr_.top()->translate_heads(rest_l_arr_.top()->dir_i_* dy);
106 // meisjes met jongetjes
108 #if 0 // breendet: rests go always under
109 // geen gemug, trug op je rug
111 rest_l_arr_[0]->translate_heads(dir_i * 3 );
113 // int dir_i = - ncol_l_arr_[0]->dir_i_;
114 int dir_i = rest_l_arr_[0]->dir_i_;
115 // hope it's 4: if it works->doco
122 // UGH Should get dims from table!
125 int sep_i = 3 + size_i / 2;
126 for (int i = 0; i < ncol_l_arr_.size(); i++) {
127 // how to know whether to sort?
128 ncol_l_arr_[i]->sort();
129 for ( int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++ )
130 minpos = minpos >? dir_i *
131 (ncol_l_arr_[i]->head_l_arr_[j]->position_i_ -midpos ) + sep_i;
133 rest_l_arr_[0]->translate_heads(dir_i * minpos );
139 Rest_collision::do_print() const
142 mtor << "rests: " << rest_l_arr_.size() << ", ";
143 mtor << "cols: " << ncol_l_arr_.size();
148 Rest_collision::do_substitute_dependency(Score_elem*o,Score_elem*n)
150 Item*o_l = o->item();
151 Item*n_l = n?n->item():0;
153 rest_l_arr_.substitute((Rest_column*)o_l,(Rest_column*)n_l);
154 ncol_l_arr_.substitute((Note_column*)o_l,(Note_column*)n_l);
157 Rest_collision::Rest_collision()
159 transparent_b_ = true;