]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-collision.cc
patch::: 1.1.24.jcn1: jcn1
[lilypond.git] / lily / rest-collision.cc
1 /*
2   rest-collision.cc -- implement Rest_collision
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
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
17
18
19
20 void
21 Rest_collision::add_column (Note_column *nc_l)
22 {
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);
28 }
29
30 void
31 Rest_collision::do_post_processing()
32 {
33   /*
34     [TODO]
35     handle rest under beam (do_post: beams are calculated now)
36     what about combination of collisions and rest under beam
37    */
38 }
39
40 void
41 Rest_collision::do_pre_processing()
42 {
43   /* 
44      handle rest-rest and rest-note collisions
45
46      [todo]
47      decide not to print rest if too crowded?
48    */
49
50   // no rests to collide
51   if (!rest_l_arr_.size())
52     return;
53
54   // no partners to collide with
55   if (rest_l_arr_.size() + ncol_l_arr_.size () < 2)
56     return;
57
58   // meisjes met meisjes
59   if (!ncol_l_arr_.size()) 
60     {
61       int dy = rest_l_arr_.size() > 2 ? 6 : 4;
62         
63       rest_l_arr_[0]->translate_rests (rest_l_arr_[0]->dir_ *dy);       
64       // top is last element...
65       rest_l_arr_.top()->translate_rests (rest_l_arr_.top ()->dir_* dy);        
66     }
67   // meisjes met jongetjes
68   else 
69     {
70       // int dir_i = - ncol_l_arr_[0]->dir_;
71       int dir_i = rest_l_arr_[0]->dir_;
72         
73       // minimum move
74       int minpos = 4;
75         
76       // quart rest height
77       // UGH Should get dims from table!
78       int size_i = 6;
79         
80       Real internote_f = paper ()->internote_f ();
81       int sep_i = 3 + size_i / 2;
82       for (int i = 0; i < ncol_l_arr_.size(); i++) 
83         {
84           // how to know whether to sort?
85           ncol_l_arr_[i]->sort();
86           for (int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
87             {
88               int stem = (int)((ncol_l_arr_[i]->stem_l_->extent
89                                (Y_AXIS)[dir_i]) / internote_f);
90               minpos = minpos >? (dir_i * stem + sep_i);
91             }
92         }
93       rest_l_arr_[0]->translate_rests (dir_i * minpos); 
94     }
95 }
96
97 void
98 Rest_collision::do_print() const
99 {
100 #ifndef NPRINT
101   DOUT << "rests: " << rest_l_arr_.size() << ", ";
102   DOUT << "cols: " << ncol_l_arr_.size();
103 #endif
104 }
105
106 void
107 Rest_collision::do_substitute_dependency (Score_element*o,Score_element*n)
108 {
109   if (Note_column *onl = dynamic_cast<Note_column *> (o))
110     {
111       Note_column *n_l = n?dynamic_cast<Note_column *> (n):0;
112       rest_l_arr_.substitute (onl, n_l);
113       ncol_l_arr_.substitute (onl, n_l);
114     }
115 }
116
117 Rest_collision::Rest_collision()
118 {
119   transparent_b_ = true;
120   set_empty (true);
121 }