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);
25 ncol_l_arr_.push (nc_l);
29 Rest_collision::add (Rest_column *rc_l)
31 add_dependency (rc_l);
32 rest_l_arr_.push (rc_l);
36 Rest_collision::do_post_processing()
39 handle rest under beam (do_post: beams are calculated now)
42 i-d like to have access to the beam itself,
43 iso only the (half-initialised?) stem
45 what about combination of collisions and rest under beam
48 // no rests to collide
49 if (!rest_l_arr_.size())
52 Stem* stem_l = rest_l_arr_[0]->stem_l_;
56 if (!(stem_l->beams_left_i_ || stem_l->beams_right_i_))
59 int dir_i = rest_l_arr_[0]->dir_i_;
63 int stem_length_i = 7 - 2;
64 // ugh, Stem::stem_start vs Stem::stem_end
65 int pos = (stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
66 #else // nogo: stem_start not set for rests?
67 int pos = (stem_l->stem_start_f() - midpos) + dir_i * 2;
69 rest_l_arr_[0]->translate_heads (pos);
73 Rest_collision::do_pre_processing()
76 handle rest-rest and rest-note collisions
79 decide not to print rest if too crowded?
82 // no rests to collide
83 if (!rest_l_arr_.size())
86 // no partners to collide with
87 if (rest_l_arr_.size() + ncol_l_arr_.size () < 2)
90 // meisjes met meisjes
91 if (!ncol_l_arr_.size())
93 int dy = rest_l_arr_.size() > 2 ? 6 : 4;
95 rest_l_arr_[0]->translate_heads (rest_l_arr_[0]->dir_i_ *dy);
96 // top is last element...
97 rest_l_arr_.top()->translate_heads (rest_l_arr_.top ()->dir_i_* dy);
99 // meisjes met jongetjes
102 #if 0 // breendet: rests go always under
103 // geen gemug, trug op je rug
105 rest_l_arr_[0]->translate_heads (dir_i * 3);
107 // int dir_i = - ncol_l_arr_[0]->dir_i_;
108 int dir_i = rest_l_arr_[0]->dir_i_;
109 // hope it's 4: if it works->doco
116 // UGH Should get dims from table!
119 int sep_i = 3 + size_i / 2;
120 for (int i = 0; i < ncol_l_arr_.size(); i++)
122 // how to know whether to sort?
123 ncol_l_arr_[i]->sort();
124 for ( int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
125 minpos = minpos >? dir_i *
126 (ncol_l_arr_[i]->head_l_arr_[j]->position_i_ -midpos) + sep_i;
128 rest_l_arr_[0]->translate_heads (dir_i * minpos);
134 Rest_collision::do_print() const
137 DOUT << "rests: " << rest_l_arr_.size() << ", ";
138 DOUT << "cols: " << ncol_l_arr_.size();
143 Rest_collision::do_substitute_dependency (Score_elem*o,Score_elem*n)
145 Item*o_l = o->item();
146 Item*n_l = n?n->item():0;
148 rest_l_arr_.substitute ((Rest_column*)o_l,(Rest_column*)n_l);
149 ncol_l_arr_.substitute ((Note_column*)o_l,(Note_column*)n_l);
152 Rest_collision::Rest_collision()
154 transparent_b_ = true;