lilypond-1.3.65
[lilypond.git] / lily / mark-engraver.cc
blob019e36736182f5aed63a32140826215c47a87983
1 /*
2 mark-engraver.cc -- implement Mark_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include <ctype.h>
10 #include "bar.hh"
11 #include "command-request.hh"
12 #include "dimension-cache.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 #include "protected-scm.hh"
19 #include "side-position-interface.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "staff-symbol.hh"
22 #include "item.hh"
23 #include "group-interface.hh"
25 /**
26 put stuff over or next to bars. Examples: bar numbers, marginal notes,
27 rehearsal marks.
29 class Mark_engraver : public Engraver
31 public:
32 VIRTUAL_COPY_CONS(Translator);
33 Mark_engraver ();
34 protected:
35 Item* text_p_;
36 Protected_scm staffs_;
38 protected:
39 virtual void do_creation_processing ();
40 virtual void do_pre_move_processing ();
41 virtual void acknowledge_element (Score_element_info);
42 void create_items(Request*);
43 virtual bool do_try_music (Music *req_l);
44 virtual void do_process_music ();
45 virtual void do_post_move_processing ();
46 private:
47 Mark_req * mark_req_l_;
51 ADD_THIS_TRANSLATOR (Mark_engraver);
54 Mark_engraver::Mark_engraver ()
56 text_p_ =0;
57 mark_req_l_ = 0;
58 staffs_ = SCM_EOL;
61 void
62 Mark_engraver::do_creation_processing ()
67 void
68 Mark_engraver::acknowledge_element (Score_element_info inf)
70 Score_element * s = inf.elem_l_;
71 if (dynamic_cast<Staff_symbol*> (s))
73 staffs_ = gh_cons (inf.elem_l_->self_scm_, staffs_);
75 else if (text_p_ && dynamic_cast<Bar*> (s))
78 Ugh. Figure out how to do this right at beginning of line, (without
79 creating class Bar_script : public Item).
81 text_p_->set_parent (s, X_AXIS);
85 void
86 Mark_engraver::do_pre_move_processing ()
88 if (text_p_)
90 text_p_->set_elt_pointer("side-support-elements" , staffs_);
91 typeset_element (text_p_);
92 text_p_ =0;
97 void
98 Mark_engraver::create_items (Request *rq)
100 if (text_p_)
101 return;
103 SCM s = get_property ("basicMarkProperties");
104 text_p_ = new Item (s);
106 Group_interface (text_p_, "interfaces").add_thing (ly_symbol2scm ("Mark"));
107 Side_position_interface staffside(text_p_);
108 staffside.set_axis (Y_AXIS);
111 -> Generic props.
113 SCM prop = get_property ("markDirection");
114 if (!isdir_b (prop))
116 prop = gh_int2scm (UP);
118 text_p_->set_elt_property ("direction", prop);
120 SCM padding = get_property ("markScriptPadding");
121 if (gh_number_p(padding))
123 text_p_->set_elt_property ("padding", padding);
125 else
127 text_p_
128 ->set_elt_property ("padding",
129 gh_double2scm(paper_l ()->get_var ("interline")));
133 announce_element (Score_element_info (text_p_, rq));
137 void
138 Mark_engraver::do_post_move_processing ()
140 mark_req_l_ = 0;
144 bool
145 Mark_engraver::do_try_music (Music* r_l)
147 if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
149 if (mark_req_l_ && mr->equal_b (mark_req_l_))
150 return true;
151 if (mark_req_l_)
152 return false;
153 mark_req_l_ = mr;
154 return true;
156 return false;
159 void
160 Mark_engraver::do_process_music ()
162 if (mark_req_l_)
164 create_items (mark_req_l_);
166 String t;
169 automatic marks.
171 SCM m = (mark_req_l_->mark_label_ == SCM_UNDEFINED)
172 ? get_property ("rehearsalMark")
173 : SCM(mark_req_l_->mark_label_);
175 if (gh_number_p (m))
177 int mark_count = gh_scm2int (m);
178 t = to_str (mark_count);
179 mark_count ++;
180 m = gh_int2scm (mark_count);
182 else if (gh_string_p (m))
184 t = ly_scm2string (m);
185 String next;
186 if (t.length_i ())
188 char c = t[0];
189 c++;
190 next = to_str (c);
192 m = ly_str02scm (next.ch_C());
194 else
196 m = gh_int2scm (1);
199 daddy_trans_l_->set_property ("rehearsalMark", m);
202 text_p_->set_elt_property ("text",
203 ly_str02scm ( t.ch_C()));
205 String style = "mark";
206 for (int i=0; i < t.length_i(); i++)
208 if (!isdigit(t[i]))
210 style = "large";
211 break;
214 SCM st = ly_str02scm (style.ch_C());
215 text_p_->set_elt_property ("style", st);