''
[lilypond.git] / lily / slur-engraver.cc
blob259905900881327acdc05c4c86b4877ae307e66f
1 /*
2 slur-engraver.cc -- implement Slur_engraver
4 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
7 #include "musical-request.hh"
8 #include "slur.hh"
9 #include "debug.hh"
10 #include "note-column.hh"
11 #include "translator-group.hh"
12 #include "engraver.hh"
13 #include "spanner.hh"
15 class Slur_engraver : public Engraver
17 Link_array<Span_req> requests_arr_;
18 Link_array<Span_req> new_slur_req_l_arr_;
19 Link_array<Grob> slur_l_stack_;
20 Link_array<Grob> end_slur_l_arr_;
21 Moment last_start_;
23 void set_melisma (bool);
25 protected:
26 virtual bool try_music (Music*);
27 virtual void acknowledge_grob (Grob_info);
28 virtual void stop_translation_timestep ();
29 virtual void start_translation_timestep ();
30 virtual void finalize ();
31 virtual void process_acknowledged_grobs ();
33 public:
34 TRANSLATOR_DECLARATIONS (Slur_engraver);
37 Slur_engraver::Slur_engraver ()
39 last_start_ = Moment (-1);
42 bool
43 Slur_engraver::try_music (Music *req_l)
45 if (Span_req *sl = dynamic_cast <Span_req *> (req_l))
47 String t = ly_scm2string (sl->get_mus_property ("span-type"));
48 if (t == "abort")
50 for (int i = 0; i < slur_l_stack_.size (); i++)
52 slur_l_stack_[i]->suicide ();
54 slur_l_stack_.clear ();
55 for (int i = 0; i < end_slur_l_arr_.size (); i++)
57 end_slur_l_arr_[i]->suicide ();
59 end_slur_l_arr_.clear ();
60 requests_arr_.clear ();
61 new_slur_req_l_arr_.clear ();
63 else if (t == "slur")
66 Let's not start more than one slur per moment.
68 if (sl->get_span_dir () == START)
70 if (now_mom () > last_start_)
72 new_slur_req_l_arr_.push (sl);
73 last_start_ = now_mom ();
74 return true;
77 else
79 new_slur_req_l_arr_.push (sl);
80 return true;
84 return false;
87 void
88 Slur_engraver::set_melisma (bool m)
90 daddy_trans_l_->set_property ("slurMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
93 void
94 Slur_engraver::acknowledge_grob (Grob_info info)
96 if (Note_column::has_interface (info.grob_l_))
98 Grob *e =info.grob_l_;
99 for (int i = 0; i < slur_l_stack_.size (); i++)
100 Slur::add_column (slur_l_stack_[i], e);
101 for (int i = 0; i < end_slur_l_arr_.size (); i++)
102 Slur::add_column (end_slur_l_arr_[i], e);
106 void
107 Slur_engraver::finalize ()
109 for (int i = 0; i < slur_l_stack_.size (); i++)
111 #if 0
112 typeset_grob (slur_l_stack_[i]);
113 #else
115 Let's not typeset unterminated stuff
117 slur_l_stack_[i]->suicide ();
118 #endif
120 slur_l_stack_.clear ();
122 for (int i=0; i < requests_arr_.size (); i++)
124 requests_arr_[i]->origin ()->warning (_ ("unterminated slur"));
128 void
129 Slur_engraver::process_acknowledged_grobs ()
131 Link_array<Grob> start_slur_l_arr;
132 for (int i=0; i< new_slur_req_l_arr_.size (); i++)
134 Span_req* slur_req_l = new_slur_req_l_arr_[i];
135 // end slur: move the slur to other array
136 if (slur_req_l->get_span_dir () == STOP)
138 if (slur_l_stack_.empty ())
139 /* How to shut up this warning, when Voice_devnull_engraver has
140 eaten start request? */
141 slur_req_l->origin ()->warning (_f ("can't find start of slur"));
142 else
144 Grob* slur = slur_l_stack_.pop ();
146 end_slur_l_arr_.push (slur);
147 requests_arr_.pop ();
150 else if (slur_req_l->get_span_dir () == START)
152 // push a new slur onto stack.
153 // (use temp. array to wait for all slur STOPs)
154 Grob* slur = new Spanner (get_property ("Slur"));
155 Slur::set_interface (slur); // cannot remove yet!
156 start_slur_l_arr.push (slur);
157 requests_arr_.push (slur_req_l);
158 announce_grob (slur, slur_req_l->self_scm ());
161 for (int i=0; i < start_slur_l_arr.size (); i++)
162 slur_l_stack_.push (start_slur_l_arr[i]);
163 new_slur_req_l_arr_.clear ();
166 void
167 Slur_engraver::stop_translation_timestep ()
169 for (int i = 0; i < end_slur_l_arr_.size (); i++)
171 typeset_grob (end_slur_l_arr_[i]);
173 end_slur_l_arr_.clear ();
176 void
177 Slur_engraver::start_translation_timestep ()
179 new_slur_req_l_arr_.clear ();
180 SCM m = get_property ("automaticMelismata");
181 if (to_boolean (m))
183 set_melisma (slur_l_stack_.size ());
189 ENTER_DESCRIPTION (Slur_engraver,
190 /* descr */ "Build slurs from Slur_reqs",
191 /* creats*/ "Slur",
192 /* acks */ "note-column-interface",
193 /* reads */ "slurMelismaBusy",
194 /* write */ "");