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