#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
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);
}
/**
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 ();
{
/* 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;
{
/* skip this stopnote,
don't play the start note */
- delete note;
note = 0;
break;
}
{
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;
}
}
}
-/**
- Advance the track to #now#, output the item, and adjust current "moment".
-*/
void
Midi_walker::output_event (int now_ticks, Midi_item *l)
{
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_channel_item*> (midi))
mci->channel_ = channel_;
- //midi->channel_ = track_->number_;
if (Midi_note *note = dynamic_cast<Midi_note *> (midi))
{
if (note->audio_->length_mom_.to_bool ())
}
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
{