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"
15 // #include "international.hh"
18 struct Head_event_tuple
20 Audio_element_info head_;
22 Head_event_tuple () { }
23 Head_event_tuple (Audio_element_info h, Moment m)
31 class Tie_performer : public Performer
34 // We don't really need a deque here. A vector would suffice. However,
35 // for some strange reason, using vectors always leads to memory
36 // corruption in the STL templates! (i.e. after the first
37 // now_heads_.push_back (inf_mom), the now_heads_.size() will be
38 // something like 3303820998 :(
39 deque<Head_event_tuple> now_heads_;
40 deque<Head_event_tuple> now_tied_heads_;
41 deque<Head_event_tuple> heads_to_tie_;
44 void stop_translation_timestep ();
45 void start_translation_timestep ();
46 virtual void acknowledge_audio_element (Audio_element_info);
47 void process_music ();
48 DECLARE_TRANSLATOR_LISTENER (tie);
50 TRANSLATOR_DECLARATIONS (Tie_performer);
53 Tie_performer::Tie_performer ()
58 IMPLEMENT_TRANSLATOR_LISTENER (Tie_performer, tie);
60 Tie_performer::listen_tie (Stream_event *ev)
66 Tie_performer::process_music ()
69 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
73 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
75 if (Audio_note *an = dynamic_cast<Audio_note *> (inf.elem_))
77 // message (_f ("acknowledge_audio_element, Size of now_heads_=%d", now_heads_.size ()));
78 Head_event_tuple inf_mom (inf, now_mom ());
80 now_tied_heads_.push_back (inf_mom);
82 now_heads_.push_back (inf_mom);
84 // message (_f ("acknowledge_audio_element, added, Size of now_heads_=%d", now_heads_.size ()));
85 // Find a previous note that ties to the current note. If it exists,
86 // remove it from the heads_to_tie vector and create the tie
87 deque<Head_event_tuple>::iterator it;
89 Stream_event *right_mus = inf.event_;
90 for ( it = heads_to_tie_.begin() ; (!found) && (it < heads_to_tie_.end()); it++ )
92 Audio_element_info et = (*it).head_;
93 Audio_note *th = dynamic_cast<Audio_note *> (et.elem_);
94 Stream_event *left_mus = et.event_;
96 if (th && right_mus && left_mus
97 && ly_is_equal (right_mus->get_property ("pitch"),
98 left_mus->get_property ("pitch")))
101 Moment skip = now_mom() - (*it).moment_ - th->length_mom_;
102 an->tie_to (th, skip);
103 // this invalidates the iterator, we are leaving the loop anyway
104 heads_to_tie_.erase (it);
111 Tie_performer::start_translation_timestep ()
113 context ()->set_property ("tieMelismaBusy",
114 ly_bool2scm (heads_to_tie_.size ()));
118 Tie_performer::stop_translation_timestep ()
120 // We might have dangling open ties like c~ d. Close them, unless we have
121 // tieWaitForNote set...
122 if (!to_boolean (get_property ("tieWaitForNote")))
124 heads_to_tie_.clear ();
129 for (vsize i = now_heads_.size (); i--;)
130 heads_to_tie_.push_back (now_heads_[i]);
133 for (vsize i = now_tied_heads_.size (); i--;)
134 heads_to_tie_.push_back (now_tied_heads_[i]);
138 now_tied_heads_.clear ();
141 ADD_TRANSLATOR (Tie_performer,
143 "Generate ties between note heads of equal pitch.",