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