lilypond-1.1.21
[lilypond.git] / lily / rest-collision.cc
blob35a41c6f9d00c76d2915942c8e9504983a2deecd
1 /*
2 rest-collision.cc -- implement Rest_collision
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "debug.hh"
10 #include "rest-collision.hh"
11 #include "note-column.hh"
12 #include "stem.hh"
13 #include "note-head.hh"
14 #include "collision.hh"
15 #include "paper-def.hh"
20 void
21 Rest_collision::add_column (Note_column *nc_l)
23 add_dependency (nc_l);
24 if (nc_l->rest_b ())
25 rest_l_arr_.push (nc_l);
26 else
27 ncol_l_arr_.push (nc_l);
30 void
31 Rest_collision::do_post_processing()
34 handle rest under beam (do_post: beams are calculated now)
36 [todo]
37 i-d like to have access to the beam itself,
38 iso only the (half-initialised?) stem
40 what about combination of collisions and rest under beam
43 // no rests to collide
44 if (!rest_l_arr_.size())
45 return;
46 // can this happen?
47 Stem* stem_l = rest_l_arr_[0]->stem_l_;
48 if (!stem_l)
49 return;
50 // no beam
51 if (!(stem_l->beams_i_drul_[LEFT] || stem_l->beams_i_drul_[RIGHT]))
52 return;
54 int dir_i = rest_l_arr_[0]->dir_;
55 int midpos = 4;
56 // ugh
57 int stem_length_i = 7 - 2;
58 // ugh, Stem::stem_start vs Stem::stem_end
59 int pos = (int)(stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
61 nogo: stem_start not set for rests?
62 int pos = (stem_l->stem_begin_f() - midpos) + dir_i * 2;
64 WHY IS THIS STILL HERE? --hwn
66 rest_l_arr_[0]->translate_rests (pos);
69 void
70 Rest_collision::do_pre_processing()
72 /*
73 handle rest-rest and rest-note collisions
75 [todo]
76 decide not to print rest if too crowded?
79 // no rests to collide
80 if (!rest_l_arr_.size())
81 return;
83 // no partners to collide with
84 if (rest_l_arr_.size() + ncol_l_arr_.size () < 2)
85 return;
87 // meisjes met meisjes
88 if (!ncol_l_arr_.size())
90 int dy = rest_l_arr_.size() > 2 ? 6 : 4;
92 rest_l_arr_[0]->translate_rests (rest_l_arr_[0]->dir_ *dy);
93 // top is last element...
94 rest_l_arr_.top()->translate_rests (rest_l_arr_.top ()->dir_* dy);
96 // meisjes met jongetjes
97 else
99 // int dir_i = - ncol_l_arr_[0]->dir_;
100 int dir_i = rest_l_arr_[0]->dir_;
101 // hope it's 4: if it works->doco
102 int midpos = 0;
104 // minimum move
105 int minpos = 4;
107 // quart rest height
108 // UGH Should get dims from table!
109 int size_i = 6;
111 int sep_i = 3 + size_i / 2;
112 for (int i = 0; i < ncol_l_arr_.size(); i++)
114 // how to know whether to sort?
115 ncol_l_arr_[i]->sort();
116 for (int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
117 minpos = minpos >? dir_i *
118 (ncol_l_arr_[i]->head_l_arr_[j]->position_i_ -midpos) + sep_i;
120 rest_l_arr_[0]->translate_rests (dir_i * minpos);
124 void
125 Rest_collision::do_print() const
127 #ifndef NPRINT
128 DOUT << "rests: " << rest_l_arr_.size() << ", ";
129 DOUT << "cols: " << ncol_l_arr_.size();
130 #endif
133 void
134 Rest_collision::do_substitute_dependency (Score_element*o,Score_element*n)
136 if (Note_column *onl = dynamic_cast<Note_column *> (o))
138 Note_column *n_l = n?dynamic_cast<Note_column *> (n):0;
139 rest_l_arr_.substitute (onl, n_l);
140 ncol_l_arr_.substitute (onl, n_l);
144 Rest_collision::Rest_collision()
146 transparent_b_ = true;
147 set_empty (true);