lilypond-1.3.12
[lilypond.git] / lily / break-align-engraver.cc
blobf735fe9e8c65eb52eb3151e646040c086002e06f
1 /*
2 break-align-engraver.cc -- implement Break_align_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "engraver.hh"
10 #include "protected-scm.hh"
11 #include "break-align-item.hh"
12 #include "axis-group-item.hh"
14 class Break_align_engraver : public Engraver
16 Break_align_item *align_l_;
17 Protected_scm column_alist_;
18 protected:
19 virtual void acknowledge_element(Score_element_info i);
20 virtual void do_pre_move_processing ();
21 void add_column (SCM);
23 public:
24 VIRTUAL_COPY_CONS(Translator);
25 Break_align_engraver ();
30 ADD_THIS_TRANSLATOR(Break_align_engraver);
32 void
33 Break_align_engraver::add_column (SCM smob)
35 Score_element * e = unsmob_element (smob);
36 align_l_->add_element (e);
37 typeset_element (e);
40 void
41 Break_align_engraver::do_pre_move_processing ()
43 SCM order = get_property ("breakAlignOrder", 0);
44 for (; gh_pair_p (order); order = gh_cdr (order))
46 SCM p = scm_assoc ( gh_car (order), column_alist_);
47 if (gh_pair_p (p))
49 add_column (gh_cdr (p));
50 column_alist_ = scm_assoc_remove_x (column_alist_, gh_car (order));
54 for (SCM p = column_alist_; gh_pair_p (p); p = gh_cdr (p))
56 SCM pair = gh_car (p);
57 add_column (gh_cdr (pair));
61 column_alist_ = SCM_EOL;
63 if (align_l_)
65 typeset_element (align_l_);
66 align_l_ = 0;
71 Break_align_engraver::Break_align_engraver ()
73 column_alist_ = SCM_EOL;
74 align_l_ =0;
77 void
78 Break_align_engraver::acknowledge_element (Score_element_info inf)
80 if (Item * item_l = dynamic_cast <Item *> (inf.elem_l_))
82 if (item_l->empty_b (X_AXIS) || item_l->parent_l (X_AXIS))
83 return;
85 SCM bp=item_l->remove_elt_property ("breakable");
86 bool breakable = (gh_boolean_p (bp) && gh_scm2bool (bp));
87 if (!breakable)
88 return ;
90 SCM al = item_l->remove_elt_property ("break-aligned");
91 if (!gh_boolean_p (al ) || !gh_scm2bool (al))
92 return ;
95 if (!align_l_)
97 align_l_ = new Break_align_item;
98 align_l_->set_elt_property ("breakable", SCM_BOOL_T);
99 announce_element (Score_element_info (align_l_,0));
102 SCM name = ly_str02scm (inf.elem_l_->name());
103 SCM s = scm_assoc (name, column_alist_);
105 Axis_group_item * group = 0;
106 if (s != SCM_BOOL_F)
108 Score_element *e = unsmob_element (gh_cdr(s));
109 group = dynamic_cast<Axis_group_item*> (e);
111 else
113 group = new Axis_group_item;
114 group->set_axes (X_AXIS,X_AXIS);
115 group->set_elt_property ("origin", name);
116 group->set_parent (align_l_, Y_AXIS);
117 announce_element (Score_element_info (group, 0));
118 column_alist_ = scm_assoc_set_x (column_alist_, name, group->self_scm_);
120 group->add_element (item_l);