lilypond-1.3.16
[lilypond.git] / lily / rest-collision.cc
blob1f1c8748068ab97ae29edf8f7dff659e8677f52a
1 /*
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>
7 */
8 #include "beam.hh"
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"
16 #include "rest.hh"
17 #include "group-interface.hh"
19 void
20 Rest_collision::add_column (Note_column *nc_l)
22 add_dependency (nc_l);
23 Group_interface gi (this);
24 if (nc_l->rest_b ())
25 gi.name_ = "rests";
26 else
27 gi.name_ = "notes";
29 gi.add_element (nc_l);
32 void
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");
41 /*
42 handle rest-rest and rest-note collisions
44 [todo]
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())
52 return;
54 // no partners to collide with
55 if (rest_l_arr.size() + ncol_l_arr.size () < 2)
56 return;
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
70 else
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 ())
87 return;
89 // staff ref'd?
90 Real staff_space = paper_l()->get_var ("interline");
92 /* FIXME
93 staff_space = rcol->rest_l_arr[0]->staff_space ();
95 Real half_staff_space_f = staff_space/2;
96 Real minimum_dist = paper_l ()->get_var ("restcollision_minimum_dist")
97 * half_staff_space_f;
100 assumption: ref points are the same.
102 Interval notedim;
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);
111 Real dist =
112 minimum_dist + dir * (notedim[dir] - restdim[-dir]) >? 0;
115 // FIXME
116 int stafflines = 5; // rcol->rest_l_arr[0]->line_count;
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);
136 set_empty (X_AXIS);
137 set_empty (Y_AXIS);