]> git.donarmstrong.com Git - lilypond.git/blob - lily/dot-column.cc
patch::: 1.3.8.uu1
[lilypond.git] / lily / dot-column.cc
1 /*
2   dot-column.cc -- implement Dot_column
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 "dots.hh"
10 #include "dot-column.hh"
11 #include "rhythmic-head.hh"
12
13 void
14 Dot_column::add_dots (Dots *d)
15 {
16   dot_l_arr_.push (d);
17   add_dependency (d);
18   add_element (d);
19 }
20
21 void
22 Dot_column::add_head (Rhythmic_head *r)
23 {
24   if (!r->dots_l_)
25     return ;
26
27   add_support (r);
28   add_dots (r->dots_l_);
29 }
30
31 void
32 Dot_column::do_substitute_element_pointer (Score_element*o,Score_element*n)
33 {
34   Note_head_side::do_substitute_element_pointer (o,n);
35   if (Dots * d = dynamic_cast<Dots*> (o))
36     dot_l_arr_.substitute (d, dynamic_cast<Dots*> (n));
37 }
38
39 int
40 Dot_column::compare (Dots * const &d1, Dots * const &d2)
41 {
42   return int (d1->position_f () - d2->position_f ());
43 }
44
45 void
46 Dot_column::do_pre_processing ()
47 {
48   dot_l_arr_.sort (Dot_column::compare);
49   Note_head_side::do_pre_processing ();
50 }
51
52 Dot_column::Dot_column ()
53 {
54   set_direction (RIGHT);
55   set_axes(X_AXIS,X_AXIS);
56 }
57
58 /*
59   Will fuck up in this case.
60
61   X.  .
62   X.X .
63    |X .
64    |
65    |
66    |X .
67    |
68    |
69
70
71    Should be smarter.
72  */
73 void
74 Dot_column::do_post_processing ()
75 {
76   if (dot_l_arr_.size () < 2)
77     return;
78   Slice s;
79   s.set_empty ();
80
81   Array<int> taken_posns;
82   int conflicts = 0;
83   for (int i=0; i < dot_l_arr_.size (); i++)
84     {
85       for (int j=0; j < taken_posns.size (); j++)
86         if (taken_posns[j] == (int) dot_l_arr_[i]->position_f ())
87           conflicts++;
88       taken_posns.push ((int)dot_l_arr_[i]->position_f ());
89       s.unite (Slice ((int)dot_l_arr_[i]->position_f (),
90                       (int)dot_l_arr_[i]->position_f ()));      
91     }
92
93   if (!conflicts)
94     return;
95   
96   int  middle = s.center ();
97   /*
98     +1 -> off by one 
99    */
100   int pos = middle - dot_l_arr_.size () + 1;
101   if (!(pos % 2))
102     pos ++;                     // center () rounds down.
103
104   for (int i=0; i  <dot_l_arr_.size (); pos += 2, i++)
105     {
106       dot_l_arr_[i]->set_position(pos);
107     }
108 }