Merge branch 'fret-diagram-details'
[lilypond/csorensen.git] / lily / mark-engraver.cc
blob7ba13d49a454802a8838a5787bdf193bfa2be8e6
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);
48 Mark_engraver::Mark_engraver ()
50 text_ = 0;
51 mark_ev_ = 0;
54 void
55 Mark_engraver::acknowledge_break_alignment (Grob_info inf)
57 Grob *s = inf.grob ();
58 if (text_
59 && dynamic_cast<Item *> (s))
61 text_->set_parent (s, X_AXIS);
66 void
67 Mark_engraver::stop_translation_timestep ()
69 if (text_)
71 text_->set_object ("side-support-elements",
72 grob_list_to_grob_array (get_property ("stavesFound")));
73 text_ = 0;
75 mark_ev_ = 0;
78 void
79 Mark_engraver::create_items (Stream_event *ev)
81 if (text_)
82 return;
84 text_ = make_item ("RehearsalMark", ev->self_scm ());
87 IMPLEMENT_TRANSLATOR_LISTENER (Mark_engraver, mark);
88 void
89 Mark_engraver::listen_mark (Stream_event *ev)
91 ASSIGN_EVENT_ONCE (mark_ev_, ev);
95 TODO: make the increment function in Scheme.
97 void
98 Mark_engraver::process_music ()
100 if (mark_ev_)
102 create_items (mark_ev_);
105 automatic marks.
108 SCM m = mark_ev_->get_property ("label");
109 SCM proc = get_property ("markFormatter");
110 if (!Text_interface::is_markup (m)
111 && ly_is_procedure (proc))
113 if (!scm_is_number (m))
114 m = get_property ("rehearsalMark");
116 if (scm_integer_p (m) == SCM_BOOL_T
117 && scm_exact_p (m) == SCM_BOOL_T)
119 int mark_count = scm_to_int (m);
120 mark_count++;
121 context ()->set_property ("rehearsalMark",
122 scm_from_int (mark_count));
125 if (scm_is_number (m))
126 m = scm_call_2 (proc, m, context ()->self_scm ());
127 else
128 /* FIXME: constant error message. */
129 warning (_ ("rehearsalMark must have integer value"));
132 if (Text_interface::is_markup (m))
133 text_->set_property ("text", m);
134 else
135 warning (_ ("mark label must be a markup object"));
139 ADD_ACKNOWLEDGER (Mark_engraver, break_alignment);
141 ADD_TRANSLATOR (Mark_engraver,
142 /* doc */
143 "Create @code{RehearsalMark} objects. It puts them on top of"
144 " all staves (which is taken from the property"
145 " @code{stavesFound}). If moving this engraver to a different"
146 " context, @ref{Staff_collecting_engraver} must move along,"
147 " otherwise all marks end up on the same Y@tie{}location.",
149 /* create */
150 "RehearsalMark ",
152 /* read */
153 "markFormatter "
154 "rehearsalMark "
155 "stavesFound ",
157 /* write */