2 midi-walker.cc -- implement Midi_walker
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "midi-walker.hh"
12 #include "audio-column.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 Moment m = (left.key - right.key);
36 Midi_walker::Midi_walker (Audio_staff *audio_staff, Midi_track *track,
42 items_ = &audio_staff->audio_items_;
47 Midi_walker::~Midi_walker ()
50 do_stop_notes (last_mom_ + Moment (Rational (10, 1)));
54 Find out if start_note event is needed, and do it if needed.
57 Midi_walker::do_start_note (Midi_note *note)
59 Audio_item *ptr = (*items_)[index_];
60 Moment stop_mom = note->get_length () + ptr->audio_column_->at_mom ();
62 bool play_start = true;
63 for (vsize i = 0; i < stop_note_queue.size (); i++)
65 /* if this pith already in queue */
66 if (stop_note_queue[i].val->get_semitone_pitch () == note->get_semitone_pitch ())
68 if (stop_note_queue[i].key < stop_mom)
70 /* let stopnote in queue be ignored,
72 stop_note_queue[i].ignore_b_ = true;
73 /* don't replay start note, */
79 /* skip this stopnote,
80 don't play the start note */
91 e.val = new Midi_note_off (note);
93 stop_note_queue.insert (e);
96 output_event (ptr->audio_column_->at_mom (), note);
101 Output note events for all notes which end before #max_mom#
104 Midi_walker::do_stop_notes (Moment max_mom)
106 while (stop_note_queue.size () && stop_note_queue.front ().key <= max_mom)
108 Midi_note_event e = stop_note_queue.get ();
115 Moment stop_mom = e.key;
116 Midi_note *note = e.val;
118 output_event (stop_mom, note);
123 Advance the track to #now#, output the item, and adjust current "moment".
126 Midi_walker::output_event (Moment now_mom, Midi_item *l)
128 Moment delta_t = now_mom - last_mom_;
132 this is not correct, but at least it doesn't crash when you
135 if (delta_t < Moment (0))
136 delta_t = Moment (0);
138 track_->add (delta_t, l);
142 Midi_walker::process ()
144 Audio_item *audio = (*items_)[index_];
145 do_stop_notes (audio->audio_column_->at_mom ());
147 if (Midi_item *midi = Midi_item::get_midi (audio))
149 if (Midi_channel_item *mci = dynamic_cast<Midi_channel_item*> (midi))
150 mci->channel_ = channel_;
152 //midi->channel_ = track_->number_;
153 if (Midi_note *note = dynamic_cast<Midi_note *> (midi))
155 if (note->get_length ().to_bool ())
156 do_start_note (note);
159 output_event (audio->audio_column_->at_mom (), midi);
164 Midi_walker::ok () const
166 return index_ < items_->size ();
170 Midi_walker::operator ++ (int)