X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmidi-walker.cc;h=782c3e2932ea3d6cbf10066f43b82547746c064b;hb=3dd560c0c440c9e97730ca13f6d5abbb020bb02e;hp=48c4cf8723658aa6a4eb37ecd9b580f4500c8504;hpb=7c6bba557e7d5ab6b32d7cd17c947e76cb1c1172;p=lilypond.git diff --git a/lily/midi-walker.cc b/lily/midi-walker.cc index 48c4cf8723..782c3e2932 100644 --- a/lily/midi-walker.cc +++ b/lily/midi-walker.cc @@ -12,12 +12,13 @@ #include "audio-column.hh" #include "audio-staff.hh" #include "midi-item.hh" +#include "midi-chunk.hh" #include "midi-stream.hh" #include "warn.hh" Midi_note_event::Midi_note_event () { - ignore_b_ = false; + ignore_ = false; } int @@ -53,10 +54,13 @@ Midi_walker::Midi_walker (Audio_staff *audio_staff, Midi_track *track, Midi_walker::~Midi_walker () { - do_stop_notes (last_tick_ + 384); + junk_pointers (midi_events_); +} - for (vsize i = 0; i < midi_items_.size (); i++) - delete midi_items_[i]; +void +Midi_walker::finalize () +{ + do_stop_notes (INT_MAX); } /** @@ -66,6 +70,7 @@ void Midi_walker::do_start_note (Midi_note *note) { Audio_item *ptr = items_[index_]; + assert (note->audio_ == ptr); int stop_ticks = int (moment_to_real (note->audio_->length_mom_) * Real (384 * 4)) + ptr->audio_column_->ticks (); @@ -80,7 +85,8 @@ Midi_walker::do_start_note (Midi_note *note) { /* let stopnote in queue be ignored, new stop note wins */ - stop_note_queue[i].ignore_b_ = true; + stop_note_queue[i].ignore_ = true; + /* don't replay start note, */ play_start = false; break; @@ -89,7 +95,6 @@ Midi_walker::do_start_note (Midi_note *note) { /* skip this stopnote, don't play the start note */ - delete note; note = 0; break; } @@ -100,28 +105,24 @@ Midi_walker::do_start_note (Midi_note *note) { Midi_note_event e; e.val = new Midi_note_off (note); + + midi_events_.push_back (e.val); e.key = int (stop_ticks); stop_note_queue.insert (e); if (play_start) output_event (ptr->audio_column_->ticks (), note); - - midi_items_.push_back (e.val); } } -/** - Output note events for all notes which end before #max_mom# -*/ void Midi_walker::do_stop_notes (int max_ticks) { while (stop_note_queue.size () && stop_note_queue.front ().key <= max_ticks) { Midi_note_event e = stop_note_queue.get (); - if (e.ignore_b_) + if (e.ignore_) { - delete e.val; continue; } @@ -132,9 +133,6 @@ Midi_walker::do_stop_notes (int max_ticks) } } -/** - Advance the track to #now#, output the item, and adjust current "moment". -*/ void Midi_walker::output_event (int now_ticks, Midi_item *l) { @@ -160,12 +158,11 @@ Midi_walker::process () Audio_item *audio = items_[index_]; do_stop_notes (audio->audio_column_->ticks ()); - if (Midi_item *midi = Midi_item::get_midi (audio)) + if (Midi_item *midi = get_midi (audio)) { if (Midi_channel_item *mci = dynamic_cast (midi)) mci->channel_ = channel_; - //midi->channel_ = track_->number_; if (Midi_note *note = dynamic_cast (midi)) { if (note->audio_->length_mom_.to_bool ()) @@ -173,12 +170,17 @@ Midi_walker::process () } else output_event (audio->audio_column_->ticks (), midi); - - - midi_items_.push_back (midi); } } +Midi_item* +Midi_walker::get_midi (Audio_item *i) +{ + Midi_item *mi = Midi_item::get_midi (i); + midi_events_.push_back (mi); + return mi; +} + bool Midi_walker::ok () const {