Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / staff-symbol-engraver.cc
blob5d70855273e152e87b134a8fd2f72f0e5694ff24
1 /*
2 staff-symbol-engraver.cc -- implement Staff_symbol_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "engraver.hh"
10 #include "international.hh"
11 #include "spanner.hh"
12 #include "stream-event.hh"
13 #include "warn.hh"
15 #include "translator.icc"
17 class Staff_symbol_engraver : public Engraver
19 public:
20 TRANSLATOR_DECLARATIONS (Staff_symbol_engraver);
22 protected:
23 Drul_array<Stream_event *> span_events_;
24 Spanner *span_;
25 Spanner *finished_span_;
26 bool first_start_;
28 protected:
29 virtual void start_spanner ();
30 virtual void stop_spanner ();
32 void stop_translation_timestep ();
33 virtual ~Staff_symbol_engraver ();
34 DECLARE_ACKNOWLEDGER (grob);
35 DECLARE_TRANSLATOR_LISTENER (staff_span);
36 virtual void finalize ();
37 void process_music ();
40 Staff_symbol_engraver::~Staff_symbol_engraver ()
42 assert (!span_);
45 Staff_symbol_engraver::Staff_symbol_engraver ()
47 finished_span_ = 0;
48 first_start_ = true;
49 span_ = 0;
50 span_events_[LEFT] = 0;
51 span_events_[RIGHT] = 0;
54 IMPLEMENT_TRANSLATOR_LISTENER (Staff_symbol_engraver, staff_span);
55 void
56 Staff_symbol_engraver::listen_staff_span (Stream_event *ev)
58 Direction d = to_dir (ev->get_property ("span-direction"));
59 if (d)
60 ASSIGN_EVENT_ONCE (span_events_[d], ev);
61 else
62 programming_error (_ ("staff-span event has no direction"));
65 void
66 Staff_symbol_engraver::process_music ()
68 if (span_events_[STOP])
70 finished_span_ = span_;
71 span_ = 0;
72 if (first_start_)
73 first_start_ = false;
76 if (span_events_[START]
77 || (first_start_ && !span_events_[STOP]))
78 start_spanner ();
81 void
82 Staff_symbol_engraver::start_spanner ()
84 if (!span_)
86 span_ = make_spanner ("StaffSymbol", SCM_EOL);
87 span_->set_bound (LEFT,
88 unsmob_grob (get_property ("currentCommandColumn")));
92 void
93 Staff_symbol_engraver::stop_spanner ()
95 if (!finished_span_)
96 return;
98 if (!finished_span_->get_bound (RIGHT))
99 finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
101 announce_end_grob (finished_span_,
102 span_events_[STOP]
103 ? span_events_[STOP]->self_scm ()
104 : SCM_EOL);
106 finished_span_ = 0;
109 void
110 Staff_symbol_engraver::stop_translation_timestep ()
112 if ((span_events_[START] || first_start_)
113 && span_)
115 first_start_ = false;
118 span_events_[START] = 0;
119 span_events_[STOP] = 0;
120 stop_spanner ();
123 void
124 Staff_symbol_engraver::finalize ()
126 finished_span_ = span_;
127 span_ = 0;
128 stop_spanner ();
132 Todo: staff-symbol-referencer iface.
134 void
135 Staff_symbol_engraver::acknowledge_grob (Grob_info s)
138 Perhaps should try to take SeparationItem as bound of the staff
139 symbol?
141 if (span_ || finished_span_)
143 Spanner *my = span_ ? span_ : finished_span_;
144 s.grob ()->set_object ("staff-symbol", my->self_scm ());
148 ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
150 ADD_TRANSLATOR (Staff_symbol_engraver,
151 /* doc */
152 "Create the constellation of five (default) staff lines.",
154 /* create */
155 "StaffSymbol ",
157 /* read */
160 /* write */