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 struct Head_event_tuple
18 Audio_element_info head_;
20 Head_event_tuple () { }
21 Head_event_tuple (Audio_element_info h, Moment m)
29 class Tie_performer : public Performer
32 vector<Head_event_tuple> now_heads_;
33 vector<Head_event_tuple> now_tied_heads_;
34 vector<Head_event_tuple> heads_to_tie_;
37 void stop_translation_timestep ();
38 void start_translation_timestep ();
39 virtual void acknowledge_audio_element (Audio_element_info);
40 void process_music ();
41 DECLARE_TRANSLATOR_LISTENER (tie);
43 TRANSLATOR_DECLARATIONS (Tie_performer);
46 Tie_performer::Tie_performer ()
51 IMPLEMENT_TRANSLATOR_LISTENER (Tie_performer, tie);
53 Tie_performer::listen_tie (Stream_event *ev)
59 Tie_performer::process_music ()
62 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
66 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
68 if (Audio_note *an = dynamic_cast<Audio_note *> (inf.elem_))
70 Head_event_tuple inf_mom (inf, now_mom ());
72 now_tied_heads_.push_back (inf_mom);
74 now_heads_.push_back (inf_mom);
76 // Find a previous note that ties to the current note. If it exists,
77 // remove it from the heads_to_tie vector and create the tie
78 vector<Head_event_tuple>::iterator it;
80 Stream_event *right_mus = inf.event_;
81 for ( it = heads_to_tie_.begin() ; (!found) && (it < heads_to_tie_.end()); it++ )
83 Audio_element_info et = (*it).head_;
84 Audio_note *th = dynamic_cast<Audio_note *> (et.elem_);
85 Stream_event *left_mus = et.event_;
87 if (th && right_mus && left_mus
88 && ly_is_equal (right_mus->get_property ("pitch"),
89 left_mus->get_property ("pitch")))
92 Moment skip = now_mom() - (*it).moment_ - th->length_mom_;
93 an->tie_to (th, skip);
94 // this invalidates the iterator, we are leaving the loop anyway
95 heads_to_tie_.erase (it);
102 Tie_performer::start_translation_timestep ()
104 context ()->set_property ("tieMelismaBusy",
105 ly_bool2scm (heads_to_tie_.size ()));
109 Tie_performer::stop_translation_timestep ()
111 // We might have dangling open ties like c~ d. Close them, unless we have
112 // tieWaitForNote set...
113 if (!to_boolean (get_property ("tieWaitForNote")))
115 heads_to_tie_.clear ();
120 for (vsize i = now_heads_.size (); i--;)
121 heads_to_tie_.push_back (now_heads_[i]);
124 for (vsize i = now_tied_heads_.size (); i--;)
125 heads_to_tie_.push_back (now_tied_heads_[i]);
129 now_tied_heads_.clear ();
132 ADD_TRANSLATOR (Tie_performer,
134 "Generate ties between note heads of equal pitch.",