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