2 slur-engraver.cc -- implement Slur_engraver
4 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "note-column.hh"
13 #include "engraver.hh"
17 TODO: junk nested slur functionality.
19 class Slur_engraver : public Engraver
21 Link_array<Music> events_;
22 Link_array<Music> new_slur_evs_;
23 Link_array<Grob> slur_stack_;
24 Link_array<Grob> end_slurs_;
27 void set_melisma (bool);
30 virtual bool try_music (Music*);
31 virtual void acknowledge_grob (Grob_info);
32 virtual void stop_translation_timestep ();
33 virtual void finalize ();
34 virtual void process_music ();
37 TRANSLATOR_DECLARATIONS (Slur_engraver);
40 Slur_engraver::Slur_engraver ()
42 last_start_ = Moment (-1);
46 Slur_engraver::try_music (Music *ev)
48 if (ev->is_mus_type ("slur-event"))
51 Let's not start more than one slur per moment.
53 Direction d = to_dir (ev->get_property ("span-direction"));
56 if (now_mom () > last_start_)
58 new_slur_evs_.push (ev);
59 last_start_ = now_mom ();
63 But we swallow other slur events.
73 for (int j = new_slur_evs_.size (); j--;)
75 Direction nd = to_dir (new_slur_evs_[j]->get_property ("span-direction"));
81 new_slur_evs_.push (ev);
89 Slur_engraver::set_melisma (bool m)
91 context ()->set_property ("slurMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
95 Slur_engraver::acknowledge_grob (Grob_info info)
97 if (Note_column::has_interface (info.grob_))
100 for (int i = 0; i < slur_stack_.size (); i++)
101 Slur::add_column (slur_stack_[i], e);
102 for (int i = 0; i < end_slurs_.size (); i++)
103 Slur::add_column (end_slurs_[i], e);
108 Slur_engraver::finalize ()
110 for (int i = 0; i < slur_stack_.size (); i++)
113 Let's not typeset unterminated stuff
115 slur_stack_[i]->suicide ();
117 slur_stack_.clear ();
119 for (int i=0; i < events_.size (); i++)
121 events_[i]->origin ()->warning (_ ("unterminated slur"));
126 Slur_engraver::process_music ()
128 Link_array<Grob> start_slurs;
129 for (int i=0; i< new_slur_evs_.size (); i++)
131 Music* slur_ev = new_slur_evs_[i];
132 // end slur: move the slur to other array
133 Direction d = to_dir (slur_ev->get_property ("span-direction"));
136 if (slur_stack_.is_empty ())
137 /* How to shut up this warning, when Voice_devnull_engraver has
138 eaten start event? */
139 slur_ev->origin ()->warning (_f ("can't find start of slur"));
142 Grob* slur = slur_stack_.pop ();
144 end_slurs_.push (slur);
150 // push a new slur onto stack.
151 // (use temp. array to wait for all slur STOPs)
152 Grob* slur = make_spanner ("Slur", slur_ev->self_scm ());
153 Slur::set_interface (slur); // cannot remove yet!
156 if (Direction updown = to_dir (slur_ev->get_property ("direction")))
158 slur->set_property ("direction", scm_int2num (updown));
161 start_slurs.push (slur);
162 events_.push (slur_ev);
166 slur_stack_.concat (start_slurs);
168 set_melisma (slur_stack_.size ());
170 new_slur_evs_.clear ();
174 Slur_engraver::stop_translation_timestep ()
177 new_slur_evs_.clear ();
182 ENTER_DESCRIPTION (Slur_engraver,
183 /* descr */ "Build slurs from Slur_evs",
185 /* accepts */ "slur-event",
186 /* acks */ "note-column-interface",
187 /* reads */ "slurMelismaBusy",