]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
release: 1.5.29
[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--2002 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 "side-position-interface.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "item.hh"
21 #include "group-interface.hh"
22
23 /**
24   put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
25   rehearsal marks.
26  */
27 class Mark_engraver : public Engraver
28 {
29 public:
30   TRANSLATOR_DECLARATIONS(Mark_engraver);
31 protected:
32   Item* text_p_;
33   
34 protected:
35   virtual void stop_translation_timestep ();
36   virtual void acknowledge_grob (Grob_info);
37   void create_items (Request*);
38   virtual bool try_music (Music *req_l);
39   virtual void start_translation_timestep ();
40   virtual void process_music ();
41   
42 private:
43   Mark_req * mark_req_l_;
44 };
45
46
47
48
49
50 Mark_engraver::Mark_engraver ()
51 {
52   text_p_ =0;
53   mark_req_l_ = 0;
54 }
55
56 void
57 Mark_engraver::acknowledge_grob (Grob_info inf)
58 {
59   Grob * s = inf.grob_l_;
60  if (text_p_ && Bar::has_interface (s))
61     {
62       /*
63         Ugh. Figure out how to do this right at beginning of line, (without
64         creating class Bar_script : public Item).
65       */
66       text_p_->set_parent (s, X_AXIS);
67     }
68 }
69
70 void 
71 Mark_engraver::stop_translation_timestep ()
72 {
73   if (text_p_)
74     {
75       text_p_->set_grob_property ("side-support-elements" , get_property ("stavesFound"));
76       typeset_grob (text_p_);
77       text_p_ =0;
78     }
79 }
80
81
82 void
83 Mark_engraver::create_items (Request *rq)
84 {
85   if (text_p_)
86     return;
87
88   SCM s = get_property ("RehearsalMark");
89   text_p_ = new Item (s);
90
91
92   Side_position_interface::set_axis (text_p_, Y_AXIS);
93
94   announce_grob (text_p_, rq);
95 }
96
97
98 void
99 Mark_engraver::start_translation_timestep ()
100 {
101   mark_req_l_ = 0;
102 }
103
104
105 bool
106 Mark_engraver::try_music (Music* r_l)
107 {
108   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
109     {
110       if (mark_req_l_ && mr->equal_b (mark_req_l_))
111         return true;
112       if (mark_req_l_)
113         return false;
114       mark_req_l_ = mr;
115       return true;
116     }
117   return false;
118 }
119
120
121 /*
122
123   TODO: make the increment function in Scheme.
124
125 */
126 void
127 Mark_engraver::process_music ()
128 {
129   if (mark_req_l_)
130     {
131       create_items (mark_req_l_);
132
133       String t;
134
135       /*
136         automatic marks.
137        */
138       
139       SCM m = mark_req_l_->get_mus_property ("label");
140       if (gh_pair_p (m)) // markup text
141         text_p_->set_grob_property ("text",m);
142       else 
143         {
144           if (!gh_string_p (m)) 
145             m =  get_property ("rehearsalMark");
146           ;
147           
148           if (gh_number_p (m))
149             {
150               int mark_count = gh_scm2int (m);
151               t = to_str (mark_count);
152               mark_count ++;
153               m = gh_int2scm (mark_count);
154             }
155           else if (gh_string_p (m))
156             {
157               t = ly_scm2string (m);
158               String next;
159               if (t.length_i ())
160                 {
161                   char c = t[0];
162                   c++;
163                   next = to_str (c);
164                 }
165               m = ly_str02scm (next.ch_C ());
166             }
167           else
168             {
169               m = gh_int2scm (1);
170             }
171           
172           daddy_trans_l_->set_property ("rehearsalMark", m);
173           
174           text_p_->set_grob_property ("text",
175                                       ly_str02scm (t.ch_C ()));
176
177           String style = "mark";
178           for (int i=0; i < t.length_i (); i++)
179             {
180               if (!isdigit (t[i])) 
181                 {
182                   style = "large";
183                   break;
184                 }
185             }
186           SCM st = ly_symbol2scm (style.ch_C ());
187           text_p_->set_grob_property ("font-style",  st);
188         }
189
190     }
191 }
192
193 ENTER_DESCRIPTION(Mark_engraver,
194 /* descr */       "",
195 /* creats*/       "RehearsalMark",
196 /* acks  */       "bar-line-interface", 
197 /* reads */       "rehearsalMark stavesFound",
198 /* write */       "");