2 tie-performer.cc -- implement Tie_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "performer.hh"
11 #include "audio-item.hh"
13 #include "stream-event.hh"
14 #include "translator.icc"
16 class Tie_performer : public Performer
19 vector<Audio_element_info> now_heads_;
20 vector<Audio_element_info> now_tied_heads_;
21 vector<Audio_element_info> heads_to_tie_;
24 void stop_translation_timestep ();
25 void start_translation_timestep ();
26 virtual void acknowledge_audio_element (Audio_element_info);
27 void process_music ();
28 DECLARE_TRANSLATOR_LISTENER (tie);
30 TRANSLATOR_DECLARATIONS (Tie_performer);
33 Tie_performer::Tie_performer ()
38 IMPLEMENT_TRANSLATOR_LISTENER (Tie_performer, tie);
40 Tie_performer::listen_tie (Stream_event *ev)
46 Tie_performer::process_music ()
49 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
53 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
55 if (Audio_note *an = dynamic_cast<Audio_note *> (inf.elem_))
58 now_tied_heads_.push_back (inf);
60 now_heads_.push_back (inf);
62 // Find a previous note that ties to the current note. If it exists,
63 // remove it from the heads_to_tie vector and create the tie
64 vector<Audio_element_info>::iterator it;
66 Stream_event *right_mus = inf.event_;
67 for ( it = heads_to_tie_.begin() ; (!found) && (it < heads_to_tie_.end()); it++ )
69 Audio_element_info et = *it;
70 Audio_note *th = dynamic_cast<Audio_note *> (et.elem_);
71 Stream_event *left_mus = et.event_;
73 if (th && right_mus && left_mus
74 && ly_is_equal (right_mus->get_property ("pitch"),
75 left_mus->get_property ("pitch")))
79 // this invalidates the iterator, we are leaving the loop anyway
80 heads_to_tie_.erase (it);
87 Tie_performer::start_translation_timestep ()
89 context ()->set_property ("tieMelismaBusy",
90 ly_bool2scm (heads_to_tie_.size ()));
94 Tie_performer::stop_translation_timestep ()
96 // We might have dangling open ties like c~ d. Close them, unless we have
97 // tieWaitForNote set...
98 if (!to_boolean (get_property ("tieWaitForNote")))
100 heads_to_tie_.clear ();
105 heads_to_tie_ = now_heads_;
108 for (vsize i = now_tied_heads_.size (); i--;)
109 heads_to_tie_.push_back (now_tied_heads_[i]);
113 now_tied_heads_.clear ();
116 ADD_TRANSLATOR (Tie_performer,
118 "Generate ties between note heads of equal pitch.",