Hopefully fix disappearing MIDI recorded regions on the first record of a new session.
authorCarl Hetherington <carl@carlh.net>
Tue, 1 Mar 2011 02:03:52 +0000 (02:03 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 1 Mar 2011 02:03:52 +0000 (02:03 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8993 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/midi_source.h
libs/ardour/midi_diskstream.cc
libs/ardour/midi_source.cc

index c58452c044e70ca1731940493c292f4252c81273..4cfba10930703a5ad627eea815ea3d89a2a2da17 100644 (file)
@@ -81,6 +81,7 @@ class MidiSource : virtual public Source, public boost::enable_shared_from_this<
        virtual void mark_streaming_midi_write_started (NoteMode mode, framepos_t start_time);
        virtual void mark_streaming_write_started ();
        virtual void mark_streaming_write_completed ();
+       void mark_write_starting_now ();
 
        virtual void session_saved();
 
index f434af50f39eb93469ef2d43ab5c72a17dd28304..89a497cf018f208d448837cb483bd1ce01325374 100644 (file)
@@ -520,6 +520,7 @@ MidiDiskstream::process (framepos_t transport_frame, pframes_t nframes, bool can
                calculate_record_range(ot, transport_frame, nframes, rec_nframes, rec_offset);
 
                if (rec_nframes && !was_recording) {
+                       _write_source->mark_write_starting_now ();
                        capture_captured = 0;
                        was_recording = true;
                }
index d330eb2bcd766f67f0c334f7adc8b63c577c00d2..16ff6ac7ac21f55185e18859e77db24617b195c4 100644 (file)
@@ -267,17 +267,32 @@ MidiSource::midi_write (MidiRingBuffer<framepos_t>& source, framepos_t source_st
 void
 MidiSource::mark_streaming_midi_write_started (NoteMode mode, framepos_t start_frame)
 {
-       set_timeline_position(start_frame);
-
        if (_model) {
                _model->set_note_mode(mode);
                _model->start_write();
        }
 
-       _last_write_end = start_frame;
        _writing = true;
 }
 
+void
+MidiSource::mark_write_starting_now ()
+{
+       /* I'm not sure if this is the best way to approach this, but
+          _last_write_end needs to be set up with the transport frame
+          when a record actually starts, as it is used by
+          SMFSource::write_unlocked to decide whether incoming notes
+          are within the correct time range.
+          mark_streaming_midi_write_started (perhaps a more logical
+          place to do this) is not called at exactly the time when
+          record starts, and I don't think it necessarily can be
+          because it is not RT-safe.
+       */
+
+       set_timeline_position (_session.transport_frame ());
+       _last_write_end = _session.transport_frame ();
+}
+
 void
 MidiSource::mark_streaming_write_started ()
 {