]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
release: 1.3.46
[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
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
25 /**
26   put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
27   rehearsal marks.
28  */
29 class Mark_engraver : public Engraver
30 {
31 public:
32   VIRTUAL_COPY_CONS(Translator);
33   Mark_engraver ();
34 protected:
35   Text_item* text_p_;
36   Protected_scm visibility_lambda_;
37   Protected_scm staffs_;
38   
39 protected:
40   virtual void do_creation_processing ();
41   virtual void do_pre_move_processing ();
42   virtual void acknowledge_element (Score_element_info);
43   void create_items(Request*);
44   virtual bool do_try_music (Music *req_l);
45   virtual void do_process_music ();
46   virtual void do_post_move_processing ();
47 private:
48   Mark_req * mark_req_l_;
49 };
50
51
52 ADD_THIS_TRANSLATOR (Mark_engraver);
53
54
55 Mark_engraver::Mark_engraver ()
56 {
57   text_p_ =0;
58   mark_req_l_ = 0;
59   staffs_ = SCM_EOL;
60 }
61
62 void
63 Mark_engraver::do_creation_processing ()
64 {
65   String t = "markVisibilityFunction";
66   SCM proc = get_property (t);
67
68   if (gh_procedure_p (proc))
69     visibility_lambda_ = proc;
70 }
71
72
73
74 void
75 Mark_engraver::acknowledge_element (Score_element_info inf)
76 {
77   Score_element * s = inf.elem_l_;
78   if (dynamic_cast<Staff_symbol*> (s))
79     {
80       staffs_ = gh_cons (inf.elem_l_->self_scm_, staffs_);
81     }
82   else if (text_p_ && dynamic_cast<Bar*> (s))
83     {
84       /*
85         Ugh. Figure out how to do this right at beginning of line, (without
86         creating class Bar_script : public Text_item).
87       */
88       text_p_->set_parent (s, X_AXIS);
89     }
90 }
91
92 void 
93 Mark_engraver::do_pre_move_processing ()
94 {
95   if (text_p_)
96     {
97       text_p_->set_elt_property ("side-support" , staffs_);
98       typeset_element (text_p_);
99       text_p_ =0;
100     }
101 }
102
103
104 void
105 Mark_engraver::create_items (Request *rq)
106 {
107   if (text_p_)
108     return;
109   
110   text_p_ = new Text_item;
111   text_p_->set_elt_property ("breakable", SCM_BOOL_T); // ugh
112   Side_position_interface staffside(text_p_);
113   staffside.set_axis (Y_AXIS);
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 ("interline")));
132     }
133
134   if (gh_procedure_p (visibility_lambda_))
135       text_p_->set_elt_property ("visibility-lambda",
136                                  visibility_lambda_);
137   
138   announce_element (Score_element_info (text_p_, rq));
139 }
140
141
142 void
143 Mark_engraver::do_post_move_processing ()
144 {
145   mark_req_l_ = 0;
146 }
147
148
149 bool
150 Mark_engraver::do_try_music (Music* r_l)
151 {
152   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
153     {
154       if (mark_req_l_ && mr->equal_b (mark_req_l_))
155         return true;
156       if (mark_req_l_)
157         return false;
158       mark_req_l_ = mr;
159       return true;
160     }
161   return false;
162 }
163
164 void
165 Mark_engraver::do_process_music ()
166 {
167   if (mark_req_l_)
168     {
169       create_items (mark_req_l_);
170
171       String t;
172
173       /*
174         automatic marks.
175        */
176       SCM m = (mark_req_l_->mark_label_ == SCM_UNDEFINED)
177         ? get_property ("rehearsalMark")
178         : SCM(mark_req_l_->mark_label_);
179       
180       if (gh_number_p (m))
181         {
182           int mark_count = gh_scm2int (m);
183           t = to_str (mark_count);
184           mark_count ++;
185           m = gh_int2scm (mark_count);
186         }
187       else if (gh_string_p (m))
188         {
189           t = ly_scm2string (m);
190           String next;
191           if (t.length_i ())
192             {
193               char c = t[0];
194               c++;
195               next = to_str (c);
196             }
197           m = ly_str02scm (next.ch_C());
198         }
199       else
200         {
201           m = gh_int2scm (1);
202         }
203           
204       daddy_trans_l_->set_property ("rehearsalMark", m);
205
206       
207       text_p_->set_elt_property ("text",
208                                  ly_str02scm ( t.ch_C()));
209       SCM st = ly_str02scm ((t.index_any_i ("0123456789")  >= 0 )
210                             ? "mark" : "large");
211       text_p_->set_elt_property ("style",  st);
212     }
213 }
214