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"
19 IMPLEMENT_IS_TYPE_B1(Rest_collision,Item);
22 Rest_collision::add (Note_column *nc_l)
24 add_dependency (nc_l);
26 rest_l_arr_.push (nc_l);
28 ncol_l_arr_.push (nc_l);
32 Rest_collision::do_post_processing()
35 handle rest under beam (do_post: beams are calculated now)
38 i-d like to have access to the beam itself,
39 iso only the (half-initialised?) stem
41 what about combination of collisions and rest under beam
44 // no rests to collide
45 if (!rest_l_arr_.size())
48 Stem* stem_l = rest_l_arr_[0]->stem_l_;
52 if (!(stem_l->beams_left_i_ || stem_l->beams_right_i_))
55 int dir_i = rest_l_arr_[0]->dir_;
59 int stem_length_i = 7 - 2;
60 // ugh, Stem::stem_start vs Stem::stem_end
61 int pos = (int)(stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
62 #else // nogo: stem_start not set for rests?
63 int pos = (stem_l->stem_start_f() - midpos) + dir_i * 2;
65 rest_l_arr_[0]->translate_rests (pos);
69 Rest_collision::do_pre_processing()
72 handle rest-rest and rest-note collisions
75 decide not to print rest if too crowded?
78 // no rests to collide
79 if (!rest_l_arr_.size())
82 // no partners to collide with
83 if (rest_l_arr_.size() + ncol_l_arr_.size () < 2)
86 // meisjes met meisjes
87 if (!ncol_l_arr_.size())
89 int dy = rest_l_arr_.size() > 2 ? 6 : 4;
91 rest_l_arr_[0]->translate_rests (rest_l_arr_[0]->dir_ *dy);
92 // top is last element...
93 rest_l_arr_.top()->translate_rests (rest_l_arr_.top ()->dir_* dy);
95 // meisjes met jongetjes
98 #if 0 // breendet: rests go always under
99 // geen gemug, trug op je rug
101 rest_l_arr_[0]->translate_rests (dir_i * 3);
103 // int dir_i = - ncol_l_arr_[0]->dir_;
104 int dir_i = rest_l_arr_[0]->dir_;
105 // hope it's 4: if it works->doco
112 // UGH Should get dims from table!
115 int sep_i = 3 + size_i / 2;
116 for (int i = 0; i < ncol_l_arr_.size(); i++)
118 // how to know whether to sort?
119 ncol_l_arr_[i]->sort();
120 for (int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
121 minpos = minpos >? dir_i *
122 (ncol_l_arr_[i]->head_l_arr_[j]->position_i_ -midpos) + sep_i;
124 rest_l_arr_[0]->translate_rests (dir_i * minpos);
130 Rest_collision::do_print() const
133 DOUT << "rests: " << rest_l_arr_.size() << ", ";
134 DOUT << "cols: " << ncol_l_arr_.size();
139 Rest_collision::do_substitute_dependency (Score_elem*o,Score_elem*n)
141 Item*o_l = o->item();
144 if (o_l&&o_l->is_type_b (Note_column::static_name ()))
146 Note_column *n_l = n?(Note_column*)n->item():0;
147 rest_l_arr_.substitute ((Note_column*)o_l, n_l);
148 ncol_l_arr_.substitute ((Note_column*)o_l, n_l);
152 Rest_collision::Rest_collision()
154 transparent_b_ = true;