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