X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdot-column.cc;h=a9838ae13b25609a68a41bbdde03ab62c0443896;hb=46bfe1acbea4a8c22817d6d650734ff92029c22e;hp=97afd43bf25f747d247ff003a26598cc76e40616;hpb=615a9212789c2cb2994748c023d0e19f3a83a0fd;p=lilypond.git diff --git a/lily/dot-column.cc b/lily/dot-column.cc index 97afd43bf2..a9838ae13b 100644 --- a/lily/dot-column.cc +++ b/lily/dot-column.cc @@ -3,54 +3,132 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1998 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ #include "dots.hh" #include "dot-column.hh" #include "rhythmic-head.hh" +#include "group-interface.hh" +#include "staff-symbol-referencer.hh" +#include "directional-element-interface.hh" +#include "side-position-interface.hh" +#include "axis-group-interface.hh" + + + + void -Dot_column::add_dots (Dots *d) +Dot_column::set_interface (Score_element* me) { - dot_l_arr_.push (d); - add_dependency (d); - add_element (d); + + Directional_element_interface::set (me, RIGHT); + + Axis_group_interface::set_interface (me); + Axis_group_interface::set_axes (me, X_AXIS,X_AXIS); } -void -Dot_column::add_head (Rhythmic_head *r) +/* + Will fuck up in this case. + + X. . + X.X . + |X . + | + | + |X . + | + | + + + Should be smarter. + */ + + +MAKE_SCHEME_CALLBACK(Dot_column,force_shift_callback,2); +SCM +Dot_column::force_shift_callback (SCM element_smob, SCM axis) { - if (!r->dots_l_) - return ; - - head_l_arr_.push (r); - add_dependency (r); - add_dots (r->dots_l_); + Score_element *me = unsmob_element (element_smob); + Axis a = (Axis) gh_scm2int (axis); + assert (a == Y_AXIS); + me = me->parent_l (X_AXIS); + SCM dots = me->get_elt_property ("dots"); + do_shifts (dots); + return gh_double2scm (0.0); } -void -Dot_column::do_substitute_dependency (Score_element*o,Score_element*n) +SCM +Dot_column::do_shifts (SCM l) { - Item *oi =dynamic_cast (o); + Link_array dots; + while (gh_pair_p (l)) + { + dots.push (unsmob_element (gh_car (l))); + l = gh_cdr (l); + } + + dots.sort (compare_position); - if (oi && dynamic_cast (oi)) - head_l_arr_.substitute (dynamic_cast (oi), - dynamic_cast(n)); - else if (oi && dynamic_cast (oi)) - dot_l_arr_.substitute (dynamic_cast (oi), - dynamic_cast (n)); + if (dots.size () < 2) + return SCM_UNSPECIFIED; + Slice s; + s.set_empty (); + + Array taken_posns; + int conflicts = 0; + for (int i=0; i < dots.size (); i++) + { + Real p = Staff_symbol_referencer::position_f (dots[i]); + for (int j=0; j < taken_posns.size (); j++) + { + if (taken_posns[j] == (int) p) + conflicts++; + } + taken_posns.push ((int)p); + s.unite (Slice ((int)p, + (int)p)); + } + + if (!conflicts) + return SCM_UNSPECIFIED; + + int middle = s.center (); + /* + +1 -> off by one + */ + int pos = middle - dots.size () + 1; + if (!(pos % 2)) + pos ++; // center () rounds down. + + for (int i=0; i < dots.size (); pos += 2, i++) + { + Score_element * d = dots[i]; + Staff_symbol_referencer::set_position (d,pos); + } + + return SCM_UNSPECIFIED; } -void -Dot_column::do_pre_processing () +bool +Dot_column::has_interface (Score_element*m) { - Interval w; - for (int i=0; i < head_l_arr_.size (); i++) - w.unite (head_l_arr_[i]->width ()); - - if (!w.empty_b ()) - translate_axis (w[RIGHT] - width() [LEFT],X_AXIS); + return m && m->has_interface (ly_symbol2scm ("dot-column-interface")); } +void +Dot_column::add_head (Score_element * me, Score_element *rh) +{ + Score_element * d = unsmob_element (rh->get_elt_property ("dot")); + if (d) + { + Side_position::add_support (me,rh); + + Pointer_group_interface ::add_element (me, "dots",d); + d->add_offset_callback (Dot_column::force_shift_callback_proc , Y_AXIS); + Axis_group_interface::add_element (me, d); + } +} +