]> git.donarmstrong.com Git - lilypond.git/blob - lily/vertical-align-engraver.cc
release: 1.3.73
[lilypond.git] / lily / vertical-align-engraver.cc
1 /*
2   vertical-align-grav.cc -- implement Vertical_align_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "translator-group.hh"
9 #include "paper-column.hh"
10 #include "align-interface.hh"
11 #include "span-bar.hh"
12 #include "axis-group-interface.hh"
13 #include "engraver.hh"
14 #include "spanner.hh"
15
16 class Vertical_align_engraver : public Engraver
17 {
18   Spanner * valign_p_;
19   bool qualifies_b (Score_element_info) const;  
20 public:
21   VIRTUAL_COPY_CONS(Translator);
22   Vertical_align_engraver();
23 protected:
24   virtual void acknowledge_element (Score_element_info);
25   virtual void do_creation_processing();
26   virtual void do_removal_processing();
27 };
28
29 Vertical_align_engraver::Vertical_align_engraver()
30 {
31   valign_p_ =0;
32 }
33
34 void
35 Vertical_align_engraver::do_creation_processing()
36 {
37   valign_p_ =new Spanner (SCM_EOL); // todo -> basic props
38   Align_interface::set_interface (valign_p_);
39   Align_interface::set_axis (valign_p_,Y_AXIS);
40   valign_p_->set_elt_property ("stacking-dir",
41                                gh_int2scm (DOWN));
42   
43   valign_p_->set_bound(LEFT,unsmob_element (get_property ("currentCommandColumn")));
44   announce_element (valign_p_ , 0);
45 }
46
47 void
48 Vertical_align_engraver::do_removal_processing()
49 {
50   SCM min = get_property ("maxVerticalAlign");
51   SCM max = get_property ("minVerticalAlign");
52
53   if (gh_number_p (min) || gh_number_p (max))
54     {
55       min = gh_number_p (min) ? min : gh_double2scm (0.0);
56       max = gh_number_p (max) ? max : gh_double2scm (infinity_f);    
57     
58       valign_p_->set_elt_property ("threshold",
59                                    gh_cons (min,max));
60     }
61   valign_p_->set_bound(RIGHT,unsmob_element (get_property ("currentCommandColumn")));
62   typeset_element (valign_p_);
63   valign_p_ =0;
64 }
65
66
67 bool
68 Vertical_align_engraver::qualifies_b (Score_element_info i) const
69 {
70   int sz = i.origin_trans_l_arr ((Translator*)this).size()  ;
71
72   return sz > 1 && Axis_group_interface::has_interface (i.elem_l_)
73     && !i.elem_l_->parent_l (Y_AXIS) && Axis_group_interface::axis_b (i.elem_l_, Y_AXIS);
74 }
75
76 void
77 Vertical_align_engraver::acknowledge_element (Score_element_info i)
78 {
79   if (qualifies_b (i))
80     {
81       Align_interface::add_element (valign_p_,i.elem_l_);
82     }
83 }
84
85 ADD_THIS_TRANSLATOR(Vertical_align_engraver);