]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-priority-engraver.cc
release: 1.1.29
[lilypond.git] / lily / score-priority-engraver.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--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #include "horizontal-group-item.hh"
11 #include "score-priority-engraver.hh"
12 #include "item.hh"
13 #include "dictionary-iter.hh"
14 #include "break-align-item.hh"
15
16
17 Score_priority_engraver::Score_priority_engraver()
18 {
19   align_p_tab_.hash_func_ = int_hash;
20 }
21
22 void
23 Score_priority_engraver::do_pre_move_processing()
24 {
25   for (Hash_table_iter<int, Horizontal_group_item*> i(align_p_tab_);
26        i.ok() ; i++)
27     {
28       if (i.val ())
29         {
30           typeset_element (i.val ());
31           i.val_ref () = 0;
32         }
33     }
34   align_p_tab_.clear ();
35 }
36
37 void
38 Score_priority_engraver::acknowledge_element (Score_element_info inf)
39 {
40   Item * item_l = dynamic_cast <Item *> (inf.elem_l_);
41   if (item_l && item_l->breakable_b_ && !item_l->empty_b ())
42     {
43       /*
44         Don't try to eat up our (probable) parent.
45       */
46       if (inf.origin_grav_l_arr_.size () <= 1 &&
47           dynamic_cast<Break_align_item *> (item_l))
48         return; 
49
50       
51       int priority =item_l->break_priority_i_;
52       Horizontal_group_item * hg =0;
53       if (!align_p_tab_.elem_b(priority))
54         {
55           hg = new Horizontal_group_item;
56           announce_element (Score_element_info (hg,0));
57           align_p_tab_[priority] = hg;
58           hg->break_priority_i_ = priority;
59           hg->breakable_b_ = true;
60         }
61       else
62         hg = align_p_tab_[priority];
63       
64       Score_element * unbound_elem = inf.elem_l_;
65
66       /*
67         ugh
68        */
69       while (unbound_elem->parent_l (X_AXIS))
70         {
71           /* We might have added inf.elem_l_ earlier because we added one
72              of its children.  We don't want to add ourselves to ourself
73           */
74           Graphical_element * e = unbound_elem->parent_l (X_AXIS);
75           if (e == hg)
76             return;
77           unbound_elem = dynamic_cast<Score_element*> (e);
78         }
79
80       hg->add_element (unbound_elem);
81     }
82 }
83
84
85 ADD_THIS_TRANSLATOR(Score_priority_engraver);