2 tie-performer.cc -- implement Tie_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2002 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "command-request.hh"
11 #include "audio-item.hh"
12 #include "musical-request.hh"
14 #include "performer.hh"
16 struct CNote_melodic_tuple {
20 CNote_melodic_tuple ();
21 CNote_melodic_tuple (Audio_note*, Melodic_req*, Moment);
22 static int pitch_compare (CNote_melodic_tuple const &, CNote_melodic_tuple const &);
23 static int time_compare (CNote_melodic_tuple const &, CNote_melodic_tuple const &);
26 inline int compare (CNote_melodic_tuple const &a, CNote_melodic_tuple const &b)
28 return CNote_melodic_tuple::time_compare (a,b);
33 Manufacture ties. Acknowledge notes, and put them into a
34 priority queue. If we have a Tie_req, connect the notes that finish
35 just at this time, and note that start at this time.
37 TODO: should share code with Tie_engraver ?
39 class Tie_performer : public Performer
42 TRANSLATOR_DECLARATIONS(Tie_performer);
45 PQueue<CNote_melodic_tuple> past_notes_pq_;
47 Array<CNote_melodic_tuple> now_notes_;
48 Array<CNote_melodic_tuple> stopped_notes_;
49 Link_array<Audio_tie> ties_;
52 virtual void initialize ();
53 virtual void start_translation_timestep ();
54 virtual void stop_translation_timestep ();
55 virtual void acknowledge_audio_element (Audio_element_info);
56 virtual bool try_music (Music*);
57 virtual void create_audio_elements ();
61 Tie_performer::Tie_performer ()
67 ENTER_DESCRIPTION (Tie_performer, "", "",
73 Tie_performer::initialize ()
80 Tie_performer::try_music (Music *m)
84 if (Tie_req * c = dynamic_cast<Tie_req*> (m))
94 Tie_performer::acknowledge_audio_element (Audio_element_info i)
96 if (Audio_note *nh = dynamic_cast<Audio_note *> (i.elem_))
98 Note_req * m = dynamic_cast<Note_req *> (i.req_);
101 now_notes_.push (CNote_melodic_tuple (nh, m, now_mom ()+ m->length_mom ()));
106 Tie_performer::create_audio_elements ()
110 Moment now = now_mom ();
111 Link_array<Audio_note> nharr;
113 stopped_notes_.clear ();
114 while (past_notes_pq_.size ()
115 && past_notes_pq_.front ().end_ == now)
116 stopped_notes_.push (past_notes_pq_.get ());
123 now_notes_.sort (CNote_melodic_tuple::pitch_compare);
124 stopped_notes_.sort (CNote_melodic_tuple::pitch_compare);
128 while (i < now_notes_.size () && j < stopped_notes_.size ())
131 = Pitch::compare (*unsmob_pitch (now_notes_[i].req_->get_mus_property ("pitch")),
132 *unsmob_pitch (stopped_notes_[j].req_->get_mus_property ("pitch")));
136 (comp < 0) ? i ++ : j++;
143 /* don't go around recreating ties that were already
144 made. Not infallible. Due to reordering in sort (),
145 we will make the wrong ties when notenotes are
147 if (tie_count > ties_.size ())
149 Audio_tie * p = new Audio_tie;
150 p->set_note (LEFT, stopped_notes_[j].note_);
151 p->set_note (RIGHT, now_notes_[i].note_);
153 announce_element (Audio_element_info (p, req_));
163 req_->origin ()->warning (_ ("No ties were created!"));
170 Tie_performer::stop_translation_timestep ()
172 for (int i=0; i < now_notes_.size (); i++)
174 past_notes_pq_.insert (now_notes_[i]);
178 for (int i=0; i< ties_.size (); i++)
180 //play_element (ties_[i]);
181 ties_[i]->note_l_drul_[RIGHT]->tie_to (ties_[i]->note_l_drul_[LEFT]);
187 Tie_performer::start_translation_timestep ()
191 Moment now = now_mom ();
192 while (past_notes_pq_.size () && past_notes_pq_.front ().end_ < now)
193 past_notes_pq_.delmin ();
197 CNote_melodic_tuple::CNote_melodic_tuple ()
204 CNote_melodic_tuple::CNote_melodic_tuple (Audio_note *h, Melodic_req*m, Moment mom)
212 CNote_melodic_tuple::pitch_compare (CNote_melodic_tuple const&h1,
213 CNote_melodic_tuple const &h2)
215 SCM p1 = h1.req_->get_mus_property ("pitch");
216 SCM p2 = h2.req_->get_mus_property ("pitch");
217 return Pitch::compare (*unsmob_pitch (p1),
222 CNote_melodic_tuple::time_compare (CNote_melodic_tuple const&h1,
223 CNote_melodic_tuple const &h2)
225 return (h1.end_ - h2.end_).main_part_.sign ();