]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-priority-engraver.cc
release: 1.1.37
[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 "axis-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_element_priority (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 = gh_scm2int (SCM_CDR (pr));
74       
75       Score_element * column_l = 0;
76       if (halign_p_)
77         column_l = halign_p_->get_elt_by_priority (priority);
78       Axis_group_item * hg=0;
79       if (column_l)
80         {
81           hg = dynamic_cast<Axis_group_item*> (column_l);
82         }
83       else
84         {
85           hg = new Axis_group_item;
86           hg->set_axes (X_AXIS,X_AXIS);
87           hg->set_elt_property (ly_symbol("origin"),
88                                 SCM_EOL);
89           announce_element (Score_element_info (hg,0));
90           add_horizontal_group (hg, priority);
91         }
92       
93       hg->set_elt_property (ly_symbol("origin"),
94                             scm_cons (gh_str02scm (item_l->name()),
95                                       hg->get_elt_property (ly_symbol ("origin"))));
96       hg->add_element (item_l);
97       
98     }
99 }
100
101 ADD_THIS_TRANSLATOR(Score_priority_engraver);