]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
``slikken kreng''
[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_;
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);
39   virtual void start_translation_timestep ();
40   virtual void process_music ();
41   
42 private:
43   Mark_req * mark_req_;
44 };
45
46
47
48
49
50 Mark_engraver::Mark_engraver ()
51 {
52   text_ =0;
53   mark_req_ = 0;
54 }
55
56 void
57 Mark_engraver::acknowledge_grob (Grob_info inf)
58 {
59   Grob * s = inf.grob_;
60   if (text_ && 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_->set_parent (s, X_AXIS);
67     }
68 }
69
70 void 
71 Mark_engraver::stop_translation_timestep ()
72 {
73   if (text_)
74     {
75       text_->set_grob_property ("side-support-elements" , get_property ("stavesFound"));
76       typeset_grob (text_);
77       text_ =0;
78     }
79 }
80
81
82 void
83 Mark_engraver::create_items (Request *rq)
84 {
85   if (text_)
86     return;
87
88   SCM s = get_property ("RehearsalMark");
89   text_ = new Item (s);
90
91
92   announce_grob(text_, rq->self_scm());
93 }
94
95
96 void
97 Mark_engraver::start_translation_timestep ()
98 {
99   mark_req_ = 0;
100 }
101
102
103 bool
104 Mark_engraver::try_music (Music* r)
105 {
106   if (Mark_req *mr = dynamic_cast <Mark_req *> (r))
107     {
108       if (mark_req_ && mr->equal_b (mark_req_))
109         return true;
110       if (mark_req_)
111         return false;
112       mark_req_ = 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_)
128     {
129       create_items (mark_req_);
130
131       String t;
132
133       /*
134         automatic marks.
135        */
136       
137       SCM m = mark_req_->get_mus_property ("label");
138       if (gh_pair_p (m)) // markup text
139         text_->set_grob_property ("text",m);
140       else 
141         {
142           if (!gh_string_p (m) && !gh_number_p (m)) 
143             m =  get_property ("rehearsalMark");
144           
145           if (gh_number_p (m))
146             {
147               int mark_count = gh_scm2int (m);
148               t = to_string (mark_count);
149               mark_count ++;
150               m = gh_int2scm (mark_count);
151             }
152           else if (gh_string_p (m))
153             {
154               t = ly_scm2string (m);
155               String next;
156               if (t.length ())
157                 {
158                   char c = t[0];
159                   c++;
160                   next = to_string (c);
161                 }
162               m = ly_str02scm (next.to_str0 ());
163             }
164           else
165             {
166               m = gh_int2scm (1);
167             }
168           
169           daddy_trans_->set_property ("rehearsalMark", m);
170           
171           text_->set_grob_property ("text",
172                                       ly_str02scm (t.to_str0 ()));
173
174           String style = "mark-number";
175           for (int i=0; i < t.length (); i++)
176             {
177               if (!isdigit (t[i])) 
178                 {
179                   style = "mark-letter";
180                   break;
181                 }
182             }
183           SCM st = ly_symbol2scm (style.to_str0 ());
184           text_->set_grob_property ("font-style",  st);
185         }
186
187     }
188 }
189
190 ENTER_DESCRIPTION(Mark_engraver,
191 /* descr */       "",
192 /* creats*/       "RehearsalMark",
193 /* acks  */       "bar-line-interface", 
194 /* reads */       "rehearsalMark stavesFound",
195 /* write */       "");