]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
release: 1.5.13
[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--2001 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   TRANSLATOR_DECLARATIONS(Mark_engraver);
32 protected:
33   Item* text_p_;
34   
35 protected:
36   virtual void stop_translation_timestep ();
37   virtual void acknowledge_grob (Grob_info);
38   void create_items (Request*);
39   virtual bool try_music (Music *req_l);
40   virtual void start_translation_timestep ();
41   virtual void initialize ();
42   virtual void process_music ();
43   
44 private:
45   Mark_req * mark_req_l_;
46 };
47
48
49
50
51
52 Mark_engraver::Mark_engraver ()
53 {
54   text_p_ =0;
55   mark_req_l_ = 0;
56 }
57
58 void
59 Mark_engraver::initialize ()
60 {
61   daddy_trans_l_->set_property ("stavesFound", SCM_EOL); // ugh: sharing with barnumber grav.
62 }
63
64
65
66
67 /*
68
69 which grobs carry INVISIBLE-STAFF ?
70
71 */
72
73 void
74 Mark_engraver::acknowledge_grob (Grob_info inf)
75 {
76   Grob * s = inf.grob_l_;
77   if (Staff_symbol::has_interface (s)
78       || to_boolean (s->get_grob_property ("invisible-staff")))
79     {
80       SCM sts = get_property ("stavesFound");
81       SCM thisstaff = inf.grob_l_->self_scm ();
82       if (scm_memq (thisstaff, sts) == SCM_BOOL_F)
83         daddy_trans_l_->set_property ("stavesFound", gh_cons (thisstaff, sts));
84     }
85   else if (text_p_ && Bar::has_interface (s))
86     {
87       /*
88         Ugh. Figure out how to do this right at beginning of line, (without
89         creating class Bar_script : public Item).
90       */
91       text_p_->set_parent (s, X_AXIS);
92     }
93 }
94
95 void 
96 Mark_engraver::stop_translation_timestep ()
97 {
98   if (text_p_)
99     {
100       text_p_->set_grob_property ("side-support-elements" , get_property ("stavesFound"));
101       typeset_grob (text_p_);
102       text_p_ =0;
103     }
104 }
105
106
107 void
108 Mark_engraver::create_items (Request *rq)
109 {
110   if (text_p_)
111     return;
112
113   SCM s = get_property ("RehearsalMark");
114   text_p_ = new Item (s);
115
116
117   Side_position_interface::set_axis (text_p_, Y_AXIS);
118
119   announce_grob (text_p_, rq);
120 }
121
122
123 void
124 Mark_engraver::start_translation_timestep ()
125 {
126   mark_req_l_ = 0;
127 }
128
129
130 bool
131 Mark_engraver::try_music (Music* r_l)
132 {
133   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
134     {
135       if (mark_req_l_ && mr->equal_b (mark_req_l_))
136         return true;
137       if (mark_req_l_)
138         return false;
139       mark_req_l_ = mr;
140       return true;
141     }
142   return false;
143 }
144
145
146 /*
147
148   TODO: make the increment function in Scheme.
149
150 */
151 void
152 Mark_engraver::process_music ()
153 {
154   if (mark_req_l_)
155     {
156       create_items (mark_req_l_);
157
158       String t;
159
160       /*
161         automatic marks.
162        */
163       
164       SCM m = mark_req_l_->get_mus_property ("label");
165       if (gh_pair_p (m)) // markup text
166         text_p_->set_grob_property ("text",m);
167       else 
168         {
169           if (!gh_string_p (m)) 
170             m =  get_property ("rehearsalMark");
171           ;
172           
173           if (gh_number_p (m))
174             {
175               int mark_count = gh_scm2int (m);
176               t = to_str (mark_count);
177               mark_count ++;
178               m = gh_int2scm (mark_count);
179             }
180           else if (gh_string_p (m))
181             {
182               t = ly_scm2string (m);
183               String next;
184               if (t.length_i ())
185                 {
186                   char c = t[0];
187                   c++;
188                   next = to_str (c);
189                 }
190               m = ly_str02scm (next.ch_C ());
191             }
192           else
193             {
194               m = gh_int2scm (1);
195             }
196           
197           daddy_trans_l_->set_property ("rehearsalMark", m);
198           
199           text_p_->set_grob_property ("text",
200                                       ly_str02scm (t.ch_C ()));
201
202           String style = "mark";
203           for (int i=0; i < t.length_i (); i++)
204             {
205               if (!isdigit (t[i])) 
206                 {
207                   style = "large";
208                   break;
209                 }
210             }
211           SCM st = ly_symbol2scm (style.ch_C ());
212           text_p_->set_grob_property ("font-style",  st);
213         }
214
215     }
216 }
217
218 ENTER_DESCRIPTION(Mark_engraver,
219 /* descr */       "",
220 /* creats*/       "RehearsalMark",
221 /* acks  */       "grob-interface", 
222 /* reads */       "rehearsalMark stavesFound",
223 /* write */       "");