lilypond-1.1.67
[lilypond.git] / lily / dot-column.cc
blobd510fba7f46850ae6151e2332455b0019c72b557
1 /*
2 dot-column.cc -- implement Dot_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "dots.hh"
10 #include "dot-column.hh"
11 #include "rhythmic-head.hh"
13 void
14 Dot_column::add_dots (Dots *d)
16 dot_l_arr_.push (d);
17 add_dependency (d);
18 add_element (d);
21 void
22 Dot_column::add_head (Rhythmic_head *r)
24 if (!r->dots_l_)
25 return ;
27 add_support (r);
28 add_dots (r->dots_l_);
31 void
32 Dot_column::do_substitute_element_pointer (Score_element*o,Score_element*n)
34 Note_head_side::do_substitute_element_pointer (o,n);
35 if (Dots * d = dynamic_cast<Dots*> (o))
36 dot_l_arr_.substitute (d, dynamic_cast<Dots*> (n));
39 int
40 Dot_column::compare (Dots * const &d1, Dots * const &d2)
42 return d1->position_i_ - d2->position_i_;
45 void
46 Dot_column::do_pre_processing ()
48 dot_l_arr_.sort (Dot_column::compare);
49 Note_head_side::do_pre_processing ();
52 Dot_column::Dot_column ()
54 notehead_align_dir_ = RIGHT;
55 set_axes(X_AXIS,X_AXIS);
59 Will fuck up in this case.
61 X. .
62 X.X .
63 |X .
66 |X .
71 Should be smarter.
73 void
74 Dot_column::do_post_processing ()
76 if (dot_l_arr_.size () < 2)
77 return;
78 Slice s;
79 s.set_empty ();
81 Array<int> taken_posns;
82 int conflicts = 0;
83 for (int i=0; i < dot_l_arr_.size (); i++)
85 for (int j=0; j < taken_posns.size (); j++)
86 if (taken_posns[j] == dot_l_arr_[i]->position_i_)
87 conflicts++;
88 taken_posns.push (dot_l_arr_[i]->position_i_);
89 s.unite (Slice (dot_l_arr_[i]->position_i_,dot_l_arr_[i]->position_i_));
92 if (!conflicts)
93 return;
95 int middle = s.center ();
97 +1 -> off by one
99 int pos = middle - dot_l_arr_.size () + 1;
100 if (!(pos % 2))
101 pos ++; // center () rounds down.
103 for (int i=0; i <dot_l_arr_.size (); pos += 2, i++)
105 dot_l_arr_[i]->position_i_ = pos;