]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-priority-grav.cc
partial: 1.0.1.jcn
[lilypond.git] / lily / score-priority-grav.cc
1 /*
2   score-align-reg.cc -- implement Score_priority_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #include "horizontal-group-item.hh"
11 #include "score-priority-grav.hh"
12 #include "item.hh"
13 #include "assoc-iter.hh"
14 #include "break-align-item.hh"
15
16
17 Score_priority_engraver::Score_priority_engraver()
18 {
19 }
20
21 void
22 Score_priority_engraver::do_pre_move_processing()
23 {
24   for (Assoc_iter<int, Horizontal_group_item*> i(align_p_assoc_); i.ok() ; i++)
25     {
26       if (i.val ())
27         {
28           typeset_element (i.val ());
29           i.val () = 0;
30         }
31     }
32   align_p_assoc_.clear ();
33 }
34
35 void
36 Score_priority_engraver::acknowledge_element (Score_elem_info inf)
37 {
38   Item * item_l = inf.elem_l_->item ();
39   if (item_l && item_l->breakable_b_ && !item_l->empty_b ())
40     {
41       /*
42         Don't try to eat up our (probable) parent.
43       */
44       if (inf.origin_grav_l_arr_.size () <= 1 &&
45           item_l->is_type_b (Break_align_item::static_name ()))
46         return; 
47
48       
49       int priority =item_l->break_priority_i_;
50       Horizontal_group_item * hg =0;
51       if (!align_p_assoc_.elt_b(priority))
52         {
53           hg = new Horizontal_group_item;
54           announce_element (Score_elem_info (hg,0));
55           align_p_assoc_[priority] = hg;
56           hg->break_priority_i_ = priority;
57           hg->breakable_b_ = true;
58         }
59       else
60         hg = align_p_assoc_[priority];
61       
62       Score_elem * unbound_elem = inf.elem_l_;
63
64       while (unbound_elem->axis_group_l_a_[X_AXIS])
65         {
66           /* We might have added inf.elem_l_ earlier because we added one
67              of its children.  We don't want to add ourselves to ourself
68           */
69           if (unbound_elem->axis_group_l_a_[X_AXIS] == hg)
70             return;
71           unbound_elem = unbound_elem->axis_group_l_a_[X_AXIS];
72         }
73
74       hg->add_element (unbound_elem);
75     }
76 }
77
78 IMPLEMENT_IS_TYPE_B1(Score_priority_engraver, Engraver);
79 ADD_THIS_TRANSLATOR(Score_priority_engraver);