]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-priority-engraver.cc
0ed5caee1d0435859f5467f6ecdaf638d990cfb2
[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   halign_p_ = 0;
20 }
21
22 void
23 Score_priority_engraver::do_pre_move_processing()
24 {
25   for (int i=0; i < column_p_arr_.size ();i++)
26     typeset_element (column_p_arr_[i]);
27   column_p_arr_.clear ();
28
29   if (halign_p_)
30     {
31       typeset_element (halign_p_);
32       halign_p_ =0;
33     }
34   
35 }
36
37 void
38 Score_priority_engraver::add_horizontal_group (Item* it, int priority)
39 {
40   if (!halign_p_)
41     {
42       halign_p_ = new Break_align_item;
43       halign_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T);
44       announce_element (Score_element_info (halign_p_,0));
45     }
46
47   if (priority == 0)
48     halign_p_->center_l_ = it;
49
50   halign_p_->add_item (it, priority);
51
52   column_p_arr_.push (it);
53 }
54
55 void
56 Score_priority_engraver::acknowledge_element (Score_element_info inf)
57 {
58   if (Item * item_l = dynamic_cast <Item *> (inf.elem_l_))
59     {
60       Dimension_cache * c = &item_l->dim_cache_[X_AXIS];
61       if (c->empty_b () || c->parent_l_)
62         return;
63
64       SCM pr = item_l->remove_elt_property (break_priority_scm_sym); 
65
66       if (pr == SCM_BOOL_F)
67         return;
68
69       bool breakable = (item_l->remove_elt_property (breakable_scm_sym) != SCM_BOOL_F);
70       if (!breakable)
71         return ;
72       
73       int priority = SCM_CDR (pr);
74       /*
75         Don't try to eat up our (probable) parent.
76       */
77       if (inf.origin_grav_l_arr_.size () <= 1 &&
78           dynamic_cast<Break_align_item *> (item_l))
79         return; 
80
81       
82       Score_element * column_l = 0;
83       if (halign_p_)
84         column_l = halign_p_->get_elt_by_priority (priority);
85       Horizontal_group_item * hg;
86       if (column_l)
87         {
88           hg = dynamic_cast<Horizontal_group_item*> (column_l);
89         }
90       else
91         {
92           hg = new Horizontal_group_item;
93           announce_element (Score_element_info (hg,0));
94           add_horizontal_group (hg, priority);
95           hg->set_elt_property (breakable_scm_sym, SCM_BOOL_T);
96         }
97       
98
99       hg->add_element (item_l);
100     }
101 }
102
103 ADD_THIS_TRANSLATOR(Score_priority_engraver);