]> git.donarmstrong.com Git - lilypond.git/blob - lily/a2-engraver.cc
patch::: 1.3.78.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 "translator-group.hh"
14 #include "side-position-interface.hh"
15 #include "directional-element-interface.hh"
16
17 class A2_engraver : public Engraver
18 {
19 public:
20   A2_engraver ();
21   VIRTUAL_COPY_CONS (Translator);
22   
23 protected:
24   virtual void do_process_music ();
25   virtual void acknowledge_element (Score_element_info);
26
27   virtual void do_pre_move_processing ();
28
29 private:
30   Item* text_p_;
31   enum State { NORMAL, SOLO, SPLIT_INTERVAL, UNISON } state_;
32 };
33
34 ADD_THIS_TRANSLATOR (A2_engraver);
35
36 A2_engraver::A2_engraver ()
37 {
38   text_p_ = 0;
39   state_ = NORMAL;
40 }
41
42 void
43 A2_engraver::do_process_music ()
44 {
45   if (!text_p_)
46     {
47       SCM unison = get_property ("unison");
48       SCM unirhythm = get_property ("unirhythm");
49       SCM solo = get_property ("solo");
50       SCM split_interval = get_property ("split-interval");
51       SCM solo_adue = get_property ("soloADue");
52
53       if (solo_adue == SCM_BOOL_T
54           && ((solo == SCM_BOOL_T && state_ != SOLO)
55               || (unison == SCM_BOOL_T && state_ != UNISON
56                   && daddy_trans_l_->id_str_ == "one")))
57         {
58           text_p_ = new Item (get_property ("basicTextScriptProperties"));
59           Side_position::set_axis (text_p_, Y_AXIS);
60           announce_element (text_p_, 0);
61       
62           Direction dir = UP;
63           SCM text;
64           if (solo == SCM_BOOL_T)
65             {
66               state_ = SOLO;
67               if (daddy_trans_l_->id_str_ == "one")
68                 {
69                   text = get_property ("soloText");
70                 }
71               else
72                 {
73                   text = get_property ("soloIIText");
74                   dir = DOWN;
75                 }
76             }
77           else if (unison == SCM_BOOL_T)
78             {
79               state_ = UNISON;
80               if (daddy_trans_l_->id_str_ == "one")
81                 text = get_property ("aDueText");
82             }
83           
84           Side_position::set_direction (text_p_, dir);
85           text_p_->set_elt_property ("text", text);
86         }
87       else if (unison == SCM_BOOL_T)
88         state_ = UNISON;
89       else if (unirhythm == SCM_BOOL_T && split_interval == SCM_BOOL_T)
90         state_ = SPLIT_INTERVAL;
91     }
92 }
93
94 void
95 A2_engraver::acknowledge_element (Score_element_info i)
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           
114   if (Stem::has_interface (i.elem_l_))
115     {
116       Item *stem_l = dynamic_cast<Item*> (i.elem_l_);
117
118       SCM unison = get_property ("unison");
119       SCM unirhythm = get_property ("unirhythm");
120       SCM solo = get_property ("solo");
121       SCM split_interval = get_property ("split-interval");
122       SCM solo_adue = get_property ("soloADue");
123
124       if ((unirhythm != SCM_BOOL_T && solo != SCM_BOOL_T)
125           || (unirhythm == SCM_BOOL_T && split_interval == SCM_BOOL_T
126               && (unison != SCM_BOOL_T || solo_adue != SCM_BOOL_T)))
127         {
128           if (daddy_trans_l_->id_str_ == "one")
129             {
130               stem_l->set_elt_property ("direction", gh_int2scm (1));
131             }
132           else if (daddy_trans_l_->id_str_ == "two")
133             {
134               stem_l->set_elt_property ("direction", gh_int2scm (-1));
135             }
136         }
137     }
138 }
139
140 void 
141 A2_engraver::do_pre_move_processing ()
142 {
143   if (text_p_)
144     {
145       Side_position::add_staff_support (text_p_);
146       typeset_element (text_p_);
147       text_p_ = 0;
148     }
149 }
150