Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / slur-engraver.cc
blob13ca895e2e1e52a586efbbaac3bf96ebda84ec19
1 /*
2 slur-engraver.cc -- implement Slur_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"
11 #include "context.hh"
12 #include "directional-element-interface.hh"
13 #include "international.hh"
14 #include "note-column.hh"
15 #include "slur.hh"
16 #include "spanner.hh"
17 #include "stream-event.hh"
18 #include "warn.hh"
20 #include "translator.icc"
24 NOTE NOTE NOTE
26 This is largely similar to Phrasing_slur_engraver. Check if fixes
27 apply there too.
29 (on principle, engravers don't use inheritance for code sharing)
34 It is possible that a slur starts and ends on the same note. At
35 least, it is for phrasing slurs: a note can be both beginning and
36 ending of a phrase.
38 class Slur_engraver : public Engraver
40 Drul_array<Stream_event *> events_;
41 Stream_event *running_slur_start_;
42 vector<Grob*> slurs_;
43 vector<Grob*> end_slurs_;
45 void set_melisma (bool);
47 protected:
48 DECLARE_TRANSLATOR_LISTENER (slur);
49 DECLARE_ACKNOWLEDGER (accidental);
50 DECLARE_ACKNOWLEDGER (fingering);
51 DECLARE_ACKNOWLEDGER (note_column);
52 DECLARE_ACKNOWLEDGER (script);
53 DECLARE_ACKNOWLEDGER (text_script);
54 DECLARE_ACKNOWLEDGER (tie);
55 DECLARE_ACKNOWLEDGER (tuplet_number);
57 void acknowledge_extra_object (Grob_info);
58 void stop_translation_timestep ();
59 void process_music ();
61 virtual void finalize ();
64 public:
65 TRANSLATOR_DECLARATIONS (Slur_engraver);
68 Slur_engraver::Slur_engraver ()
70 events_[START] = events_[STOP] = 0;
73 IMPLEMENT_TRANSLATOR_LISTENER (Slur_engraver, slur);
74 void
75 Slur_engraver::listen_slur (Stream_event *ev)
77 Direction d = to_dir (ev->get_property ("span-direction"));
78 if (d == START)
79 ASSIGN_EVENT_ONCE (events_[START], ev);
80 else if (d == STOP)
81 ASSIGN_EVENT_ONCE (events_[STOP], ev);
82 else ev->origin ()->warning (_f ("direction of %s invalid: %d",
83 "slur-event", int (d)));
86 void
87 Slur_engraver::set_melisma (bool m)
89 context ()->set_property ("slurMelismaBusy", m ? SCM_BOOL_T : SCM_BOOL_F);
92 void
93 Slur_engraver::acknowledge_note_column (Grob_info info)
95 Grob *e = info.grob ();
96 for (vsize i = slurs_.size (); i--;)
97 Slur::add_column (slurs_[i], e);
98 for (vsize i = end_slurs_.size (); i--;)
99 Slur::add_column (end_slurs_[i], e);
102 void
103 Slur_engraver::acknowledge_extra_object (Grob_info info)
105 Slur::auxiliary_acknowledge_extra_object (info, slurs_, end_slurs_);
108 void
109 Slur_engraver::acknowledge_accidental (Grob_info info)
111 acknowledge_extra_object (info);
114 void
115 Slur_engraver::acknowledge_fingering (Grob_info info)
117 acknowledge_extra_object (info);
120 void
121 Slur_engraver::acknowledge_tuplet_number (Grob_info info)
123 acknowledge_extra_object (info);
127 void
128 Slur_engraver::acknowledge_script (Grob_info info)
130 if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
131 acknowledge_extra_object (info);
134 void
135 Slur_engraver::acknowledge_text_script (Grob_info info)
137 acknowledge_extra_object (info);
140 void
141 Slur_engraver::acknowledge_tie (Grob_info info)
143 acknowledge_extra_object (info);
146 void
147 Slur_engraver::finalize ()
149 if (slurs_.size ())
151 slurs_[0]->warning (_ ("unterminated slur"));
152 for (vsize i = 0; i < slurs_.size (); i++)
153 slurs_[i]->suicide ();
157 void
158 Slur_engraver::process_music ()
160 if (events_[STOP])
162 if (slurs_.size () == 0)
163 events_[STOP]->origin ()->warning (_ ("cannot end slur"));
166 end_slurs_ = slurs_;
167 slurs_.clear ();
170 if (events_[START] && slurs_.empty ())
172 Stream_event *ev = events_[START];
174 bool double_slurs = to_boolean (get_property ("doubleSlurs"));
176 Grob *slur = make_spanner ("Slur", events_[START]->self_scm ());
177 Direction updown = to_dir (ev->get_property ("direction"));
178 if (updown && !double_slurs)
179 set_grob_direction (slur, updown);
181 slurs_.push_back (slur);
183 if (double_slurs)
185 set_grob_direction (slur, DOWN);
186 slur = make_spanner ("Slur", events_[START]->self_scm ());
187 set_grob_direction (slur, UP);
188 slurs_.push_back (slur);
191 set_melisma (slurs_.size ());
194 void
195 Slur_engraver::stop_translation_timestep ()
197 if (Grob *g = unsmob_grob (get_property ("currentCommandColumn")))
199 for (vsize i = 0; i < end_slurs_.size (); i++)
200 Slur::add_extra_encompass (end_slurs_[i], g);
202 if (!events_[START])
203 for (vsize i = 0; i < slurs_.size (); i++)
204 Slur::add_extra_encompass (slurs_[i], g);
208 for (vsize i = 0; i < end_slurs_.size (); i++)
210 Spanner * s = dynamic_cast<Spanner*> (end_slurs_[i]);
211 if (!s->get_bound (RIGHT))
212 s->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn")));
213 announce_end_grob (s, SCM_EOL);
215 end_slurs_.clear ();
216 events_[START] = events_[STOP] = 0;
219 ADD_ACKNOWLEDGER (Slur_engraver, accidental);
220 ADD_ACKNOWLEDGER (Slur_engraver, fingering);
221 ADD_ACKNOWLEDGER (Slur_engraver, note_column);
222 ADD_ACKNOWLEDGER (Slur_engraver, script);
223 ADD_ACKNOWLEDGER (Slur_engraver, text_script);
224 ADD_ACKNOWLEDGER (Slur_engraver, tie);
225 ADD_ACKNOWLEDGER (Slur_engraver, tuplet_number);
226 ADD_TRANSLATOR (Slur_engraver,
227 /* doc */
228 "Build slur grobs from slur events.",
230 /* create */
231 "Slur ",
233 /* read */
234 "slurMelismaBusy "
235 "doubleSlurs ",
237 /* write */