2 tie-performer.cc -- implement Tie_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Jan Nieuwenhuizen <janneke@gnu.org>
11 #include "audio-item.hh"
14 #include "performer.hh"
16 struct CNote_melodic_tuple {
20 CNote_melodic_tuple ();
21 CNote_melodic_tuple (Audio_note*, Music*, 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 Music, 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);
46 Array<CNote_melodic_tuple> now_notes_;
47 Array<CNote_melodic_tuple> tied_notes_;
52 Link_array<Audio_tie> ties_;
55 virtual void process_music ();
56 virtual void start_translation_timestep ();
57 virtual void stop_translation_timestep ();
58 virtual void acknowledge_audio_element (Audio_element_info);
59 virtual bool try_music (Music*);
60 virtual void create_audio_elements ();
64 Tie_performer::process_music ()
67 daddy_context_->set_property ("tieMelismaBusy", SCM_BOOL_T);
71 Tie_performer::Tie_performer ()
74 ties_created_ = false;
78 ENTER_DESCRIPTION (Tie_performer, "", "",
85 Tie_performer::try_music (Music *m)
96 Tie_performer::acknowledge_audio_element (Audio_element_info i)
98 if (Audio_note *nh = dynamic_cast<Audio_note *> (i.elem_))
101 if (m->is_mus_type ("note-event"))
102 now_notes_.push (CNote_melodic_tuple (nh, m, now_mom ()+ m->get_length ()));
107 Tie_performer::create_audio_elements ()
110 This is a nested loop. Not optimal, but good enough.
112 if (tied_notes_.size ())
114 Moment now = now_mom();
115 for (int i = tied_notes_.size (); i--; )
117 if (tied_notes_[i].end_ != now)
120 for (int j = now_notes_.size(); j--;)
123 = Pitch::compare (*unsmob_pitch (tied_notes_[i].event_->get_mus_property ("pitch")),
124 *unsmob_pitch (now_notes_[j].event_->get_mus_property ("pitch")));
129 Audio_tie * p = new Audio_tie;
130 p->set_note (LEFT, tied_notes_[i].note_);
131 p->set_note (RIGHT, now_notes_[j].note_);
133 announce_element (Audio_element_info (p, event_));
134 ties_created_ = true;
146 Tie_performer::stop_translation_timestep ()
148 if (prev_event_ && tied_notes_.size () && !ties_.size ()
149 && now_notes_.size ())
151 prev_event_->origin ()->warning (_ ("No ties were performed."));
162 tied_notes_ = now_notes_ ;
163 prev_event_ = event_;
167 now_notes_ .clear ();
169 for (int i=ties_.size (); i--;)
171 ties_[i]->note_drul_[RIGHT]->tie_to (ties_[i]->note_drul_[LEFT]);
178 Tie_performer::start_translation_timestep ()
181 ties_created_ = false;
182 Moment now = now_mom ();
183 for (int i= tied_notes_.size (); i-- ;)
185 if (tied_notes_[i].end_ < now)
193 CNote_melodic_tuple::CNote_melodic_tuple ()
200 CNote_melodic_tuple::CNote_melodic_tuple (Audio_note *h, Music*m, Moment mom)
208 CNote_melodic_tuple::pitch_compare (CNote_melodic_tuple const&h1,
209 CNote_melodic_tuple const &h2)
211 SCM p1 = h1.event_->get_mus_property ("pitch");
212 SCM p2 = h2.event_->get_mus_property ("pitch");
213 return Pitch::compare (*unsmob_pitch (p1),
218 CNote_melodic_tuple::time_compare (CNote_melodic_tuple const&h1,
219 CNote_melodic_tuple const &h2)
221 return (h1.end_ - h2.end_).main_part_.sign ();