]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-collision.cc
release: 1.1.35
[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--1999 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       Direction dir = 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
81       // staff ref'd?
82       Real internote_f = paper_l ()->get_realvar (interline_scm_sym)/2.0;
83       int sep_i = 3 + size_i / 2;
84       for (int i = 0; i < ncol_l_arr_.size(); i++) 
85         {
86           // how to know whether to sort?
87           ncol_l_arr_[i]->sort();
88           for (int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
89             {
90               int stem = (int)((ncol_l_arr_[i]->stem_l_->extent
91                                (Y_AXIS)[dir]) / internote_f);
92               minpos = minpos >? (dir * stem + sep_i);
93             }
94         }
95       rest_l_arr_[0]->translate_rests (dir * minpos);   
96     }
97 }
98
99 void
100 Rest_collision::do_print() const
101 {
102 #ifndef NPRINT
103   DOUT << "rests: " << rest_l_arr_.size() << ", ";
104   DOUT << "cols: " << ncol_l_arr_.size();
105 #endif
106 }
107
108 void
109 Rest_collision::do_substitute_element_pointer (Score_element*o,Score_element*n)
110 {
111   if (Note_column *onl = dynamic_cast<Note_column *> (o))
112     {
113       Note_column *n_l = n?dynamic_cast<Note_column *> (n):0;
114       rest_l_arr_.substitute (onl, n_l);
115       ncol_l_arr_.substitute (onl, n_l);
116     }
117 }
118
119 Rest_collision::Rest_collision()
120 {
121   set_elt_property (transparent_scm_sym, SCM_BOOL_T);
122   set_empty (true);
123 }