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