Introduce new time for session-relative frame time, and make source interface capable...
[ardour.git] / libs / ardour / audiosource.cc
index b8366e0ac038a70e1d92e8fed326b57ed7a93cde..a25a2dc8abaa5648a13340c498f55690b5021a08 100644 (file)
@@ -41,6 +41,7 @@
 #include <ardour/cycle_timer.h>
 #include <ardour/session.h>
 #include <ardour/transient_detector.h>
+#include <ardour/runtime_functions.h>
 
 #include "i18n.h"
 
@@ -55,7 +56,7 @@ bool AudioSource::_build_peakfiles = false;
 #define _FPP 256
 
 AudioSource::AudioSource (Session& s, ustring name)
-       : Source (s, name, DataType::AUDIO)
+       : Source (s, DataType::AUDIO, name)
 {
        _peaks_built = false;
        _peak_byte_max = 0;
@@ -117,8 +118,6 @@ AudioSource::set_state (const XMLNode& node)
 {
        const XMLProperty* prop;
 
-       Source::set_state (node);
-
        if ((prop = node.property ("captured-for")) != 0) {
                _captured_for = prop->value();
        }
@@ -248,7 +247,7 @@ AudioSource::initialize_peakfile (bool newfile, ustring audio_path)
 }
 
 nframes_t
-AudioSource::read (Sample *dst, nframes_t start, nframes_t cnt) const
+AudioSource::read (Sample *dst, sframes_t start, nframes_t cnt) const
 {
        Glib::Mutex::Lock lm (_lock);
        return read_unlocked (dst, start, cnt);
@@ -262,13 +261,13 @@ AudioSource::write (Sample *dst, nframes_t cnt)
 }
 
 int
-AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, nframes_t start, nframes_t cnt, double samples_per_visual_peak) const
+AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, sframes_t start, nframes_t cnt, double samples_per_visual_peak) const
 {
        return read_peaks_with_fpp (peaks, npeaks, start, cnt, samples_per_visual_peak, _FPP);
 }
 
 int 
-AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, nframes_t start, nframes_t cnt, 
+AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, sframes_t start, nframes_t cnt, 
                                  double samples_per_visual_peak, nframes_t samples_per_file_peak) const
 {
        Glib::Mutex::Lock lm (_lock);
@@ -427,7 +426,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, nframes_t s
                        if (i == stored_peaks_read) {
 
                                uint32_t       start_byte = current_stored_peak * sizeof(PeakData);
-                               tnp = min ((_length/samples_per_file_peak - current_stored_peak), (nframes_t) expected_peaks);
+                               tnp = min ((nframes_t)(_length/samples_per_file_peak - current_stored_peak), (nframes_t) expected_peaks);
                                to_read = min (chunksize, tnp);
                                
 #ifdef DEBUG_READ_PEAKS
@@ -521,7 +520,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, nframes_t s
 
                        if (i == frames_read) {
                                
-                               to_read = min (chunksize, (_length - current_frame));
+                               to_read = min (chunksize, nframes_t(_length - current_frame));
 
                                if (to_read == 0) {
                                        /* XXX ARGH .. out by one error ... need to figure out why this happens
@@ -682,14 +681,15 @@ AudioSource::done_with_peakfile_writes (bool done)
 }
 
 int
-AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframes_t cnt, bool force, bool intermediate_peaks_ready)
+AudioSource::compute_and_write_peaks (Sample* buf, sframes_t first_frame, nframes_t cnt,
+               bool force, bool intermediate_peaks_ready)
 {
        return compute_and_write_peaks (buf, first_frame, cnt, force, intermediate_peaks_ready, _FPP);
 }
 
 int
-AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframes_t cnt, bool force, 
-                                     bool intermediate_peaks_ready, nframes_t fpp)
+AudioSource::compute_and_write_peaks (Sample* buf, sframes_t first_frame, nframes_t cnt,
+               bool force, bool intermediate_peaks_ready, nframes_t fpp)
 {
        Sample* buf2 = 0;
        nframes_t to_do;
@@ -912,11 +912,3 @@ AudioSource::available_peaks (double zoom_factor) const
        return (end/sizeof(PeakData)) * _FPP;
 }
 
-void
-AudioSource::update_length (nframes_t pos, nframes_t cnt)
-{
-       if (pos + cnt > _length) {
-               _length = pos+cnt;
-       }
-}
-