lilypond-1.5.10
[lilypond.git] / lily / slur-engraver.cc
blob6eb8973f7700daa1ea3ba53aa4460aa49b6e4ea2
1 /*
2 slur-engraver.cc -- implement Slur_engraver
4 (c) 1997--2001 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 create_grobs ();
33 public:
34 VIRTUAL_COPY_CONS (Translator);
35 Slur_engraver ();
38 Slur_engraver::Slur_engraver ()
40 last_start_ = Moment (-1);
43 bool
44 Slur_engraver::try_music (Music *req_l)
46 if (Span_req *sl = dynamic_cast <Span_req *> (req_l))
48 String t = ly_scm2string (sl->get_mus_property ("span-type"));
49 if (t == "abort")
51 for (int i = 0; i < slur_l_stack_.size (); i++)
53 slur_l_stack_[i]->suicide ();
55 slur_l_stack_.clear ();
56 for (int i = 0; i < end_slur_l_arr_.size (); i++)
58 end_slur_l_arr_[i]->suicide ();
60 end_slur_l_arr_.clear ();
61 requests_arr_.clear ();
62 new_slur_req_l_arr_.clear ();
64 else if (t == "slur")
67 Let's not start more than one slur per moment.
69 if (sl->get_span_dir () == START)
71 if (now_mom () > last_start_)
73 new_slur_req_l_arr_.push (sl);
74 last_start_ = now_mom ();
75 return true;
78 else
80 new_slur_req_l_arr_.push (sl);
81 return true;
85 return false;
88 void
89 Slur_engraver::set_melisma (bool m)
91 daddy_trans_l_->set_property ("slurMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
94 void
95 Slur_engraver::acknowledge_grob (Grob_info info)
97 if (Note_column::has_interface (info.elem_l_))
99 Grob *e =info.elem_l_;
100 for (int i = 0; i < slur_l_stack_.size (); i++)
101 Slur::add_column (slur_l_stack_[i], e);
102 for (int i = 0; i < end_slur_l_arr_.size (); i++)
103 Slur::add_column (end_slur_l_arr_[i], e);
107 void
108 Slur_engraver::finalize ()
110 for (int i = 0; i < slur_l_stack_.size (); i++)
112 #if 0
113 typeset_grob (slur_l_stack_[i]);
114 #else
116 Let's not typeset unterminated stuff
118 slur_l_stack_[i]->suicide ();
119 #endif
121 slur_l_stack_.clear ();
123 for (int i=0; i < requests_arr_.size (); i++)
125 requests_arr_[i]->origin ()->warning (_ ("unterminated slur"));
129 void
130 Slur_engraver::create_grobs ()
132 Link_array<Grob> start_slur_l_arr;
133 for (int i=0; i< new_slur_req_l_arr_.size (); i++)
135 Span_req* slur_req_l = new_slur_req_l_arr_[i];
136 // end slur: move the slur to other array
137 if (slur_req_l->get_span_dir () == STOP)
139 if (slur_l_stack_.empty ())
140 /* How to shut up this warning, when Voice_devnull_engraver has
141 eaten start request? */
142 slur_req_l->origin ()->warning (_f ("can't find start of slur"));
143 else
145 Grob* slur = slur_l_stack_.pop ();
146 SCM s = get_property ("slurEndAttachment");
147 if (gh_symbol_p (s))
149 index_set_cell (slur->get_grob_property ("attachment"), STOP, s);
151 end_slur_l_arr_.push (slur);
152 requests_arr_.pop ();
155 else if (slur_req_l->get_span_dir () == START)
157 // push a new slur onto stack.
158 // (use temp. array to wait for all slur STOPs)
159 Grob* slur = new Spanner (get_property ("Slur"));
160 Slur::set_interface (slur);
161 SCM s = get_property ("slurBeginAttachment");
162 if (gh_symbol_p (s))
164 index_set_cell (slur->get_grob_property ("attachment"), START, s);
166 start_slur_l_arr.push (slur);
167 requests_arr_.push (slur_req_l);
168 announce_grob (slur, slur_req_l);
171 for (int i=0; i < start_slur_l_arr.size (); i++)
172 slur_l_stack_.push (start_slur_l_arr[i]);
173 new_slur_req_l_arr_.clear ();
176 void
177 Slur_engraver::stop_translation_timestep ()
179 for (int i = 0; i < end_slur_l_arr_.size (); i++)
181 typeset_grob (end_slur_l_arr_[i]);
183 end_slur_l_arr_.clear ();
186 void
187 Slur_engraver::start_translation_timestep ()
189 new_slur_req_l_arr_.clear ();
190 SCM m = get_property ("automaticMelismata");
191 if (to_boolean (m))
193 set_melisma (slur_l_stack_.size ());
198 ADD_THIS_TRANSLATOR (Slur_engraver);