]> git.donarmstrong.com Git - lilypond.git/blob - lily/a2-engraver.cc
patch::: 1.3.108.jcn3
[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   void deprecated_process_music ();
26   virtual void acknowledge_element (Score_element_info);
27
28   virtual void process_acknowledged ();
29   virtual void do_pre_move_processing ();
30
31 private:
32   Item* text_p_;
33   enum State { SOLO, SPLIT_INTERVAL, UNIRHYTHM, UNISILENCE, UNISON } state_;
34 };
35
36 ADD_THIS_TRANSLATOR (A2_engraver);
37
38 A2_engraver::A2_engraver ()
39 {
40   text_p_ = 0;
41   state_ = UNISILENCE;
42 }
43
44
45 void
46 A2_engraver::deprecated_process_music ()
47 {
48   if (!to_boolean (get_property ("combineParts")))
49     return ;
50   if (!text_p_)
51     {
52       SCM unison = get_property ("unison");
53       SCM solo = get_property ("solo");
54       SCM solo_adue = get_property ("soloADue");
55
56       if (solo_adue == SCM_BOOL_T
57           && ((solo == SCM_BOOL_T && state_ != SOLO)
58               || (unison == SCM_BOOL_T && state_ != UNISON
59                   && daddy_trans_l_->id_str_ == "one")))
60         {
61           text_p_ = new Item (get_property ("TextScript"));
62           Side_position::set_axis (text_p_, Y_AXIS);
63           announce_element (text_p_, 0);
64       
65           Direction dir = UP;
66           SCM text;
67           if (solo == SCM_BOOL_T)
68             {
69               state_ = SOLO;
70               if (daddy_trans_l_->id_str_ == "one")
71                 {
72                   text = get_property ("soloText");
73                 }
74               else
75                 {
76                   text = get_property ("soloIIText");
77                   dir = DOWN;
78                 }
79             }
80           else if (unison == SCM_BOOL_T)
81             {
82               state_ = UNISON;
83               if (daddy_trans_l_->id_str_ == "one")
84                 text = get_property ("aDueText");
85             }
86           
87           Side_position::set_direction (text_p_, dir);
88           text_p_->set_elt_property ("text", text);
89         }
90     }
91 }
92
93 void
94 A2_engraver::acknowledge_element (Score_element_info i)
95 {
96   if (!to_boolean (get_property ("combineParts")))
97     return ;
98   
99   if (text_p_)
100     {
101       if (Note_head::has_interface (i.elem_l_))
102         {
103           Score_element*t = text_p_;
104           Side_position::add_support (t, i.elem_l_);
105           if (Side_position::get_axis (t) == X_AXIS
106               && !t->parent_l (Y_AXIS))
107             t->set_parent (i.elem_l_, Y_AXIS);
108         }
109       if (Stem::has_interface (i.elem_l_))
110         {
111           Side_position::add_support (text_p_, i.elem_l_);
112         }
113     }
114           
115   SCM unisilence = get_property ("unisilence");
116   SCM unison = get_property ("unison");
117   SCM unirhythm = get_property ("unirhythm");
118   SCM solo = get_property ("solo");
119   SCM split_interval = get_property ("split-interval");
120   SCM solo_adue = get_property ("soloADue");
121   
122   State previous_state = state_;
123   if (unisilence == SCM_BOOL_T)
124     /*
125       state_ = UNISILENCE;
126     */
127     ;
128   else if (solo == SCM_BOOL_T)
129     state_ = SOLO;
130   else if (unison == SCM_BOOL_T)
131     state_ = UNISON;
132   else if (unirhythm == SCM_BOOL_T && split_interval == SCM_BOOL_T)
133     state_ = SPLIT_INTERVAL;
134   else if (unirhythm)
135     state_ = UNIRHYTHM;
136           
137   if (Stem::has_interface (i.elem_l_)
138       || Slur::has_interface (i.elem_l_)
139       // || Text_item::has_interface (i.elem_l_)
140       //|| Hairpin::has_interface (i.elem_l_)
141       )
142     {
143       /*
144         Hmm.  We must set dir when solo, in order to get
145         the rests collided to the right position
146       */
147       if ((unirhythm != SCM_BOOL_T) || (solo == SCM_BOOL_T)
148           || ((unisilence == SCM_BOOL_T && previous_state != UNISON))
149           || (unirhythm == SCM_BOOL_T && split_interval == SCM_BOOL_T
150               && (unison != SCM_BOOL_T || solo_adue != SCM_BOOL_T)))
151         {
152           if (daddy_trans_l_->id_str_ == "one")
153             {
154               i.elem_l_->set_elt_property ("direction", gh_int2scm (1));
155             }
156           else if (daddy_trans_l_->id_str_ == "two")
157             {
158               i.elem_l_->set_elt_property ("direction", gh_int2scm (-1));
159             }
160         }
161     }
162 }
163
164 void
165 A2_engraver::process_acknowledged ()
166 {
167   deprecated_process_music ();
168 }
169
170 void 
171 A2_engraver::do_pre_move_processing ()
172 {
173   if (text_p_)
174     {
175       Side_position::add_staff_support (text_p_);
176       typeset_element (text_p_);
177       text_p_ = 0;
178     }
179 }
180