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