lilypond-1.3.145
[lilypond.git] / lily / mark-engraver.cc
blobf0abdbc711e37fd8912ea6ebff4a1eafa5f0110a
1 /*
2 mark-engraver.cc -- implement Mark_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
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"
19 #include "side-position-interface.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "item.hh"
22 #include "group-interface.hh"
24 /**
25 put stuff over or next to bars. Examples: bar numbers, marginal notes,
26 rehearsal marks.
28 class Mark_engraver : public Engraver
30 public:
31 VIRTUAL_COPY_CONS (Translator);
32 Mark_engraver ();
33 protected:
34 Item* text_p_;
36 protected:
37 virtual void stop_translation_timestep ();
38 virtual void acknowledge_grob (Grob_info);
39 void create_items (Request*);
40 virtual bool try_music (Music *req_l);
41 virtual void start_translation_timestep ();
42 virtual void initialize ();
43 virtual void process_music ();
45 private:
46 Mark_req * mark_req_l_;
50 ADD_THIS_TRANSLATOR (Mark_engraver);
53 Mark_engraver::Mark_engraver ()
55 text_p_ =0;
56 mark_req_l_ = 0;
59 void
60 Mark_engraver::initialize ()
62 daddy_trans_l_->set_property ("staffsFound", SCM_EOL); // ugh: sharing with barnumber grav.
66 void
67 Mark_engraver::acknowledge_grob (Grob_info inf)
69 Grob * s = inf.elem_l_;
70 if (Staff_symbol::has_interface (s)
71 || to_boolean (s->get_grob_property ("invisible-staff")))
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));
78 else if (text_p_ && Bar::has_interface (s))
81 Ugh. Figure out how to do this right at beginning of line, (without
82 creating class Bar_script : public Item).
84 text_p_->set_parent (s, X_AXIS);
88 void
89 Mark_engraver::stop_translation_timestep ()
91 if (text_p_)
93 text_p_->set_grob_property ("side-support-elements" , get_property ("staffsFound"));
94 typeset_grob (text_p_);
95 text_p_ =0;
100 void
101 Mark_engraver::create_items (Request *rq)
103 if (text_p_)
104 return;
106 SCM s = get_property ("RehearsalMark");
107 text_p_ = new Item (s);
110 Side_position_interface::set_axis (text_p_, Y_AXIS);
112 announce_grob (text_p_, rq);
116 void
117 Mark_engraver::start_translation_timestep ()
119 mark_req_l_ = 0;
123 bool
124 Mark_engraver::try_music (Music* r_l)
126 if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
128 if (mark_req_l_ && mr->equal_b (mark_req_l_))
129 return true;
130 if (mark_req_l_)
131 return false;
132 mark_req_l_ = mr;
133 return true;
135 return false;
141 TODO: make the increment function in Scheme.
144 void
145 Mark_engraver::process_music ()
147 if (mark_req_l_)
149 create_items (mark_req_l_);
151 String t;
154 automatic marks.
157 SCM m = mark_req_l_->get_mus_property ("label");
158 if (gh_pair_p (m)) // markup text
159 text_p_->set_grob_property ("text",m);
160 else
162 if (!gh_string_p (m))
163 m = get_property ("rehearsalMark");
166 if (gh_number_p (m))
168 int mark_count = gh_scm2int (m);
169 t = to_str (mark_count);
170 mark_count ++;
171 m = gh_int2scm (mark_count);
173 else if (gh_string_p (m))
175 t = ly_scm2string (m);
176 String next;
177 if (t.length_i ())
179 char c = t[0];
180 c++;
181 next = to_str (c);
183 m = ly_str02scm (next.ch_C ());
185 else
187 m = gh_int2scm (1);
190 daddy_trans_l_->set_property ("rehearsalMark", m);
192 text_p_->set_grob_property ("text",
193 ly_str02scm (t.ch_C ()));
195 String style = "mark";
196 for (int i=0; i < t.length_i (); i++)
198 if (!isdigit (t[i]))
200 style = "large";
201 break;
204 SCM st = ly_symbol2scm (style.ch_C ());
205 text_p_->set_grob_property ("font-style", st);