2 rest-collision.cc -- implement Rest_collision
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include <math.h> // ceil.
12 #include "rest-collision.hh"
13 #include "note-column.hh"
15 #include "note-head.hh"
16 #include "collision.hh"
17 #include "paper-def.hh"
19 #include "group-interface.hh"
22 Rest_collision::add_column (Note_column *nc_l)
24 add_dependency (nc_l);
25 Group_interface gi (this);
31 gi.add_element (nc_l);
35 Rest_collision::do_pre_processing()
37 Link_array<Note_column> rest_l_arr =
38 Group_interface__extract_elements (this, (Note_column*) 0, "rests");
39 Link_array<Note_column> ncol_l_arr =
40 Group_interface__extract_elements (this, (Note_column*) 0, "notes");
44 handle rest-rest and rest-note collisions
47 * decide not to print rest if too crowded?
49 * ignore rests under beams.
52 // no rests to collide
53 if (!rest_l_arr.size())
56 // no partners to collide with
57 if (rest_l_arr.size() + ncol_l_arr.size () < 2)
60 // meisjes met meisjes
61 if (!ncol_l_arr.size())
64 UGH. Should get dims from table. Should have minimum dist.
66 int dy = rest_l_arr.size() > 2 ? 6 : 4;
68 rest_l_arr[0]->translate_rests (rest_l_arr[0]->dir () *dy);
69 rest_l_arr.top()->translate_rests (rest_l_arr.top ()->dir ()* dy);
71 // meisjes met jongetjes
74 if (rest_l_arr.size () > 1)
76 warning (_("too many colliding rests"));
78 if (ncol_l_arr.size () > 1)
80 warning (_("too many notes for rest collision"));
82 Note_column * rcol = rest_l_arr[0];
84 // try to be opposite of noteheads.
85 Direction dir = - ncol_l_arr[0]->dir();
87 Interval restdim = rcol->rest_dim ();
88 if (restdim.empty_b ())
92 Real staff_space = paper_l()->get_var ("interline");
95 staff_space = rcol->rest_l_arr[0]->staff_space ();
97 Real half_staff_space_f = staff_space/2;
98 Real minimum_dist = paper_l ()->get_var ("restcollision_minimum_dist")
102 assumption: ref points are the same.
105 for (int i = 0; i < ncol_l_arr.size(); i++)
107 notedim.unite (ncol_l_arr[i]->extent (Y_AXIS));
110 Interval inter (notedim);
111 inter.intersect (restdim);
114 minimum_dist + dir * (notedim[dir] - restdim[-dir]) >? 0;
118 int stafflines = 5; // rcol->rest_l_arr[0]->line_count;
121 // move discretely by half spaces.
122 int discrete_dist = int (ceil (dist / (0.5 *staff_space)));
124 // move by whole spaces inside the staff.
125 if (discrete_dist < stafflines+1)
126 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
128 rcol->translate_rests (dir * discrete_dist);
133 Rest_collision::Rest_collision()
135 set_elt_property ("rests", SCM_EOL);
136 set_elt_property ("notes", SCM_EOL);
137 set_elt_property ("transparent", SCM_BOOL_T);