]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
patch::: 1.3.96.jcn9
[lilypond.git] / lily / mark-engraver.cc
1 /*
2   mark-engraver.cc -- implement Mark_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6  (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <ctype.h>
10 #include "bar.hh"
11 #include "command-request.hh"
12 #include "staff-symbol.hh"
13 #include "engraver-group-engraver.hh"
14 #include "engraver.hh"
15 #include "lily-guile.hh"
16 #include "paper-column.hh"
17 #include "paper-def.hh"
18
19 #include "side-position-interface.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "item.hh"
22 #include "group-interface.hh"
23
24 /**
25   put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
26   rehearsal marks.
27  */
28 class Mark_engraver : public Engraver
29 {
30 public:
31   VIRTUAL_COPY_CONS(Translator);
32   Mark_engraver ();
33 protected:
34   Item* text_p_;
35   
36 protected:
37   virtual void do_pre_move_processing ();
38   virtual void acknowledge_element (Score_element_info);
39   void create_items(Request*);
40   virtual bool do_try_music (Music *req_l);
41   virtual void do_process_music ();
42   virtual void do_post_move_processing ();
43   virtual void do_creation_processing ();
44   
45 private:
46   Mark_req * mark_req_l_;
47 };
48
49
50 ADD_THIS_TRANSLATOR (Mark_engraver);
51
52
53 Mark_engraver::Mark_engraver ()
54 {
55   text_p_ =0;
56   mark_req_l_ = 0;
57 }
58
59 void
60 Mark_engraver::do_creation_processing ()
61 {
62   daddy_trans_l_->set_property ("staffsFound", SCM_EOL); // ugh: sharing with barnumber grav.
63 }
64
65
66 void
67 Mark_engraver::acknowledge_element (Score_element_info inf)
68 {
69   Score_element * s = inf.elem_l_;
70   if (Staff_symbol::has_interface (s)
71       || to_boolean (s->get_elt_property ("invisible-staff")))
72     {
73       SCM sts = get_property ("staffsFound");
74       SCM thisstaff = inf.elem_l_->self_scm ();
75       if (scm_memq (thisstaff, sts) == SCM_BOOL_F)
76         daddy_trans_l_->set_property ("staffsFound", gh_cons (thisstaff, sts));
77     }
78   else if (text_p_ && Bar::has_interface (s))
79     {
80       /*
81         Ugh. Figure out how to do this right at beginning of line, (without
82         creating class Bar_script : public Item).
83       */
84       text_p_->set_parent (s, X_AXIS);
85     }
86 }
87
88 void 
89 Mark_engraver::do_pre_move_processing ()
90 {
91   if (text_p_)
92     {
93       text_p_->set_elt_property("side-support-elements" , get_property ("staffsFound"));
94       typeset_element (text_p_);
95       text_p_ =0;
96     }
97 }
98
99
100 void
101 Mark_engraver::create_items (Request *rq)
102 {
103   if (text_p_)
104     return;
105
106   SCM s = get_property ("RehearsalMark");
107   text_p_ = new Item (s);
108
109
110   Side_position::set_axis (text_p_, Y_AXIS);
111
112   /*
113     -> Generic props.
114    */
115   SCM prop = get_property ("markDirection");
116   if (!isdir_b (prop))
117     {
118       prop = gh_int2scm (UP);
119     }
120   text_p_->set_elt_property ("direction", prop);
121
122   SCM padding = get_property ("markScriptPadding");
123   if (gh_number_p(padding))
124     {
125       text_p_->set_elt_property ("padding", padding);
126     }
127   else
128     {
129       text_p_
130         ->set_elt_property ("padding",
131                             gh_double2scm(paper_l ()->get_var ("staffspace")));
132     }
133
134   
135   announce_element (text_p_, rq);
136 }
137
138
139 void
140 Mark_engraver::do_post_move_processing ()
141 {
142   mark_req_l_ = 0;
143 }
144
145
146 bool
147 Mark_engraver::do_try_music (Music* r_l)
148 {
149   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
150     {
151       if (mark_req_l_ && mr->equal_b (mark_req_l_))
152         return true;
153       if (mark_req_l_)
154         return false;
155       mark_req_l_ = mr;
156       return true;
157     }
158   return false;
159 }
160
161 void
162 Mark_engraver::do_process_music ()
163 {
164   if (mark_req_l_)
165     {
166       create_items (mark_req_l_);
167
168       String t;
169
170       /*
171         automatic marks.
172        */
173       
174       SCM m = mark_req_l_->get_mus_property ("label");
175       if (!gh_string_p (m)) 
176         m =  get_property ("rehearsalMark");
177 ;
178       
179       if (gh_number_p (m))
180         {
181           int mark_count = gh_scm2int (m);
182           t = to_str (mark_count);
183           mark_count ++;
184           m = gh_int2scm (mark_count);
185         }
186       else if (gh_string_p (m))
187         {
188           t = ly_scm2string (m);
189           String next;
190           if (t.length_i ())
191             {
192               char c = t[0];
193               c++;
194               next = to_str (c);
195             }
196           m = ly_str02scm (next.ch_C());
197         }
198       else
199         {
200           m = gh_int2scm (1);
201         }
202           
203       daddy_trans_l_->set_property ("rehearsalMark", m);
204
205       
206       text_p_->set_elt_property ("text",
207                                  ly_str02scm ( t.ch_C()));
208
209       String style = "mark";
210       for (int i=0; i < t.length_i(); i++)
211         {
212           if (!isdigit(t[i])) 
213             {
214               style = "large";
215               break;
216             }
217         }
218       SCM st = ly_str02scm (style.ch_C());
219       text_p_->set_elt_property ("style",  st);
220     }
221 }
222