]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
release: 1.3.61
[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 "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   Item* text_p_;
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 }
66
67
68 void
69 Mark_engraver::acknowledge_element (Score_element_info inf)
70 {
71   Score_element * s = inf.elem_l_;
72   if (dynamic_cast<Staff_symbol*> (s))
73     {
74       staffs_ = gh_cons (inf.elem_l_->self_scm_, staffs_);
75     }
76   else if (text_p_ && dynamic_cast<Bar*> (s))
77     {
78       /*
79         Ugh. Figure out how to do this right at beginning of line, (without
80         creating class Bar_script : public Item).
81       */
82       text_p_->set_parent (s, X_AXIS);
83     }
84 }
85
86 void 
87 Mark_engraver::do_pre_move_processing ()
88 {
89   if (text_p_)
90     {
91       text_p_->set_elt_pointer("side-support-elements" , staffs_);
92       typeset_element (text_p_);
93       text_p_ =0;
94     }
95 }
96
97
98 void
99 Mark_engraver::create_items (Request *rq)
100 {
101   if (text_p_)
102     return;
103
104   SCM s = get_property ("basicMarkProperties");
105   text_p_ = new Item (s);
106
107   Group_interface (text_p_, "interfaces").add_thing (ly_symbol2scm ("Mark"));
108   Side_position_interface staffside(text_p_);
109   staffside.set_axis (Y_AXIS);
110
111   /*
112     -> Generic props.
113    */
114   SCM prop = get_property ("markDirection");
115   if (!isdir_b (prop))
116     {
117       prop = gh_int2scm (UP);
118     }
119   text_p_->set_elt_property ("direction", prop);
120
121   SCM padding = get_property ("markScriptPadding");
122   if (gh_number_p(padding))
123     {
124       text_p_->set_elt_property ("padding", padding);
125     }
126   else
127     {
128       text_p_
129         ->set_elt_property ("padding",
130                             gh_double2scm(paper_l ()->get_var ("interline")));
131     }
132
133   
134   announce_element (Score_element_info (text_p_, rq));
135 }
136
137
138 void
139 Mark_engraver::do_post_move_processing ()
140 {
141   mark_req_l_ = 0;
142 }
143
144
145 bool
146 Mark_engraver::do_try_music (Music* r_l)
147 {
148   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
149     {
150       if (mark_req_l_ && mr->equal_b (mark_req_l_))
151         return true;
152       if (mark_req_l_)
153         return false;
154       mark_req_l_ = mr;
155       return true;
156     }
157   return false;
158 }
159
160 void
161 Mark_engraver::do_process_music ()
162 {
163   if (mark_req_l_)
164     {
165       create_items (mark_req_l_);
166
167       String t;
168
169       /*
170         automatic marks.
171        */
172       SCM m = (mark_req_l_->mark_label_ == SCM_UNDEFINED)
173         ? get_property ("rehearsalMark")
174         : SCM(mark_req_l_->mark_label_);
175       
176       if (gh_number_p (m))
177         {
178           int mark_count = gh_scm2int (m);
179           t = to_str (mark_count);
180           mark_count ++;
181           m = gh_int2scm (mark_count);
182         }
183       else if (gh_string_p (m))
184         {
185           t = ly_scm2string (m);
186           String next;
187           if (t.length_i ())
188             {
189               char c = t[0];
190               c++;
191               next = to_str (c);
192             }
193           m = ly_str02scm (next.ch_C());
194         }
195       else
196         {
197           m = gh_int2scm (1);
198         }
199           
200       daddy_trans_l_->set_property ("rehearsalMark", m);
201
202       
203       text_p_->set_elt_property ("text",
204                                  ly_str02scm ( t.ch_C()));
205
206       String style = "mark";
207       for (int i=0; i < t.length_i(); i++)
208         {
209           if (!isdigit(t[i])) 
210             {
211               style = "large";
212               break;
213             }
214         }
215       SCM st = ly_str02scm (style.ch_C());
216       text_p_->set_elt_property ("style",  st);
217     }
218 }
219