Fix MIDI port offsets.
[ardour.git] / libs / ardour / disk_reader.cc
index 6f559b61676e7030e5d8a47d4e9f540a40228aba..624a9ac17d7fb0cff581c60427cd51bb3f58548e 100644 (file)
@@ -18,7 +18,6 @@
 */
 
 #include "pbd/enumwriter.h"
-#include "pbd/i18n.h"
 #include "pbd/memento_command.h"
 
 #include "ardour/audioengine.h"
@@ -36,6 +35,8 @@
 #include "ardour/session.h"
 #include "ardour/session_playlists.h"
 
+#include "pbd/i18n.h"
+
 using namespace ARDOUR;
 using namespace PBD;
 using namespace std;
@@ -49,11 +50,10 @@ bool DiskReader::_no_disk_output = false;
 
 DiskReader::DiskReader (Session& s, string const & str, DiskIOProcessor::Flag f)
        : DiskIOProcessor (s, str, f)
-       , _roll_delay (0)
        , overwrite_sample (0)
-        , overwrite_offset (0)
-        , _pending_overwrite (false)
-        , overwrite_queued (false)
+       , overwrite_offset (0)
+       , _pending_overwrite (false)
+       , overwrite_queued (false)
        , _gui_feed_buffer (AudioEngine::instance()->raw_buffer_size (DataType::MIDI))
 {
        file_sample[DataType::AUDIO] = 0;
@@ -126,12 +126,6 @@ DiskReader::set_name (string const & str)
        return true;
 }
 
-void
-DiskReader::set_roll_delay (ARDOUR::samplecnt_t nframes)
-{
-       _roll_delay = nframes;
-}
-
 XMLNode&
 DiskReader::state (bool full)
 {
@@ -259,11 +253,17 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
                }
        }
 
-       if (speed == 0.0 && (ms == MonitoringDisk)) {
-               /* stopped. Don't accidentally pass any data from disk
-                * into our outputs (e.g. via interpolation)
-                */
-               bufs.silence (nframes, 0);
+       if (speed == 0.0) {
+                       /* stopped. Don't accidentally pass any data from disk
+                        * into our outputs (e.g. via interpolation)
+                        * nor jump ahead playback_sample when not rolling
+                        */
+               if (ms == MonitoringDisk) {
+                       /* when monitoring disk, clear input data so far,
+                        * everything before the disk processor is not relevant.
+                        */
+                       bufs.silence (nframes, 0);
+               }
                return;
        }
 
@@ -325,13 +325,29 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
                                disk_signal = output.data ();
                        }
 
+                       if (start_sample < playback_sample) {
+                               cerr << owner()->name() << " SS = " << start_sample << " PS = " << playback_sample << endl;
+                               abort ();
+                       }
+
+                       if (start_sample != playback_sample) {
+                               cerr << owner()->name() << " playback not aligned, jump ahead " << (start_sample - playback_sample) << endl;
+
+                               if (can_internal_playback_seek (start_sample - playback_sample)) {
+                                       internal_playback_seek (start_sample - playback_sample);
+                               } else {
+                                       cerr << owner()->name() << " playback not possible: ss = " << start_sample << " ps = " << playback_sample << endl;
+                                       goto midi;
+                               }
+                       }
+
                        chaninfo->buf->get_read_vector (&(*chan)->rw_vector);
 
                        if (disk_samples_to_consume <= (samplecnt_t) chaninfo->rw_vector.len[0]) {
 
                                if (fabsf (speed) != 1.0f) {
                                        (void) interpolation.interpolate (
-                                               n, nframes,
+                                               n, disk_samples_to_consume,
                                                chaninfo->rw_vector.buf[0],
                                                disk_signal);
                                } else if (speed != 0.0) {
@@ -377,20 +393,23 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
                        }
 
                        if (scaling != 1.0f && speed != 0.0) {
-                               apply_gain_to_buffer (disk_signal, nframes, scaling);
+                               apply_gain_to_buffer (disk_signal, disk_samples_to_consume, scaling);
                        }
 
                        chaninfo->buf->increment_read_ptr (disk_samples_to_consume);
 
-                       if ((speed != 0.0) && (ms & MonitoringInput)) {
+                 monitor_mix:
+
+                       if (ms & MonitoringInput) {
                                /* mix the disk signal into the input signal (already in bufs) */
-                               mix_buffers_no_gain (output.data(), disk_signal, speed == 0.0 ? nframes : disk_samples_to_consume);
+                               mix_buffers_no_gain (output.data(), disk_signal, disk_samples_to_consume);
                        }
                }
        }
 
        /* MIDI data handling */
 
+  midi:
        if (!_session.declick_out_pending() && bufs.count().n_midi()) {
                MidiBuffer* dst;
 
@@ -612,6 +631,8 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
        ChannelList::iterator chan;
        boost::shared_ptr<ChannelList> c = channels.reader();
 
+       //sample = std::max ((samplecnt_t)0, sample -_session.worst_output_latency ());
+
        for (n = 0, chan = c->begin(); chan != c->end(); ++chan, ++n) {
                (*chan)->buf->reset ();
        }