attempt to fix roll delay logic by moving it into DiskReader (the only place it matters)
[ardour.git] / libs / ardour / disk_io.cc
index 40f97cba0a2ab48523a5b60388dc0f0113cd06d2..60e7ea56bbc046d822cc459d339de201cb17888f 100644 (file)
@@ -54,17 +54,17 @@ DiskIOProcessor::DiskIOProcessor (Session& s, string const & str, Flag f)
        , _slaved (false)
        , loop_location (0)
        , in_set_state (false)
-        , file_frame (0)
         , playback_sample (0)
         , wrap_buffer_size (0)
         , speed_buffer_size (0)
        , _need_butler (false)
        , channels (new ChannelList)
-       , _midi_buf (new MidiRingBuffer<framepos_t> (s.butler()->midi_diskstream_buffer_size()))
-       , _frames_written_to_ringbuffer (0)
-       , _frames_read_from_ringbuffer (0)
+       , _midi_buf (new MidiRingBuffer<samplepos_t> (s.butler()->midi_diskstream_buffer_size()))
+       , _samples_written_to_ringbuffer (0)
+       , _samples_read_from_ringbuffer (0)
 {
        midi_interpolation.add_channel_to (0,0);
+       set_display_to_user (false);
 }
 
 void
@@ -76,17 +76,17 @@ DiskIOProcessor::init ()
 void
 DiskIOProcessor::set_buffering_parameters (BufferingPreset bp)
 {
-       framecnt_t read_chunk_size;
-       framecnt_t read_buffer_size;
-       framecnt_t write_chunk_size;
-       framecnt_t write_buffer_size;
+       samplecnt_t read_chunk_size;
+       samplecnt_t read_buffer_size;
+       samplecnt_t write_chunk_size;
+       samplecnt_t write_buffer_size;
 
        if (!get_buffering_presets (bp, read_chunk_size, read_buffer_size, write_chunk_size, write_buffer_size)) {
                return;
        }
 
-       DiskReader::set_chunk_frames (read_chunk_size);
-       DiskWriter::set_chunk_frames (write_chunk_size);
+       DiskReader::set_chunk_samples (read_chunk_size);
+       DiskWriter::set_chunk_samples (write_chunk_size);
 
        Config->set_audio_capture_buffer_seconds (write_buffer_size);
        Config->set_audio_playback_buffer_seconds (read_buffer_size);
@@ -94,10 +94,10 @@ DiskIOProcessor::set_buffering_parameters (BufferingPreset bp)
 
 bool
 DiskIOProcessor::get_buffering_presets (BufferingPreset bp,
-                                        framecnt_t& read_chunk_size,
-                                        framecnt_t& read_buffer_size,
-                                        framecnt_t& write_chunk_size,
-                                        framecnt_t& write_buffer_size)
+                                        samplecnt_t& read_chunk_size,
+                                        samplecnt_t& read_buffer_size,
+                                        samplecnt_t& write_chunk_size,
+                                        samplecnt_t& write_buffer_size)
 {
        switch (bp) {
        case Small:
@@ -147,24 +147,35 @@ DiskIOProcessor::configure_io (ChanCount in, ChanCount out)
 {
        DEBUG_TRACE (DEBUG::DiskIO, string_compose ("Configuring %1 for in:%2 out:%3\n", name(), in, out));
 
-       RCUWriter<ChannelList> writer (channels);
-       boost::shared_ptr<ChannelList> c = writer.get_copy();
+       bool changed = false;
 
-       uint32_t n_audio = in.n_audio();
+       {
+               RCUWriter<ChannelList> writer (channels);
+               boost::shared_ptr<ChannelList> c = writer.get_copy();
 
-       if (n_audio > c->size()) {
-               add_channel_to (c, n_audio - c->size());
-       } else if (n_audio < c->size()) {
-               remove_channel_from (c, c->size() - n_audio);
+               uint32_t n_audio = in.n_audio();
+
+               if (n_audio > c->size()) {
+                       add_channel_to (c, n_audio - c->size());
+                       changed = true;
+               } else if (n_audio < c->size()) {
+                       remove_channel_from (c, c->size() - n_audio);
+                       changed = true;
+               }
+
+               /* writer leaves scope, actual channel list is updated */
        }
 
        if (in.n_midi() > 0 && !_midi_buf) {
                const size_t size = _session.butler()->midi_diskstream_buffer_size();
-               _midi_buf = new MidiRingBuffer<framepos_t>(size);
+               _midi_buf = new MidiRingBuffer<samplepos_t>(size);
                midi_interpolation.add_channel_to (0,0);
+               changed = true;
        }
 
-       seek (_session.transport_frame());
+       if (changed) {
+               seek (_session.transport_sample());
+       }
 
        return Processor::configure_io (in, out);
 }
@@ -192,7 +203,7 @@ DiskIOProcessor::set_loop (Location *location)
 }
 
 void
-DiskIOProcessor::non_realtime_locate (framepos_t location)
+DiskIOProcessor::non_realtime_locate (samplepos_t location)
 {
        /* now refill channel buffers */
 
@@ -207,7 +218,7 @@ DiskIOProcessor::non_realtime_speed_change ()
        }
 
        if (_seek_required) {
-               seek (_session.transport_frame(), true);
+               seek (_session.transport_sample(), true);
                _seek_required = false;
        }
 }
@@ -215,7 +226,7 @@ DiskIOProcessor::non_realtime_speed_change ()
 bool
 DiskIOProcessor::realtime_speed_change ()
 {
-       const framecnt_t required_wrap_size = (framecnt_t) ceil (_session.get_block_size() * fabs (_session.transport_speed())) + 2;
+       const samplecnt_t required_wrap_size = (samplecnt_t) ceil (_session.get_block_size() * fabs (_session.transport_speed())) + 2;
        bool _buffer_reallocation_required;
 
        if (required_wrap_size > wrap_buffer_size) {
@@ -356,7 +367,7 @@ DiskIOProcessor::use_playlist (DataType dt, boost::shared_ptr<Playlist> playlist
        return 0;
 }
 
-DiskIOProcessor::ChannelInfo::ChannelInfo (framecnt_t bufsize)
+DiskIOProcessor::ChannelInfo::ChannelInfo (samplecnt_t bufsize)
 {
        buf = new RingBufferNPT<Sample> (bufsize);
 
@@ -371,7 +382,7 @@ DiskIOProcessor::ChannelInfo::ChannelInfo (framecnt_t bufsize)
 }
 
 void
-DiskIOProcessor::ChannelInfo::resize (framecnt_t bufsize)
+DiskIOProcessor::ChannelInfo::resize (samplecnt_t bufsize)
 {
        delete buf;
        buf = new RingBufferNPT<Sample> (bufsize);
@@ -387,10 +398,20 @@ DiskIOProcessor::ChannelInfo::~ChannelInfo ()
        capture_transition_buf = 0;
 }
 
+void
+DiskIOProcessor::drop_route ()
+{
+       _route.reset ();
+}
+
 void
 DiskIOProcessor::set_route (boost::shared_ptr<Route> r)
 {
        _route = r;
+
+       if (_route) {
+               _route->DropReferences.connect_same_thread (*this, boost::bind (&DiskIOProcessor::drop_route, this));
+       }
 }
 
 /** Get the start, end, and length of a location "atomically".
@@ -402,9 +423,9 @@ DiskIOProcessor::set_route (boost::shared_ptr<Route> r)
  */
 void
 DiskIOProcessor::get_location_times(const Location* location,
-                   framepos_t*     start,
-                   framepos_t*     end,
-                   framepos_t*     length)
+                   samplepos_t*     start,
+                   samplepos_t*     end,
+                   samplepos_t*     length)
 {
        if (location) {
                *start  = location->start();
@@ -412,3 +433,4 @@ DiskIOProcessor::get_location_times(const Location* location,
                *length = *end - *start;
        }
 }
+