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