]> git.donarmstrong.com Git - lilypond.git/blob - lily/a2-engraver.cc
patch::: 1.3.78.jcn2
[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, UNISON, SOLO } 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 }
46
47
48 void
49 A2_engraver::acknowledge_element (Score_element_info i)
50 {
51   if (!text_p_)
52     {
53       SCM unison = get_property ("unison");
54       SCM solo = get_property ("solo");
55
56       if ((solo == SCM_BOOL_T && state_ != SOLO)
57           || (unison == SCM_BOOL_T && state_ != UNISON))
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           /*
64             Urg, read prop
65           */
66           SCM text;
67           Direction dir = UP;
68           if (solo == SCM_BOOL_T)
69             {
70               state_ = SOLO;
71               if (daddy_trans_l_->id_str_ == "one")
72                 text = ly_str02scm ("Solo");
73               else
74                 {
75                   text = ly_str02scm ("Solo II");
76                   dir = DOWN;
77                 }
78             }
79           else if (unison == SCM_BOOL_T)
80             {
81               text = ly_str02scm ("\\`a 2");
82               state_ = UNISON;
83             }
84           
85           Side_position::set_direction (text_p_, dir);
86           text_p_->set_elt_property ("text", text);
87
88         }
89     }
90 #if 0
91 }
92
93 void
94 A2_engraver::acknowledge_element (Score_element_info i)
95 {
96 #endif
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 unirhythm = get_property ("unirhythm");
119       SCM unison = get_property ("unison");
120       SCM solo = get_property ("solo");
121       SCM interval = get_property ("interval");
122
123       /*
124         This still needs some work.
125        */
126       if ((unirhythm != SCM_BOOL_T && solo != SCM_BOOL_T)
127           || (unirhythm == SCM_BOOL_T
128               && gh_number_p (interval) && gh_scm2int (interval) < 3))
129         {
130           if (daddy_trans_l_->id_str_ == "one")
131             {
132               //Directional_element_interface (stem_l).set (UP);
133               stem_l->set_elt_property ("direction", gh_int2scm (1));
134             }
135           else if (daddy_trans_l_->id_str_ == "two")
136             {
137               //Directional_element_interface (stem_l).set (DOWN);
138               stem_l->set_elt_property ("direction", gh_int2scm (-1));
139             }
140         }
141     }
142 }
143
144 void 
145 A2_engraver::do_pre_move_processing ()
146 {
147   if (text_p_)
148     {
149       Side_position::add_staff_support (text_p_);
150       typeset_element (text_p_);
151       text_p_ = 0;
152     }
153 }
154