]> git.donarmstrong.com Git - lilypond.git/blob - lily/vertical-align-engraver.cc
release: 1.3.39
[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 "axis-group-engraver.hh"
10 #include "paper-column.hh"
11 #include "align-interface.hh"
12 #include "span-bar.hh"
13 #include "axis-group-interface.hh"
14 #include "engraver.hh"
15 #include "spanner.hh"
16
17 class Vertical_align_engraver : public Engraver {
18   Spanner * valign_p_;
19   bool qualifies_b (Score_element_info) const;  
20 public:
21   VIRTUAL_COPY_CONS(Translator);
22   
23   Vertical_align_engraver();
24 protected:
25   
26   virtual void acknowledge_element (Score_element_info);
27   virtual void do_creation_processing();
28   virtual void do_removal_processing();
29 };
30
31
32 Vertical_align_engraver::Vertical_align_engraver()
33 {
34   valign_p_ =0;
35 }
36
37 void
38 Vertical_align_engraver::do_creation_processing()
39 {
40   valign_p_ =new Spanner; //Axis_align_spanner
41   Align_interface (valign_p_).set_interface ();
42   Align_interface (valign_p_).set_axis (Y_AXIS);
43   valign_p_->set_elt_property ("stacking-dir",
44                                gh_int2scm (DOWN));
45   
46   valign_p_->set_bound(LEFT,get_staff_info().command_pcol_l ());
47   announce_element (Score_element_info (valign_p_ , 0));
48 }
49
50 void
51 Vertical_align_engraver::do_removal_processing()
52 {
53   SCM min = get_property ("maxVerticalAlign");
54   SCM max = get_property ("minVerticalAlign");
55
56   if (gh_number_p (min) || gh_number_p (max))
57   {
58     min = gh_number_p (min) ? min : gh_double2scm (0.0);
59     max = gh_number_p (max) ? max : gh_double2scm (infinity_f);    
60     
61     valign_p_->set_elt_property ("threshold",
62                                  gh_cons (min,max));
63   }
64   valign_p_->set_bound(RIGHT,get_staff_info().command_pcol_l ());
65   typeset_element (valign_p_);
66   valign_p_ =0;
67 }
68
69
70 bool
71 Vertical_align_engraver::qualifies_b (Score_element_info i) const
72 {
73   int sz = i.origin_trans_l_arr ((Translator*)this).size()  ;
74
75
76   Axis_group_interface agi(i.elem_l_);
77
78   return sz > 1 && agi.has_interface_b ()
79     && !i.elem_l_->parent_l (Y_AXIS) && agi.axis_b (Y_AXIS);
80 }
81
82 void
83 Vertical_align_engraver::acknowledge_element (Score_element_info i)
84 {
85   if (qualifies_b (i))
86     {
87       Align_interface(valign_p_).add_element (i.elem_l_);
88     }
89
90 #if 1                           // 
91   /*
92     should junk this, but (crossstaff?) Beam doesn't have a clue yet
93     ...  */
94   
95   /*
96      Add make sure spanbars (whose size depends on vertical alignment)
97      depend on the vertical alignment element
98    */
99   else if (dynamic_cast<Span_bar*>(i.elem_l_) && i.origin_trans_l_arr (this).size ())
100     {
101       i.elem_l_->add_dependency (valign_p_);
102     }
103 #endif
104 }
105
106
107
108 ADD_THIS_TRANSLATOR(Vertical_align_engraver);