]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
release: 1.3.109
[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
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   
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   void deprecated_process_music ();
42   virtual void start_translation_timestep ();
43   virtual void do_creation_processing ();
44   virtual void create_grobs ();
45   
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 }
59
60 void
61 Mark_engraver::do_creation_processing ()
62 {
63   daddy_trans_l_->set_property ("staffsFound", SCM_EOL); // ugh: sharing with barnumber grav.
64 }
65
66
67 void
68 Mark_engraver::acknowledge_grob (Grob_info inf)
69 {
70   Grob * s = inf.elem_l_;
71   if (Staff_symbol::has_interface (s)
72       || to_boolean (s->get_grob_property ("invisible-staff")))
73     {
74       SCM sts = get_property ("staffsFound");
75       SCM thisstaff = inf.elem_l_->self_scm ();
76       if (scm_memq (thisstaff, sts) == SCM_BOOL_F)
77         daddy_trans_l_->set_property ("staffsFound", gh_cons (thisstaff, sts));
78     }
79   else if (text_p_ && Bar::has_interface (s))
80     {
81       /*
82         Ugh. Figure out how to do this right at beginning of line, (without
83         creating class Bar_script : public Item).
84       */
85       text_p_->set_parent (s, X_AXIS);
86     }
87 }
88
89 void 
90 Mark_engraver::stop_translation_timestep ()
91 {
92   if (text_p_)
93     {
94       text_p_->set_grob_property("side-support-elements" , get_property ("staffsFound"));
95       typeset_grob (text_p_);
96       text_p_ =0;
97     }
98 }
99
100
101 void
102 Mark_engraver::create_items (Request *rq)
103 {
104   if (text_p_)
105     return;
106
107   SCM s = get_property ("RehearsalMark");
108   text_p_ = new Item (s);
109
110
111   Side_position::set_axis (text_p_, Y_AXIS);
112
113   announce_grob (text_p_, rq);
114 }
115
116
117 void
118 Mark_engraver::start_translation_timestep ()
119 {
120   mark_req_l_ = 0;
121 }
122
123
124 bool
125 Mark_engraver::try_music (Music* r_l)
126 {
127   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
128     {
129       if (mark_req_l_ && mr->equal_b (mark_req_l_))
130         return true;
131       if (mark_req_l_)
132         return false;
133       mark_req_l_ = mr;
134       return true;
135     }
136   return false;
137 }
138
139 void
140 Mark_engraver::create_grobs ()
141 {
142   deprecated_process_music ();
143 }
144
145 void
146 Mark_engraver::deprecated_process_music ()
147 {
148   if (mark_req_l_)
149     {
150       create_items (mark_req_l_);
151
152       String t;
153
154       /*
155         automatic marks.
156        */
157       
158       SCM m = mark_req_l_->get_mus_property ("label");
159       if (!gh_string_p (m)) 
160         m =  get_property ("rehearsalMark");
161 ;
162       
163       if (gh_number_p (m))
164         {
165           int mark_count = gh_scm2int (m);
166           t = to_str (mark_count);
167           mark_count ++;
168           m = gh_int2scm (mark_count);
169         }
170       else if (gh_string_p (m))
171         {
172           t = ly_scm2string (m);
173           String next;
174           if (t.length_i ())
175             {
176               char c = t[0];
177               c++;
178               next = to_str (c);
179             }
180           m = ly_str02scm (next.ch_C());
181         }
182       else
183         {
184           m = gh_int2scm (1);
185         }
186           
187       daddy_trans_l_->set_property ("rehearsalMark", m);
188
189       
190       text_p_->set_grob_property ("text",
191                                  ly_str02scm ( t.ch_C()));
192
193       String style = "mark";
194       for (int i=0; i < t.length_i(); i++)
195         {
196           if (!isdigit(t[i])) 
197             {
198               style = "large";
199               break;
200             }
201         }
202       SCM st = ly_symbol2scm (style.ch_C());
203       text_p_->set_grob_property ("style",  st);
204     }
205 }
206