*** empty log message ***
[lilypond.git] / lily / phrasing-slur-engraver.cc
blob0906d168317e8d269694077040cbc923c9fa1251
1 /*
2 phrasing-slur-engraver.cc -- implement Phrasing_slur_engraver
4 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
7 #include "event.hh"
8 #include "slur.hh"
9 #include "warn.hh"
10 #include "note-column.hh"
11 #include "translator-group.hh"
12 #include "engraver.hh"
13 #include "spanner.hh"
16 TODO:
18 ALGRGRRGRG
20 Derive this from Slur_engraver. This code is completely duplicate.
22 class Phrasing_slur_engraver : public Engraver
24 Link_array<Music> eventses_;
25 Link_array<Music> new_phrasing_slur_evs_;
26 Link_array<Grob> phrasing_slur_l_stack_;
27 Link_array<Grob> end_phrasing_slurs_;
28 Moment last_start_;
30 protected:
31 virtual bool try_music (Music*);
32 virtual void acknowledge_grob (Grob_info);
33 virtual void stop_translation_timestep ();
34 virtual void start_translation_timestep ();
35 virtual void finalize ();
36 virtual void process_acknowledged_grobs ();
38 public:
39 TRANSLATOR_DECLARATIONS(Phrasing_slur_engraver);
43 Phrasing_slur_engraver::Phrasing_slur_engraver ()
45 last_start_ = Moment (-1);
48 bool
49 Phrasing_slur_engraver::try_music (Music *ev)
51 if (ev->is_mus_type ("abort-event"))
53 for (int i = 0; i < phrasing_slur_l_stack_.size (); i++)
55 phrasing_slur_l_stack_[i]->suicide ();
57 phrasing_slur_l_stack_.clear ();
58 for (int i = 0; i < end_phrasing_slurs_.size (); i++)
60 end_phrasing_slurs_[i]->suicide ();
62 end_phrasing_slurs_.clear ();
63 eventses_.clear ();
64 new_phrasing_slur_evs_.clear ();
66 else if (ev->is_mus_type ("phrasing-slur-event"))
69 Let's not start more than one phrasing slur per moment.
72 Direction d = to_dir (ev->get_mus_property ("span-direction"));
74 if (d == START)
76 if (now_mom () > last_start_)
78 new_phrasing_slur_evs_.push (ev);
79 last_start_ = now_mom ();
80 return true;
83 else
85 new_phrasing_slur_evs_.push (ev);
86 return true;
89 return false;
92 void
93 Phrasing_slur_engraver::acknowledge_grob (Grob_info info)
95 if (Note_column::has_interface (info.grob_))
97 Grob *e =info.grob_;
98 for (int i = 0; i < phrasing_slur_l_stack_.size (); i++)
99 Slur::add_column (phrasing_slur_l_stack_[i], e);
100 for (int i = 0; i < end_phrasing_slurs_.size (); i++)
101 Slur::add_column (end_phrasing_slurs_[i], e);
105 void
106 Phrasing_slur_engraver::finalize ()
108 for (int i = 0; i < phrasing_slur_l_stack_.size (); i++)
110 #if 0
111 typeset_grob (phrasing_slur_l_stack_[i]);
112 #else
114 Let's not typeset unterminated stuff
116 phrasing_slur_l_stack_[i]->suicide ();
117 #endif
119 phrasing_slur_l_stack_.clear ();
121 for (int i=0; i < eventses_.size (); i++)
123 eventses_[i]->origin ()->warning (_ ("unterminated phrasing slur"));
127 void
128 Phrasing_slur_engraver::process_acknowledged_grobs ()
130 Link_array<Grob> start_phrasing_slurs;
131 for (int i=0; i< new_phrasing_slur_evs_.size (); i++)
133 Music* phrasing_slur_ev = new_phrasing_slur_evs_[i];
134 // end phrasing slur: move the phrasing slur to other array
136 Direction d = to_dir (phrasing_slur_ev->get_mus_property ("span-direction"));
138 if (d == STOP)
140 if (phrasing_slur_l_stack_.empty ())
141 phrasing_slur_ev->origin ()->warning (_f ("can't find start of phrasing slur"));
142 else
144 Grob* phrasing_slur = phrasing_slur_l_stack_.pop ();
145 end_phrasing_slurs_.push (phrasing_slur);
146 eventses_.pop ();
149 else if (d == START)
151 // push a new phrasing_slur onto stack.
152 // (use temp. array to wait for all phrasing_slur STOPs)
153 Grob* phrasing_slur = new Spanner (get_property ("PhrasingSlur"));
154 Slur::set_interface (phrasing_slur); // can't remove.
157 if (Direction updown = to_dir (phrasing_slur_ev->get_mus_property ("direction")))
159 phrasing_slur->set_grob_property ("direction", gh_int2scm (updown));
162 start_phrasing_slurs.push (phrasing_slur);
163 eventses_.push (phrasing_slur_ev);
164 announce_grob(phrasing_slur, phrasing_slur_ev->self_scm());
167 for (int i=0; i < start_phrasing_slurs.size (); i++)
168 phrasing_slur_l_stack_.push (start_phrasing_slurs[i]);
169 new_phrasing_slur_evs_.clear ();
172 void
173 Phrasing_slur_engraver::stop_translation_timestep ()
175 for (int i = 0; i < end_phrasing_slurs_.size (); i++)
177 typeset_grob (end_phrasing_slurs_[i]);
179 end_phrasing_slurs_.clear ();
182 void
183 Phrasing_slur_engraver::start_translation_timestep ()
185 new_phrasing_slur_evs_.clear ();
190 ENTER_DESCRIPTION(Phrasing_slur_engraver,
191 /* descr */ "Print phrasing slurs. Similar to @ref{Slur_engraver}",
192 /* creats*/ "PhrasingSlur",
193 /* accepts */ "phrasing-slur-event",
194 /* acks */ "note-column-interface",
195 /* reads */ "",
196 /* write */ "");