]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
(process_music): only set rehearsalMark if
[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--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <ctype.h>
10 #include "bar-line.hh"
11
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 #include "text-item.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_;
34   
35 protected:
36   virtual void stop_translation_timestep ();
37   virtual void acknowledge_grob (Grob_info);
38   void create_items (Music*);
39   virtual bool try_music (Music *req);
40   virtual void start_translation_timestep ();
41   virtual void process_music ();
42   
43 private:
44   Music * mark_req_;
45 };
46
47
48
49
50
51 Mark_engraver::Mark_engraver ()
52 {
53   text_ =0;
54   mark_req_ = 0;
55 }
56
57 void
58 Mark_engraver::acknowledge_grob (Grob_info inf)
59 {
60   Grob * s = inf.grob_;
61   if (text_ && Bar_line::has_interface (s))
62     {
63       /*
64       TODO: make this configurable. RehearsalMark cannot be
65       break-aligned, since the width of the object should not be taken
66       into alignment considerations.
67       */
68       text_->set_parent (s, X_AXIS);
69     }
70 }
71
72 void 
73 Mark_engraver::stop_translation_timestep ()
74 {
75   if (text_)
76     {
77       text_->set_grob_property ("side-support-elements" , get_property ("stavesFound"));
78       typeset_grob (text_);
79       text_ =0;
80     }
81 }
82
83
84 void
85 Mark_engraver::create_items (Music *rq)
86 {
87   if (text_)
88     return;
89
90   text_ = new Item (get_property ("RehearsalMark"));
91   announce_grob(text_, rq->self_scm());
92 }
93
94
95 void
96 Mark_engraver::start_translation_timestep ()
97 {
98   mark_req_ = 0;
99 }
100
101
102 bool
103 Mark_engraver::try_music (Music* r)
104 {
105   mark_req_ = r;
106   return true;
107 }
108
109
110 /*
111
112   TODO: make the increment function in Scheme.
113
114
115   TODO: junk the number type for rehearsalMark
116 */
117 void
118 Mark_engraver::process_music ()
119 {
120   if (mark_req_)
121     {
122       create_items (mark_req_);
123
124       /*
125         automatic marks.
126        */
127       
128       SCM m = mark_req_->get_mus_property ("label");
129       if (Text_item::markup_p (m))
130         {
131           text_->set_grob_property ("text",m);
132         }
133       else 
134         {
135           String t ;
136           
137           if (!gh_string_p (m) && !gh_number_p (m)) 
138             m =  get_property ("rehearsalMark");
139           
140           if (gh_number_p (m))
141             {
142               int mark_count = gh_scm2int (m);
143               t = to_string (mark_count);
144               mark_count ++;
145               m = gh_int2scm (mark_count);
146             }
147           else if (gh_string_p (m))
148             {
149               t = ly_scm2string (m);
150               String next;
151               if (t.length ())
152                 {
153                   char c = t[0];
154                   c++;
155                   t = to_string (c);
156                 }
157               m = scm_makfrom0str (t.to_str0 ());
158             }
159           else
160             {
161               m = gh_int2scm (1);
162               t = to_string (1);
163             }
164           
165           text_->set_grob_property ("text",
166                                     scm_makfrom0str (t.to_str0 ()));
167
168           SCM series = SCM_EOL;
169           SCM family = ly_symbol2scm ("number");
170           for (int i=0; i < t.length (); i++)
171             {
172               if (!isdigit (t[i])) 
173                 {
174                   /*
175                     This looks strange, since \mark "A"
176                     isn't printed in bold.
177                     
178                    */
179                   
180                   // series = ly_symbol2scm ("bold");
181                   family = ly_symbol2scm ("roman");
182                   break;
183                 }
184             }
185           if (gh_symbol_p (series))
186             text_->set_grob_property ("font-series",  series);
187           if (gh_symbol_p (family))
188             text_->set_grob_property ("font-family",  family);
189         }
190
191       if (gh_number_p (m) || gh_string_p (m))
192         daddy_trans_->set_property ("rehearsalMark", m);
193     }
194 }
195
196 ENTER_DESCRIPTION(Mark_engraver,
197 /* descr */       "",
198 /* creats*/       "RehearsalMark",
199 /* accepts */     "mark-event",
200 /* acks  */       "bar-line-interface",
201 /* reads */       "rehearsalMark stavesFound",
202 /* write */       "");