fixes for 98% of all the warnings/errors reported by OS X gcc on tiger
[ardour.git] / libs / ardour / smf_source.cc
index 35693bd6de25ada174319bfade0b2bc123f3be51..9e777b6ae5fde5351d71251455c9684a06ad8282 100644 (file)
@@ -240,15 +240,24 @@ SMFSource::write_unlocked (MidiRingBuffer<framepos_t>& source, framepos_t positi
 
        Evoral::MIDIEvent<framepos_t> ev;
 
+       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) {
+               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;
                }
 
@@ -259,7 +268,7 @@ SMFSource::write_unlocked (MidiRingBuffer<framepos_t>& 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;
                }
 
@@ -277,11 +286,12 @@ SMFSource::write_unlocked (MidiRingBuffer<framepos_t>& source, framepos_t positi
                        continue;
                }
 
+               cerr << "SMFSource:: calling append_event_unlocked_frames()\n";
                append_event_unlocked_frames(ev, position);
        }
 
        Evoral::SMF::flush();
-       free(buf);
+       free (buf);
 
        return duration;
 }
@@ -296,9 +306,9 @@ SMFSource::append_event_unlocked_beats (const Evoral::Event<double>& ev)
                return;
        }
 
-       /* printf("SMFSource: %s - append_event_unlocked_beats ID = %d time = %lf, size = %u, data = ",
+       /*printf("SMFSource: %s - append_event_unlocked_beats ID = %d time = %lf, size = %u, data = ",
                name().c_str(), ev.id(), ev.time(), ev.size());
-           for (size_t i = 0; i < ev.size(); ++i) printf("%X ", ev.buffer()[i]); printf("\n");*/
+              for (size_t i = 0; i < ev.size(); ++i) printf("%X ", ev.buffer()[i]); printf("\n");*/
 
        assert(ev.time() >= 0);
        if (ev.time() < _last_ev_time_beats) {
@@ -336,6 +346,7 @@ SMFSource::append_event_unlocked_frames (const Evoral::Event<framepos_t>& ev, fr
 {
        assert(_writing);
        if (ev.size() == 0)  {
+               cerr << "SMFSource: asked to append zero-size event\n";
                return;
        }
 
@@ -424,9 +435,15 @@ SMFSource::mark_streaming_midi_write_started (NoteMode mode)
 
 void
 SMFSource::mark_streaming_write_completed ()
+{
+       mark_midi_streaming_write_completed (Evoral::Sequence<Evoral::MusicalTime>::DeleteStuckNotes);
+}
+
+void
+SMFSource::mark_midi_streaming_write_completed (Evoral::Sequence<Evoral::MusicalTime>::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;
@@ -446,7 +463,7 @@ SMFSource::mark_streaming_write_completed ()
 bool
 SMFSource::safe_midi_file_extension (const string& file)
 {
-       return (file.rfind(".mid") != string::npos);
+       return (file.rfind(".mid") != string::npos) || (file.rfind (".MID") != string::npos);
 }
 
 void
@@ -545,8 +562,8 @@ SMFSource::load_model (bool lock, bool force_reload)
                have_event_id = false;
        }
 
-       _model->end_write(false);
-       _model->set_edited(false);
+       _model->end_write (Evoral::Sequence<Evoral::MusicalTime>::ResolveStuckNotes, _length_beats);
+       _model->set_edited (false);
 
        _model_iter = _model->begin();
 
@@ -567,7 +584,7 @@ SMFSource::flush_midi ()
                return;
        }
 
-       Evoral::SMF::end_write();
+       Evoral::SMF::end_write ();
        /* data in the file means its no longer removable */
        mark_nonremovable ();
 }