]> git.donarmstrong.com Git - lilypond.git/blob - lily/a2-engraver.cc
88d86648c6e2c4ef500cede3e81459e5f13cadb0
[lilypond.git] / lily / a2-engraver.cc
1 /*
2   a2-engraver.cc -- implement A2_engraver
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10 #include "item.hh"
11 #include "note-head.hh"
12 #include "stem.hh"
13 #include "slur.hh"
14 #include "translator-group.hh"
15 #include "side-position-interface.hh"
16 #include "directional-element-interface.hh"
17
18 class A2_engraver : public Engraver
19 {
20 public:
21   A2_engraver ();
22   VIRTUAL_COPY_CONS (Translator);
23   
24 protected:
25   virtual void do_process_music ();
26   virtual void acknowledge_element (Score_element_info);
27
28   virtual void do_pre_move_processing ();
29
30 private:
31   Item* text_p_;
32   enum State { SOLO, SPLIT_INTERVAL, UNIRHYTHM, UNISILENCE, UNISON } state_;
33 };
34
35 ADD_THIS_TRANSLATOR (A2_engraver);
36
37 A2_engraver::A2_engraver ()
38 {
39   text_p_ = 0;
40   state_ = UNISILENCE;
41 }
42
43 void
44 A2_engraver::do_process_music ()
45 {
46   if (!text_p_)
47     {
48       SCM unison = get_property ("unison");
49       SCM solo = get_property ("solo");
50       SCM solo_adue = get_property ("soloADue");
51
52       if (solo_adue == SCM_BOOL_T
53           && ((solo == SCM_BOOL_T && state_ != SOLO)
54               || (unison == SCM_BOOL_T && state_ != UNISON
55                   && daddy_trans_l_->id_str_ == "one")))
56         {
57           text_p_ = new Item (get_property ("basicTextScriptProperties"));
58           Side_position::set_axis (text_p_, Y_AXIS);
59           announce_element (text_p_, 0);
60       
61           Direction dir = UP;
62           SCM text;
63           if (solo == SCM_BOOL_T)
64             {
65               state_ = SOLO;
66               if (daddy_trans_l_->id_str_ == "one")
67                 {
68                   text = get_property ("soloText");
69                 }
70               else
71                 {
72                   text = get_property ("soloIIText");
73                   dir = DOWN;
74                 }
75             }
76           else if (unison == SCM_BOOL_T)
77             {
78               state_ = UNISON;
79               if (daddy_trans_l_->id_str_ == "one")
80                 text = get_property ("aDueText");
81             }
82           
83           Side_position::set_direction (text_p_, dir);
84           text_p_->set_elt_property ("text", text);
85         }
86     }
87 }
88
89 void
90 A2_engraver::acknowledge_element (Score_element_info i)
91 {
92   if (text_p_)
93     {
94       if (Note_head::has_interface (i.elem_l_))
95         {
96           Score_element*t = text_p_;
97           Side_position::add_support (t, i.elem_l_);
98           if (Side_position::get_axis (t) == X_AXIS
99               && !t->parent_l (Y_AXIS))
100             t->set_parent (i.elem_l_, Y_AXIS);
101         }
102       if (Stem::has_interface (i.elem_l_))
103         {
104           Side_position::add_support (text_p_, i.elem_l_);
105         }
106     }
107           
108   SCM unisilence = get_property ("unisilence");
109   SCM unison = get_property ("unison");
110   SCM unirhythm = get_property ("unirhythm");
111   SCM solo = get_property ("solo");
112   SCM split_interval = get_property ("split-interval");
113   SCM solo_adue = get_property ("soloADue");
114   
115   State previous_state = state_;
116   if (unisilence == SCM_BOOL_T)
117     /*
118       state_ = UNISILENCE;
119     */
120     ;
121   else if (solo == SCM_BOOL_T)
122     state_ = SOLO;
123   else if (unison == SCM_BOOL_T)
124     state_ = UNISON;
125   else if (unirhythm == SCM_BOOL_T && split_interval == SCM_BOOL_T)
126     state_ = SPLIT_INTERVAL;
127   else if (unirhythm)
128     state_ = UNIRHYTHM;
129           
130   if (Stem::has_interface (i.elem_l_)
131       || Slur::has_interface (i.elem_l_)
132       // || Text_item::has_interface (i.elem_l_)
133       //|| Crescendo::has_interface (i.elem_l_)
134       )
135     {
136       /*
137         Hmm.  We must set dir when solo, in order to get
138         the rests collided to the right position
139       */
140       if ((unirhythm != SCM_BOOL_T) || (solo == SCM_BOOL_T)
141           || ((unisilence == SCM_BOOL_T && previous_state != UNISON))
142           || (unirhythm == SCM_BOOL_T && split_interval == SCM_BOOL_T
143               && (unison != SCM_BOOL_T || solo_adue != SCM_BOOL_T)))
144         {
145           if (daddy_trans_l_->id_str_ == "one")
146             {
147               i.elem_l_->set_elt_property ("direction", gh_int2scm (1));
148             }
149           else if (daddy_trans_l_->id_str_ == "two")
150             {
151               i.elem_l_->set_elt_property ("direction", gh_int2scm (-1));
152             }
153         }
154     }
155 }
156
157 void 
158 A2_engraver::do_pre_move_processing ()
159 {
160   if (text_p_)
161     {
162       Side_position::add_staff_support (text_p_);
163       typeset_element (text_p_);
164       text_p_ = 0;
165     }
166 }
167