From c99738d88e8a2ad806b219b9f3614a6b55b6bf37 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 20 Jul 2011 18:13:03 +0000 Subject: try to fix data loss at end of a capture pass for MIDI - add a new virtual method to MidiSource that specifies what should be done with stuck notes, remove duplicate(i hope) _last_flush_frame from SMFSource that mirrored, more or less, MidiSource::_last_write_end; use new virtual method when stopping after capture. git-svn-id: svn://localhost/ardour2/branches/3.0@9910 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/smf_source.cc | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'libs/ardour/smf_source.cc') diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 7d90b58859..9e777b6ae5 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -243,16 +243,21 @@ SMFSource::write_unlocked (MidiRingBuffer& source, framepos_t positi cerr << "SMFSource::write unlocked, begins writing from src buffer with _last_write_end = " << _last_write_end << " dur = " << duration << endl; while (true) { - bool ret = source.peek ((uint8_t*)&time, sizeof (time)); - if (!ret || time > _last_write_end + duration) { - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("SMFSource::write_unlocked: dropping event @ %1 because ret %4 or it is later than %2 + %3\n", - time, _last_write_end, duration, ret)); + bool ret; + + if (!(ret = source.peek ((uint8_t*)&time, sizeof (time)))) { + /* no more events to consider */ break; } - ret = source.read_prefix(&time, &type, &size); - if (!ret) { - cerr << "ERROR: Unable to read event prefix, corrupt MIDI ring buffer" << endl; + if ((duration != max_framecnt) && (time > (_last_write_end + duration))) { + DEBUG_TRACE (DEBUG::MidiIO, string_compose ("SMFSource::write_unlocked: dropping event @ %1 because it is later than %2 + %3\n", + time, _last_write_end, duration)); + break; + } + + if (!(ret = source.read_prefix (&time, &type, &size))) { + error << _("Unable to read event prefix, corrupt MIDI ring buffer") << endmsg; break; } @@ -263,7 +268,7 @@ SMFSource::write_unlocked (MidiRingBuffer& source, framepos_t positi ret = source.read_contents(size, buf); if (!ret) { - cerr << "ERROR: Read time/size but not buffer, corrupt MIDI ring buffer" << endl; + error << _("Read time/size but not buffer, corrupt MIDI ring buffer") << endmsg; break; } @@ -430,9 +435,15 @@ SMFSource::mark_streaming_midi_write_started (NoteMode mode) void SMFSource::mark_streaming_write_completed () +{ + mark_midi_streaming_write_completed (Evoral::Sequence::DeleteStuckNotes); +} + +void +SMFSource::mark_midi_streaming_write_completed (Evoral::Sequence::StuckNoteOption stuck_notes_option, Evoral::MusicalTime when) { Glib::Mutex::Lock lm (_lock); - MidiSource::mark_streaming_write_completed(); + MidiSource::mark_midi_streaming_write_completed (stuck_notes_option, when); if (!writable()) { return; @@ -551,8 +562,7 @@ SMFSource::load_model (bool lock, bool force_reload) have_event_id = false; } - _model->end_write (_length_beats, false, true); - //_model->end_write (false); + _model->end_write (Evoral::Sequence::ResolveStuckNotes, _length_beats); _model->set_edited (false); _model_iter = _model->begin(); -- cgit v1.2.3