lilypond-1.5.1
[lilypond.git] / lily / dot-column.cc
blob4ae84934f63b51338980c4c3ce73846d1151fd66
1 /*
2 dot-column.cc -- implement Dot_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 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"
17 #include "stem.hh"
19 void
20 Dot_column::set_interface (Grob* me)
23 MAKE_SCHEME_CALLBACK (Dot_column,force_shift_callback,2);
24 SCM
25 Dot_column::force_shift_callback (SCM element_smob, SCM axis)
27 Grob *me = unsmob_grob (element_smob);
28 Axis a = (Axis) gh_scm2int (axis);
29 assert (a == Y_AXIS);
30 me = me->parent_l (X_AXIS);
31 SCM l = me->get_grob_property ("dots");
32 do_shifts (l);
33 return gh_double2scm (0.0);
36 MAKE_SCHEME_CALLBACK(Dot_column,side_position, 2);
37 SCM
38 Dot_column::side_position (SCM element_smob, SCM axis)
40 Grob *me = unsmob_grob (element_smob);
41 Axis a = (Axis) gh_scm2int (axis);
42 assert (a == X_AXIS);
44 Grob * stem = unsmob_grob (me->get_grob_property ("stem"));
45 if (stem
46 && !Stem::beam_l (stem)
47 && Stem::flag_i (stem))
50 trigger stem end & direction calculation.
52 This will add the stem to the support if a flag collision happens.
54 Stem::stem_end_position (stem);
56 return Side_position_interface::aligned_side (element_smob, axis);
61 Will fuck up in this case.
63 X. .
64 X.X .
65 |X .
68 |X .
73 Should be smarter.
75 SCM
76 Dot_column::do_shifts (SCM l)
78 Link_array<Grob> dots;
79 while (gh_pair_p (l))
81 dots.push (unsmob_grob (gh_car (l)));
82 l = gh_cdr (l);
85 dots.sort (compare_position);
87 if (dots.size () < 2)
88 return SCM_UNSPECIFIED;
89 Slice s;
90 s.set_empty ();
92 Array<int> taken_posns;
93 int conflicts = 0;
94 for (int i=0; i < dots.size (); i++)
96 Real p = Staff_symbol_referencer::position_f (dots[i]);
97 for (int j=0; j < taken_posns.size (); j++)
99 if (taken_posns[j] == (int) p)
100 conflicts++;
102 taken_posns.push ((int)p);
103 s.unite (Slice ((int)p,
104 (int)p));
107 if (!conflicts)
108 return SCM_UNSPECIFIED;
110 int middle = s.center ();
112 +1 -> off by one
114 int pos = middle - dots.size () + 1;
115 if (! (pos % 2))
116 pos ++; // center () rounds down.
118 for (int i=0; i < dots.size (); pos += 2, i++)
120 Grob * d = dots[i];
121 Staff_symbol_referencer::set_position (d,pos);
124 return SCM_UNSPECIFIED;
127 bool
128 Dot_column::has_interface (Grob*m)
130 return m && m->has_interface (ly_symbol2scm ("dot-column-interface"));
134 void
135 Dot_column::add_head (Grob * me, Grob *rh)
137 Grob * d = unsmob_grob (rh->get_grob_property ("dot"));
138 if (d)
140 Side_position_interface::add_support (me,rh);
142 Pointer_group_interface ::add_element (me, "dots",d);
143 d->add_offset_callback (Dot_column::force_shift_callback_proc , Y_AXIS);
144 Axis_group_interface::add_element (me, d);