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