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