*** empty log message ***
[lilypond.git] / lily / dot-column.cc
blob736588a0e05282ba687abe2a9ba14682d8bce838
1 /*
2 dot-column.cc -- implement Dot_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 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"
20 TODO: let Dot_column communicate with stem via Note_column.
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->get_parent (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::get_beam (stem)
47 && Stem::duration_log (stem) > 2
48 && !Stem::invisible_b (stem)
52 trigger stem end & direction calculation.
54 This will add the stem to the support if a flag collision happens.
56 Stem::stem_end_position (stem);
58 return Side_position_interface::aligned_side (element_smob, axis);
63 Will fuck up in this case.
65 X. .
66 X.X .
67 |X .
70 |X .
75 Should be smarter.
77 SCM
78 Dot_column::do_shifts (SCM l)
80 Link_array<Grob> dots;
81 while (gh_pair_p (l))
83 dots.push (unsmob_grob (ly_car (l)));
84 l = ly_cdr (l);
87 dots.sort (compare_position);
89 if (dots.size () < 2)
90 return SCM_UNSPECIFIED;
91 Slice s;
92 s.set_empty ();
94 Array<int> taken_posns;
95 int conflicts = 0;
96 for (int i=0; i < dots.size (); i++)
98 Real p = Staff_symbol_referencer::get_position (dots[i]);
99 for (int j=0; j < taken_posns.size (); j++)
101 if (taken_posns[j] == (int) p)
102 conflicts++;
104 taken_posns.push ((int)p);
105 s.unite (Slice ((int)p,
106 (int)p));
109 if (!conflicts)
110 return SCM_UNSPECIFIED;
112 int middle = s.center ();
114 +1 -> off by one
116 int pos = middle - dots.size () + 1;
117 if (! (pos % 2))
118 pos ++; // center () rounds down.
120 for (int i=0; i < dots.size (); pos += 2, i++)
122 Grob * d = dots[i];
123 Staff_symbol_referencer::set_position (d,pos);
126 return SCM_UNSPECIFIED;
131 void
132 Dot_column::add_head (Grob * me, Grob *rh)
134 Grob * d = unsmob_grob (rh->get_grob_property ("dot"));
135 if (d)
137 Side_position_interface::add_support (me,rh);
139 Pointer_group_interface::add_grob (me, ly_symbol2scm ("dots"), d);
140 d->add_offset_callback (Dot_column::force_shift_callback_proc , Y_AXIS);
141 Axis_group_interface::add_element (me, d);
148 ADD_INTERFACE (Dot_column, "dot-column-interface",
149 "Interface that groups dots so they form a column",
150 "direction stem");