]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
* input/trip.ly (fugaIILeft): add arpeggio
[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 (Music*);
38   virtual bool try_music (Music *req);
39   virtual void start_translation_timestep ();
40   virtual void process_music ();
41   
42 private:
43   Music * 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 (Music *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   mark_req_ = r;
107   return true;
108 }
109
110
111 /*
112
113   TODO: make the increment function in Scheme.
114
115 */
116 void
117 Mark_engraver::process_music ()
118 {
119   if (mark_req_)
120     {
121       create_items (mark_req_);
122
123       String t;
124
125       /*
126         automatic marks.
127        */
128       
129       SCM m = mark_req_->get_mus_property ("label");
130       if (gh_pair_p (m)) // markup text
131         text_->set_grob_property ("text",m);
132       else 
133         {
134           if (!gh_string_p (m) && !gh_number_p (m)) 
135             m =  get_property ("rehearsalMark");
136           
137           if (gh_number_p (m))
138             {
139               int mark_count = gh_scm2int (m);
140               t = to_string (mark_count);
141               mark_count ++;
142               m = gh_int2scm (mark_count);
143             }
144           else if (gh_string_p (m))
145             {
146               t = ly_scm2string (m);
147               String next;
148               if (t.length ())
149                 {
150                   char c = t[0];
151                   c++;
152                   next = to_string (c);
153                 }
154               m = scm_makfrom0str (next.to_str0 ());
155             }
156           else
157             {
158               m = gh_int2scm (1);
159             }
160           
161           daddy_trans_->set_property ("rehearsalMark", m);
162           
163           text_->set_grob_property ("text",
164                                       scm_makfrom0str (t.to_str0 ()));
165
166           String style = "mark-number";
167           for (int i=0; i < t.length (); i++)
168             {
169               if (!isdigit (t[i])) 
170                 {
171                   style = "mark-letter";
172                   break;
173                 }
174             }
175           SCM st = ly_symbol2scm (style.to_str0 ());
176           text_->set_grob_property ("font-style",  st);
177         }
178
179     }
180 }
181
182 ENTER_DESCRIPTION(Mark_engraver,
183 /* descr */       "",
184 /* creats*/       "RehearsalMark",
185 /* accepts */     "mark-event",
186 /* acks  */       "bar-line-interface",
187 /* reads */       "rehearsalMark stavesFound",
188 /* write */       "");