lilypond-1.3.69
[lilypond.git] / lily / dot-column.cc
blob556928f7daf9d8a85f51d4efd9013f7cf0009ef2
1 /*
2 dot-column.cc -- implement Dot_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
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"
20 void
21 Dot_column::add_head (Score_element * me, Score_element *rh)
23 Score_element * d = unsmob_element (rh->get_elt_property ("dot"));
24 if (d)
26 Side_position::add_support (me,rh);
28 Pointer_group_interface gi (me, "dots");
29 gi.add_element (d);
31 d->add_offset_callback (force_shift_callback , Y_AXIS);
32 Axis_group_interface::add_element (me, d);
39 void
40 Dot_column::set_interface (Score_element* me)
42 me->set_elt_property ("dots", SCM_EOL);
43 Directional_element_interface (me).set (RIGHT);
45 Axis_group_interface::set_interface (me);
46 Axis_group_interface::set_axes (me, X_AXIS,X_AXIS);
50 Will fuck up in this case.
52 X. .
53 X.X .
54 |X .
57 |X .
62 Should be smarter.
66 Real
67 Dot_column::force_shift_callback (Score_element * dot, Axis a)
69 assert (a == Y_AXIS);
70 Score_element * me = dot->parent_l (X_AXIS);
71 SCM dots = me->get_elt_property ("dots");
72 do_shifts (dots);
73 return 0.0;
76 SCM
77 Dot_column::do_shifts (SCM l)
79 Link_array<Score_element> dots;
80 while (gh_pair_p (l))
82 dots.push (unsmob_element (gh_car (l)));
83 l = gh_cdr (l);
86 dots.sort (compare_position);
88 if (dots.size () < 2)
89 return SCM_UNDEFINED;
90 Slice s;
91 s.set_empty ();
93 Array<int> taken_posns;
94 int conflicts = 0;
95 for (int i=0; i < dots.size (); i++)
97 Real p = Staff_symbol_referencer::position_f (dots[i]);
98 for (int j=0; j < taken_posns.size (); j++)
100 if (taken_posns[j] == (int) p)
101 conflicts++;
103 taken_posns.push ((int)p);
104 s.unite (Slice ((int)p,
105 (int)p));
108 if (!conflicts)
109 return SCM_UNDEFINED;
111 int middle = s.center ();
113 +1 -> off by one
115 int pos = middle - dots.size () + 1;
116 if (!(pos % 2))
117 pos ++; // center () rounds down.
119 for (int i=0; i < dots.size (); pos += 2, i++)
121 Score_element * d = dots[i];
122 Staff_symbol_referencer::set_position (d,pos);
125 return SCM_UNDEFINED;
128 bool
129 Dot_column::has_interface (Score_element*m)
131 return m && m->has_interface (ly_symbol2scm ("dot-column-interface"));