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