]> git.donarmstrong.com Git - lilypond.git/blob - lily/mark-engraver.cc
*** empty log message ***
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <ctype.h>
10
11 #include "bar-line.hh"
12 #include "context.hh"
13 #include "engraver-group-engraver.hh"
14 #include "engraver.hh"
15 #include "item.hh"
16 #include "warn.hh"
17 #include "text-item.hh"
18
19 /**
20   put stuff over or next to  bars.  Examples: bar numbers, marginal notes,
21   rehearsal marks.
22  */
23 class Mark_engraver : public Engraver
24 {
25 public:
26   TRANSLATOR_DECLARATIONS (Mark_engraver);
27 protected:
28   Item* text_;
29   
30 protected:
31   virtual void stop_translation_timestep ();
32   virtual void acknowledge_grob (Grob_info);
33   void create_items (Music*);
34   virtual bool try_music (Music *ev);
35   virtual void process_music ();
36   
37 private:
38   Music * mark_ev_;
39 };
40
41
42
43
44
45 Mark_engraver::Mark_engraver ()
46 {
47   text_ =0;
48   mark_ev_ = 0;
49 }
50
51 void
52 Mark_engraver::acknowledge_grob (Grob_info inf)
53 {
54   Grob * s = inf.grob_;
55   if (text_ && Bar_line::has_interface (s))
56     {
57       /*
58       TODO: make this configurable. RehearsalMark cannot be
59       break-aligned, since the width of the object should not be taken
60       into alignment considerations.
61       */
62       text_->set_parent (s, X_AXIS);
63     }
64 }
65
66 void 
67 Mark_engraver::stop_translation_timestep ()
68 {
69   if (text_)
70     {
71       text_->set_property ("side-support-elements" , get_property ("stavesFound"));
72       typeset_grob (text_);
73       text_ =0;
74     }
75   mark_ev_ = 0;
76 }
77
78
79 void
80 Mark_engraver::create_items (Music *ev)
81 {
82   if (text_)
83     return;
84
85   text_ = make_item ("RehearsalMark");
86   announce_grob (text_, ev->self_scm ());
87 }
88
89
90 bool
91 Mark_engraver::try_music (Music* r)
92 {
93   mark_ev_ = r;
94   return true;
95 }
96
97
98 /*
99   TODO: make the increment function in Scheme.
100 */
101 void
102 Mark_engraver::process_music ()
103 {
104   if (mark_ev_)
105     {
106       create_items (mark_ev_);
107
108       /*
109         automatic marks.
110        */
111
112       
113       SCM m = mark_ev_->get_property ("label");
114       SCM proc = get_property ("markFormatter");
115       if (!Text_item::markup_p (m) &&
116           gh_procedure_p (proc))
117         {
118           if (!gh_number_p (m)) 
119             m =  get_property ("rehearsalMark");
120
121           if (scm_integer_p (m) == SCM_BOOL_T
122               && scm_exact_p (m) == SCM_BOOL_T)
123             {
124               int mark_count = gh_scm2int (m);
125               mark_count ++;
126               daddy_context_->set_property ("rehearsalMark",
127                                             gh_int2scm (mark_count));
128             }
129
130           if (gh_number_p (m))
131             m = scm_call_2 (proc, m, daddy_context_->self_scm ());
132           else
133             warning ("rehearsalMark does not have integer value.");
134         }
135
136       if (Text_item::markup_p (m))
137         text_->set_property ("text", m);
138       else
139         warning ("Mark label should be markup object.");
140     }
141 }
142
143 ENTER_DESCRIPTION (Mark_engraver,
144 /* descr */       "",
145 /* creats*/       "RehearsalMark",
146 /* accepts */     "mark-event",
147 /* acks  */       "bar-line-interface",
148 /* reads */       "rehearsalMark markFormatter stavesFound",
149 /* write */       "");