2 rest-collision.cc -- implement Rest_collision
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "rest-collision.hh"
11 #include "note-column.hh"
13 #include "note-head.hh"
14 #include "collision.hh"
15 #include "paper-def.hh"
17 #include "group-interface.hh"
20 Rest_collision::add_column (Note_column *nc_l)
22 add_dependency (nc_l);
23 Group_interface gi (this);
29 gi.add_element (nc_l);
33 Rest_collision::do_pre_processing()
35 Link_array<Note_column> rest_l_arr =
36 Group_interface__extract_elements (this, (Note_column*) 0, "rests");
37 Link_array<Note_column> ncol_l_arr =
38 Group_interface__extract_elements (this, (Note_column*) 0, "notes");
42 handle rest-rest and rest-note collisions
45 * decide not to print rest if too crowded?
47 * ignore rests under beams.
50 // no rests to collide
51 if (!rest_l_arr.size())
54 // no partners to collide with
55 if (rest_l_arr.size() + ncol_l_arr.size () < 2)
58 // meisjes met meisjes
59 if (!ncol_l_arr.size())
62 UGH. Should get dims from table. Should have minimum dist.
64 int dy = rest_l_arr.size() > 2 ? 6 : 4;
66 rest_l_arr[0]->translate_rests (rest_l_arr[0]->dir () *dy);
67 rest_l_arr.top()->translate_rests (rest_l_arr.top ()->dir ()* dy);
69 // meisjes met jongetjes
72 if (rest_l_arr.size () > 1)
74 warning (_("too many colliding rests"));
76 if (ncol_l_arr.size () > 1)
78 warning (_("too many notes for rest collision"));
80 Note_column * rcol = rest_l_arr[0];
82 // try to be opposite of noteheads.
83 Direction dir = - ncol_l_arr[0]->dir();
85 Interval restdim = rcol->rest_dim ();
86 if (restdim.empty_b ())
90 Real staff_space = paper_l()->get_var ("interline");
93 staff_space = rcol->rest_l_arr[0]->staff_line_leading_f ();
95 Real internote_f = staff_space/2;
96 Real minimum_dist = paper_l ()->get_var ("restcollision_minimum_dist")
100 assumption: ref points are the same.
103 for (int i = 0; i < ncol_l_arr.size(); i++)
105 notedim.unite (ncol_l_arr[i]->extent (Y_AXIS));
108 Interval inter (notedim);
109 inter.intersect (restdim);
112 minimum_dist + dir * (notedim[dir] - restdim[-dir]) >? 0;
116 int stafflines = 5; // rcol->rest_l_arr[0]->lines_i ();
119 // move discretely by half spaces.
120 int discrete_dist = int (ceil (dist / (0.5 *staff_space)));
122 // move by whole spaces inside the staff.
123 if (discrete_dist < stafflines+1)
124 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
126 rcol->translate_rests (dir * discrete_dist);
131 Rest_collision::Rest_collision()
133 set_elt_property ("rests", SCM_EOL);
134 set_elt_property ("notes", SCM_EOL);
135 set_elt_property ("transparent", SCM_BOOL_T);