]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-priority-grav.cc
1358ec42320cd6a7ec747c44f5564605c78fb685
[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 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_)
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 p =item_l-> break_priority_i_;
50       Horizontal_group_item * hg =0;
51       if (!align_p_assoc_.elt_b(p))
52           {
53             hg = new Horizontal_group_item;
54             announce_element (Score_elem_info (hg,0));
55             align_p_assoc_[p] = hg;
56             hg->break_priority_i_ = p;
57             hg->breakable_b_ = true;
58           }
59       else
60         hg = align_p_assoc_[p];
61       
62       Score_elem * unbound_elem = inf.elem_l_;
63
64       
65       while (unbound_elem->axis_group_l_a_[X_AXIS])
66         {
67           /* We might have added inf.elem_l_ earlier because we added one
68              of its children.  We don't want to add ourselves to ourself
69              */
70           if (unbound_elem->axis_group_l_a_[X_AXIS] == hg)
71             return;
72           unbound_elem = unbound_elem->axis_group_l_a_[X_AXIS];
73         }
74         
75
76       hg->add_element (unbound_elem);
77     }
78 }
79
80 IMPLEMENT_IS_TYPE_B1(Score_priority_engraver, Engraver);
81 ADD_THIS_TRANSLATOR(Score_priority_engraver);