]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
nu wel 58
[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-line.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_line::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   announce_grob(text_p_, rq->self_scm());
93 }
94
95
96 void
97 Mark_engraver::start_translation_timestep ()
98 {
99   mark_req_l_ = 0;
100 }
101
102
103 bool
104 Mark_engraver::try_music (Music* r_l)
105 {
106   if (Mark_req *mr = dynamic_cast <Mark_req *> (r_l))
107     {
108       if (mark_req_l_ && mr->equal_b (mark_req_l_))
109         return true;
110       if (mark_req_l_)
111         return false;
112       mark_req_l_ = mr;
113       return true;
114     }
115   return false;
116 }
117
118
119 /*
120
121   TODO: make the increment function in Scheme.
122
123 */
124 void
125 Mark_engraver::process_music ()
126 {
127   if (mark_req_l_)
128     {
129       create_items (mark_req_l_);
130
131       String t;
132
133       /*
134         automatic marks.
135        */
136       
137       SCM m = mark_req_l_->get_mus_property ("label");
138       if (gh_pair_p (m)) // markup text
139         text_p_->set_grob_property ("text",m);
140       else 
141         {
142           if (!gh_string_p (m)) 
143             m =  get_property ("rehearsalMark");
144           ;
145           
146           if (gh_number_p (m))
147             {
148               int mark_count = gh_scm2int (m);
149               t = to_str (mark_count);
150               mark_count ++;
151               m = gh_int2scm (mark_count);
152             }
153           else if (gh_string_p (m))
154             {
155               t = ly_scm2string (m);
156               String next;
157               if (t.length_i ())
158                 {
159                   char c = t[0];
160                   c++;
161                   next = to_str (c);
162                 }
163               m = ly_str02scm (next.ch_C ());
164             }
165           else
166             {
167               m = gh_int2scm (1);
168             }
169           
170           daddy_trans_l_->set_property ("rehearsalMark", m);
171           
172           text_p_->set_grob_property ("text",
173                                       ly_str02scm (t.ch_C ()));
174
175           String style = "mark-number";
176           for (int i=0; i < t.length_i (); i++)
177             {
178               if (!isdigit (t[i])) 
179                 {
180                   style = "mark-letter";
181                   break;
182                 }
183             }
184           SCM st = ly_symbol2scm (style.ch_C ());
185           text_p_->set_grob_property ("font-style",  st);
186         }
187
188     }
189 }
190
191 ENTER_DESCRIPTION(Mark_engraver,
192 /* descr */       "",
193 /* creats*/       "RehearsalMark",
194 /* acks  */       "bar-line-interface", 
195 /* reads */       "rehearsalMark stavesFound",
196 /* write */       "");