]> git.donarmstrong.com Git - lilypond.git/blob - lily/dot-column.cc
release: 1.1.58
[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--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "dots.hh"
10 #include "dot-column.hh"
11 #include "rhythmic-head.hh"
12
13 void
14 Dot_column::add_dots (Dots *d)
15 {
16   dot_l_arr_.push (d);
17   add_dependency (d);
18   add_element (d);
19 }
20
21 void
22 Dot_column::add_head (Rhythmic_head *r)
23 {
24   if (!r->dots_l_)
25     return ;
26
27   add_support (r);
28   add_dots (r->dots_l_);
29 }
30
31 void
32 Dot_column::do_substitute_element_pointer (Score_element*o,Score_element*n)
33 {
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));
37 }
38
39 int
40 Dot_column::compare (Dots * const &d1, Dots * const &d2)
41 {
42   return d1->position_i_ - d2->position_i_;
43 }
44
45 void
46 Dot_column::do_pre_processing ()
47 {
48   dot_l_arr_.sort (Dot_column::compare);
49   Note_head_side::do_pre_processing ();
50 }
51
52 Dot_column::Dot_column ()
53 {
54   align_dir_ = RIGHT;
55   set_axes(X_AXIS,X_AXIS);
56 }
57
58 void
59 Dot_column::do_post_processing ()
60 {
61   if (dot_l_arr_.size () < 2)
62     return;
63   Slice s;
64   s.set_empty ();
65   
66   for (int i=0; i < dot_l_arr_.size (); i++)
67     {
68       s.unite (Slice (dot_l_arr_[i]->position_i_,dot_l_arr_[i]->position_i_));      
69     }
70   int  middle = s.center ();
71   /*
72     +1 -> off by one 
73    */
74   int pos = middle - dot_l_arr_.size () + 1;
75   if (!(pos % 2))
76     pos ++;                     // center () rounds down.
77
78   for (int i=0; i  <dot_l_arr_.size (); pos += 2, i++)
79     {
80       dot_l_arr_[i]->position_i_ = pos;
81     }
82 }