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 Real inter_f = paper()->internote_f();
68 int dir_i = rest_l_arr_[0]->dir_i_;
72 int stem_length_i = 7 - 2;
73 // ugh, Stem::stem_start vs Stem::stem_end
74 int pos = (stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
75 #else // nogo: stem_start not set for rests?
76 int pos = (stem_l->stem_start_f() - midpos) + dir_i * 2;
78 Real dy = pos * inter_f;
79 rest_l_arr_[0]->translate_y(dy);
83 Rest_collision::do_pre_processing()
86 handle rest-rest and rest-note collisions
89 decide not to print rest if too crowded?
92 // no rests to collide
93 if (!rest_l_arr_.size())
96 // no partners to collide with
97 if (rest_l_arr_.size() + ncol_l_arr_.size() < 2 )
100 Real inter_f = paper()->internote_f();
102 // meisjes met meisjes
103 if (!ncol_l_arr_.size()) {
104 Real dy = rest_l_arr_.size() > 2 ? 6 * inter_f : 4 * inter_f;
105 rest_l_arr_[0]->translate_y(dy);
106 // top is last element...
107 rest_l_arr_.top()->translate_y(-dy);
109 // meisjes met jongetjes
111 #if 0 // breendet: rests go always under
112 // geen gemug, trug op je rug
114 rest_l_arr_[0]->translate_y(dir_i * 3 * inter_f);
116 // int dir_i = - ncol_l_arr_[0]->dir_i_;
117 int dir_i = rest_l_arr_[0]->dir_i_;
118 // hope it's 4: if it works->doco
124 int sep_i = 3 + size_i / 2;
125 for (int i = 0; i < ncol_l_arr_.size(); i++) {
126 // how to know whether to sort?
127 ncol_l_arr_[i]->sort();
128 for ( int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++ )
129 minpos = minpos >? dir_i * ( ncol_l_arr_[i]->head_l_arr_[j]->position_i_ - midpos ) + sep_i;
131 Real dy = dir_i * minpos * inter_f;
132 rest_l_arr_[0]->translate_y(dy);
138 Rest_collision::do_print() const
141 mtor << "rests: " << rest_l_arr_.size() << ", ";
142 mtor << "cols: " << ncol_l_arr_.size();
147 Rest_collision::do_substitute_dependency(Score_elem*o,Score_elem*n)
149 Item*o_l = o->item();
150 Item*n_l = n?n->item():0;
152 rest_l_arr_.substitute((Rest_column*)o_l,(Rest_column*)n_l);
153 ncol_l_arr_.substitute((Note_column*)o_l,(Note_column*)n_l);
156 Rest_collision::Rest_collision()
158 transparent_b_ = true;