2 midi-walker.cc -- implement Midi_walker
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "midi-walker.hh"
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "audio-staff.hh"
14 #include "midi-item.hh"
15 #include "midi-stream.hh"
18 Midi_note_event::Midi_note_event()
24 compare (Midi_note_event const& left, Midi_note_event const& right)
26 return sign (left.key - right.key);
29 Midi_walker::Midi_walker (Audio_staff* audio_staff_l, Midi_track* track_l)
33 item_l_arr_l_ = &audio_staff_l->audio_item_l_arr_;
37 Midi_walker::~Midi_walker()
40 do_stop_notes (last_mom_ + Moment (10, 1));
44 Find out if start_note event is needed, and do it if needed.
47 Midi_walker::do_start_note (Midi_note* note_p)
49 Audio_item* ptr = (*item_l_arr_l_)[index_];
50 Moment stop_mom = note_p->length_mom () + ptr->audio_column_l_->at_mom ();
52 bool play_start = true;
53 for (int i=0; i < stop_note_queue.size(); i++)
55 /* if this pith already in queue */
56 if (stop_note_queue[i].val->pitch_i() == note_p->pitch_i ())
58 if (stop_note_queue[i].key < stop_mom)
60 /* let stopnote in queue be ignored,
62 stop_note_queue[i].ignore_b_ = true;
65 /* don't replay start note, */
72 /* skip this stopnote,
73 don't play the start note */
84 e.val = new Midi_note_off (note_p);
86 stop_note_queue.insert (e);
89 output_event (ptr->audio_column_l_->at_mom (), note_p);
94 Output note events for all notes which end before #max_mom#
97 Midi_walker::do_stop_notes (Moment max_mom)
99 while (stop_note_queue.size() && stop_note_queue.front ().key <= max_mom)
101 Midi_note_event e = stop_note_queue.get();
108 Moment stop_mom = e.key;
109 Midi_note* note_p = e.val;
111 output_event (stop_mom, note_p);
116 Advance the track to #now#, output the item, and adjust current "moment".
119 Midi_walker::output_event (Moment now_mom, Midi_item* l)
121 Moment delta_t = now_mom - last_mom_ ;
122 last_mom_ += delta_t;
123 track_l_->add (delta_t, l);
127 Midi_walker::process()
129 Audio_item* audio_p = (*item_l_arr_l_)[index_];
130 do_stop_notes (audio_p->audio_column_l_->at_mom ());
133 THIS IS A MEMORY LEAK. FIXME.
134 where's the leak? Everything goet to Midi_track, in a killing_cons.
136 if (Midi_item* midi_p = Midi_item::midi_p (audio_p))
138 midi_p->channel_i_ = track_l_->number_i_;
139 if (Midi_note* note_p = dynamic_cast<Midi_note*>(midi_p))
141 if (note_p->length_mom ())
142 do_start_note (note_p);
145 output_event (audio_p->audio_column_l_->at_mom (), midi_p);
150 Midi_walker::ok () const
152 return index_ <item_l_arr_l_->size ();
156 Midi_walker::operator ++(int)