Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / mark-engraver.cc
blob7720dd2569aef40899c1feef3cf7ca0718021bef
1 /*
2 mark-engraver.cc -- implement Mark_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 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 Item *final_text_;
36 Stream_event *mark_ev_;
38 public:
39 TRANSLATOR_DECLARATIONS (Mark_engraver);
41 protected:
42 void process_music ();
43 void start_translation_timestep ();
44 void stop_translation_timestep ();
45 virtual void finalize ();
47 DECLARE_TRANSLATOR_LISTENER (mark);
48 DECLARE_ACKNOWLEDGER (break_alignment);
51 Mark_engraver::Mark_engraver ()
53 text_ = 0;
54 final_text_ = 0;
55 mark_ev_ = 0;
58 void
59 Mark_engraver::acknowledge_break_alignment (Grob_info inf)
61 Grob *s = inf.grob ();
62 if (text_
63 && dynamic_cast<Item *> (s))
64 text_->set_parent (s, X_AXIS);
67 void
68 Mark_engraver::start_translation_timestep ()
70 final_text_ = 0;
73 void
74 Mark_engraver::stop_translation_timestep ()
76 if (text_)
78 text_->set_object ("side-support-elements",
79 grob_list_to_grob_array (get_property ("stavesFound")));
80 final_text_ = text_;
81 text_ = 0;
83 mark_ev_ = 0;
86 void
87 Mark_engraver::finalize ()
89 if (final_text_)
90 final_text_->set_property ("break-visibility",
91 scm_c_make_vector (3, SCM_BOOL_T));
92 final_text_ = 0;
95 void
96 Mark_engraver::create_items (Stream_event *ev)
98 if (text_)
99 return;
101 text_ = make_item ("RehearsalMark", ev->self_scm ());
104 IMPLEMENT_TRANSLATOR_LISTENER (Mark_engraver, mark);
105 void
106 Mark_engraver::listen_mark (Stream_event *ev)
108 ASSIGN_EVENT_ONCE (mark_ev_, ev);
112 TODO: make the increment function in Scheme.
114 void
115 Mark_engraver::process_music ()
117 if (mark_ev_)
119 create_items (mark_ev_);
122 automatic marks.
125 SCM m = mark_ev_->get_property ("label");
126 SCM proc = get_property ("markFormatter");
127 if (!Text_interface::is_markup (m)
128 && ly_is_procedure (proc))
130 if (!scm_is_number (m))
131 m = get_property ("rehearsalMark");
133 if (scm_integer_p (m) == SCM_BOOL_T
134 && scm_exact_p (m) == SCM_BOOL_T)
136 int mark_count = scm_to_int (m);
137 mark_count++;
138 context ()->set_property ("rehearsalMark",
139 scm_from_int (mark_count));
142 if (scm_is_number (m))
143 m = scm_call_2 (proc, m, context ()->self_scm ());
144 else
145 /* FIXME: constant error message. */
146 warning (_ ("rehearsalMark must have integer value"));
149 if (Text_interface::is_markup (m))
150 text_->set_property ("text", m);
151 else
152 warning (_ ("mark label must be a markup object"));
156 ADD_ACKNOWLEDGER (Mark_engraver, break_alignment);
158 ADD_TRANSLATOR (Mark_engraver,
159 /* doc */
160 "Create @code{RehearsalMark} objects. It puts them on top of"
161 " all staves (which is taken from the property"
162 " @code{stavesFound}). If moving this engraver to a different"
163 " context, @ref{Staff_collecting_engraver} must move along,"
164 " otherwise all marks end up on the same Y@tie{}location.",
166 /* create */
167 "RehearsalMark ",
169 /* read */
170 "markFormatter "
171 "rehearsalMark "
172 "stavesFound ",
174 /* write */