Use `transform'.
[lilypond.git] / lily / mark-engraver.cc
blob3b12e46e43d1be36dfdcfa606cd4dc677c07f8d0
1 /*
2 mark-engraver.cc -- implement Mark_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include <cctype>
10 using namespace std;
12 #include "engraver.hh"
14 #include "axis-group-interface.hh"
15 #include "bar-line.hh"
16 #include "context.hh"
17 #include "grob-array.hh"
18 #include "international.hh"
19 #include "item.hh"
20 #include "stream-event.hh"
21 #include "text-interface.hh"
22 #include "warn.hh"
24 #include "translator.icc"
26 /**
27 put stuff over or next to bars. Examples: bar numbers, marginal notes,
28 rehearsal marks.
30 class Mark_engraver : public Engraver
33 void create_items (Stream_event *);
34 Item *text_;
35 Stream_event *mark_ev_;
37 public:
38 TRANSLATOR_DECLARATIONS (Mark_engraver);
40 protected:
41 void process_music ();
42 void stop_translation_timestep ();
44 DECLARE_TRANSLATOR_LISTENER (mark);
45 DECLARE_ACKNOWLEDGER (break_alignment);
46 DECLARE_ACKNOWLEDGER (break_aligned);
49 Mark_engraver::Mark_engraver ()
51 text_ = 0;
52 mark_ev_ = 0;
56 This is a flawed approach, since various break-aligned objects may
57 not appear depending on key signature etc.
59 We keep it in case someone puts the engraver in a lower context than score.
61 void
62 Mark_engraver::acknowledge_break_aligned (Grob_info inf)
64 Grob *s = inf.grob ();
65 if (text_
66 && !text_->get_parent (X_AXIS)
67 && (text_->get_property_data ("break-align-symbol")
68 == s->get_property_data ("break-align-symbol"))
69 && Axis_group_interface::has_interface (s))
72 RehearsalMark cannot be break-aligned, since the width of the
73 object should not be taken into alignment considerations.
75 text_->set_parent (s, X_AXIS);
79 void
80 Mark_engraver::acknowledge_break_alignment (Grob_info inf)
82 Grob *s = inf.grob ();
83 if (text_
84 && dynamic_cast<Item *> (s))
86 text_->set_parent (s, X_AXIS);
91 void
92 Mark_engraver::stop_translation_timestep ()
94 if (text_)
96 text_->set_object ("side-support-elements",
97 grob_list_to_grob_array (get_property ("stavesFound")));
98 text_ = 0;
100 mark_ev_ = 0;
103 void
104 Mark_engraver::create_items (Stream_event *ev)
106 if (text_)
107 return;
109 text_ = make_item ("RehearsalMark", ev->self_scm ());
112 IMPLEMENT_TRANSLATOR_LISTENER (Mark_engraver, mark);
113 void
114 Mark_engraver::listen_mark (Stream_event *ev)
116 ASSIGN_EVENT_ONCE (mark_ev_, ev);
120 TODO: make the increment function in Scheme.
122 void
123 Mark_engraver::process_music ()
125 if (mark_ev_)
127 create_items (mark_ev_);
130 automatic marks.
133 SCM m = mark_ev_->get_property ("label");
134 SCM proc = get_property ("markFormatter");
135 if (!Text_interface::is_markup (m)
136 && ly_is_procedure (proc))
138 if (!scm_is_number (m))
139 m = get_property ("rehearsalMark");
141 if (scm_integer_p (m) == SCM_BOOL_T
142 && scm_exact_p (m) == SCM_BOOL_T)
144 int mark_count = scm_to_int (m);
145 mark_count++;
146 context ()->set_property ("rehearsalMark",
147 scm_from_int (mark_count));
150 if (scm_is_number (m))
151 m = scm_call_2 (proc, m, context ()->self_scm ());
152 else
153 /* FIXME: constant error message. */
154 warning (_ ("rehearsalMark must have integer value"));
157 if (Text_interface::is_markup (m))
158 text_->set_property ("text", m);
159 else
160 warning (_ ("mark label must be a markup object"));
164 ADD_ACKNOWLEDGER (Mark_engraver, break_aligned);
165 ADD_ACKNOWLEDGER (Mark_engraver, break_alignment);
167 ADD_TRANSLATOR (Mark_engraver,
168 /* doc */ "This engraver will create RehearsalMark objects. "
169 "It puts them on top of all staves (which is taken from "
170 "the property @code{stavesFound}). If moving this engraver "
171 "to a different context, "
172 "@ref{Staff_collecting_engraver} must move along, otherwise all marks"
173 "end up on the same Y-location",
175 /* create */ "RehearsalMark",
176 /* read */
177 "markFormatter "
178 "rehearsalMark "
179 "stavesFound ",
181 /* write */ "");