2 slur-engraver.cc -- implement Slur_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "directional-element-interface.hh"
13 #include "international.hh"
14 #include "note-column.hh"
17 #include "stream-event.hh"
20 #include "translator.icc"
26 This is largely similar to Phrasing_slur_engraver. Check if fixes
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
38 class Slur_engraver : public Engraver
40 Drul_array<Stream_event *> events_;
41 Stream_event *running_slur_start_;
43 vector<Grob*> end_slurs_;
45 void set_melisma (bool);
48 DECLARE_TRANSLATOR_LISTENER (slur);
49 DECLARE_ACKNOWLEDGER (accidental);
50 DECLARE_ACKNOWLEDGER (dynamic_line_spanner);
51 DECLARE_ACKNOWLEDGER (fingering);
52 DECLARE_ACKNOWLEDGER (note_column);
53 DECLARE_ACKNOWLEDGER (script);
54 DECLARE_ACKNOWLEDGER (text_script);
55 DECLARE_ACKNOWLEDGER (tie);
56 DECLARE_ACKNOWLEDGER (tuplet_number);
58 void acknowledge_extra_object (Grob_info);
59 void stop_translation_timestep ();
60 void process_music ();
62 virtual void finalize ();
66 TRANSLATOR_DECLARATIONS (Slur_engraver);
69 Slur_engraver::Slur_engraver ()
71 events_[START] = events_[STOP] = 0;
74 IMPLEMENT_TRANSLATOR_LISTENER (Slur_engraver, slur);
76 Slur_engraver::listen_slur (Stream_event *ev)
78 Direction d = to_dir (ev->get_property ("span-direction"));
80 ASSIGN_EVENT_ONCE (events_[START], ev);
82 ASSIGN_EVENT_ONCE (events_[STOP], ev);
83 else ev->origin ()->warning (_ ("Invalid direction of slur-event"));
87 Slur_engraver::set_melisma (bool m)
89 context ()->set_property ("slurMelismaBusy", m ? SCM_BOOL_T : SCM_BOOL_F);
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);
103 Slur_engraver::acknowledge_extra_object (Grob_info info)
105 Slur::auxiliary_acknowledge_extra_object (info, slurs_, end_slurs_);
109 Slur_engraver::acknowledge_accidental (Grob_info info)
111 acknowledge_extra_object (info);
115 Slur_engraver::acknowledge_dynamic_line_spanner (Grob_info info)
117 acknowledge_extra_object (info);
121 Slur_engraver::acknowledge_fingering (Grob_info info)
123 acknowledge_extra_object (info);
127 Slur_engraver::acknowledge_tuplet_number (Grob_info info)
129 acknowledge_extra_object (info);
134 Slur_engraver::acknowledge_script (Grob_info info)
136 if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
137 acknowledge_extra_object (info);
141 Slur_engraver::acknowledge_text_script (Grob_info info)
143 acknowledge_extra_object (info);
147 Slur_engraver::acknowledge_tie (Grob_info info)
149 acknowledge_extra_object (info);
153 Slur_engraver::finalize ()
156 slurs_[0]->warning (_ ("unterminated slur"));
160 Slur_engraver::process_music ()
164 if (slurs_.size () == 0)
165 events_[STOP]->origin ()->warning (_ ("can't end slur"));
172 if (events_[START] && slurs_.empty ())
174 Stream_event *ev = events_[START];
176 bool double_slurs = to_boolean (get_property ("doubleSlurs"));
178 Grob *slur = make_spanner ("Slur", events_[START]->self_scm ());
179 Direction updown = to_dir (ev->get_property ("direction"));
180 if (updown && !double_slurs)
181 set_grob_direction (slur, updown);
183 slurs_.push_back (slur);
187 set_grob_direction (slur, DOWN);
188 slur = make_spanner ("Slur", events_[START]->self_scm ());
189 set_grob_direction (slur, UP);
190 slurs_.push_back (slur);
193 set_melisma (slurs_.size ());
197 Slur_engraver::stop_translation_timestep ()
199 for (vsize i = 0; i < end_slurs_.size (); i++)
200 announce_end_grob (end_slurs_[i], SCM_EOL);
202 events_[START] = events_[STOP] = 0;
205 ADD_ACKNOWLEDGER (Slur_engraver, accidental);
206 ADD_ACKNOWLEDGER (Slur_engraver, dynamic_line_spanner);
207 ADD_ACKNOWLEDGER (Slur_engraver, fingering);
208 ADD_ACKNOWLEDGER (Slur_engraver, note_column);
209 ADD_ACKNOWLEDGER (Slur_engraver, script);
210 ADD_ACKNOWLEDGER (Slur_engraver, text_script);
211 ADD_ACKNOWLEDGER (Slur_engraver, tie);
212 ADD_ACKNOWLEDGER (Slur_engraver, tuplet_number);
213 ADD_TRANSLATOR (Slur_engraver,
214 /* doc */ "Build slur grobs from slur events",
216 /* read */ "slurMelismaBusy doubleSlurs",