]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
release: 1.3.74
[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 "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"
18 #include "protected-scm.hh"
19 #include "side-position-interface.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "item.hh"
22 #include "group-interface.hh"
23
24 /**
25   put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
26   rehearsal marks.
27  */
28 class Mark_engraver : public Engraver
29 {
30 public:
31   VIRTUAL_COPY_CONS(Translator);
32   Mark_engraver ();
33 protected:
34   Item* text_p_;
35   Protected_scm staffs_;
36   
37 protected:
38   virtual void do_pre_move_processing ();
39   virtual void acknowledge_element (Score_element_info);
40   void create_items(Request*);
41   virtual bool do_try_music (Music *req_l);
42   virtual void do_process_music ();
43   virtual void do_post_move_processing ();
44 private:
45   Mark_req * mark_req_l_;
46 };
47
48
49 ADD_THIS_TRANSLATOR (Mark_engraver);
50
51
52 Mark_engraver::Mark_engraver ()
53 {
54   text_p_ =0;
55   mark_req_l_ = 0;
56   staffs_ = SCM_EOL;
57 }
58
59
60
61 void
62 Mark_engraver::acknowledge_element (Score_element_info inf)
63 {
64   Score_element * s = inf.elem_l_;
65   if (Staff_symbol::has_interface (s))
66     {
67       staffs_ = gh_cons (inf.elem_l_->self_scm (), staffs_);
68     }
69   else if (text_p_ && Bar::has_interface (s))
70     {
71       /*
72         Ugh. Figure out how to do this right at beginning of line, (without
73         creating class Bar_script : public Item).
74       */
75       text_p_->set_parent (s, X_AXIS);
76     }
77 }
78
79 void 
80 Mark_engraver::do_pre_move_processing ()
81 {
82   if (text_p_)
83     {
84       text_p_->set_elt_property("side-support-elements" , staffs_);
85       typeset_element (text_p_);
86       text_p_ =0;
87     }
88 }
89
90
91 void
92 Mark_engraver::create_items (Request *rq)
93 {
94   if (text_p_)
95     return;
96
97   SCM s = get_property ("basicMarkProperties");
98   text_p_ = new Item (s);
99
100
101   Side_position::set_axis (text_p_, Y_AXIS);
102
103   /*
104     -> Generic props.
105    */
106   SCM prop = get_property ("markDirection");
107   if (!isdir_b (prop))
108     {
109       prop = gh_int2scm (UP);
110     }
111   text_p_->set_elt_property ("direction", prop);
112
113   SCM padding = get_property ("markScriptPadding");
114   if (gh_number_p(padding))
115     {
116       text_p_->set_elt_property ("padding", padding);
117     }
118   else
119     {
120       text_p_
121         ->set_elt_property ("padding",
122                             gh_double2scm(paper_l ()->get_var ("interline")));
123     }
124
125   
126   announce_element (text_p_, rq);
127 }
128
129
130 void
131 Mark_engraver::do_post_move_processing ()
132 {
133   mark_req_l_ = 0;
134 }
135
136
137 bool
138 Mark_engraver::do_try_music (Music* r_l)
139 {
140   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
141     {
142       if (mark_req_l_ && mr->equal_b (mark_req_l_))
143         return true;
144       if (mark_req_l_)
145         return false;
146       mark_req_l_ = mr;
147       return true;
148     }
149   return false;
150 }
151
152 void
153 Mark_engraver::do_process_music ()
154 {
155   if (mark_req_l_)
156     {
157       create_items (mark_req_l_);
158
159       String t;
160
161       /*
162         automatic marks.
163        */
164       
165       SCM m = mark_req_l_->get_mus_property ("label");
166       if (gh_string_p (m)) 
167         m =  get_property ("rehearsalMark");
168 ;
169       
170       if (gh_number_p (m))
171         {
172           int mark_count = gh_scm2int (m);
173           t = to_str (mark_count);
174           mark_count ++;
175           m = gh_int2scm (mark_count);
176         }
177       else if (gh_string_p (m))
178         {
179           t = ly_scm2string (m);
180           String next;
181           if (t.length_i ())
182             {
183               char c = t[0];
184               c++;
185               next = to_str (c);
186             }
187           m = ly_str02scm (next.ch_C());
188         }
189       else
190         {
191           m = gh_int2scm (1);
192         }
193           
194       daddy_trans_l_->set_property ("rehearsalMark", m);
195
196       
197       text_p_->set_elt_property ("text",
198                                  ly_str02scm ( t.ch_C()));
199
200       String style = "mark";
201       for (int i=0; i < t.length_i(); i++)
202         {
203           if (!isdigit(t[i])) 
204             {
205               style = "large";
206               break;
207             }
208         }
209       SCM st = ly_str02scm (style.ch_C());
210       text_p_->set_elt_property ("style",  st);
211     }
212 }
213