X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Faudiosource.cc;h=0c820eed4d29b9c923fb0a14150b2c978b52b305;hb=7d96960b162d25da87c388a3083775e8770bba56;hp=f44628956a824293494462802fbdaaa401245945;hpb=b65f8073ba306ac2d85133875746767e7c6b0eb6;p=ardour.git diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc index f44628956a..0c820eed4d 100644 --- a/libs/ardour/audiosource.cc +++ b/libs/ardour/audiosource.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2000 Paul Davis + Copyright (C) 2000 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,6 +51,8 @@ using namespace PBD; using Glib::ustring; bool AudioSource::_build_missing_peakfiles = false; + +/** true if we want peakfiles (e.g. if we are displaying a GUI) */ bool AudioSource::_build_peakfiles = false; #define _FPP 256 @@ -69,11 +71,11 @@ AudioSource::AudioSource (Session& s, ustring name) peak_leftovers = 0; } -AudioSource::AudioSource (Session& s, const XMLNode& node) +AudioSource::AudioSource (Session& s, const XMLNode& node) : Source (s, node) , _length (0) { - + _peaks_built = false; _peak_byte_max = 0; peakfile = -1; @@ -83,7 +85,7 @@ AudioSource::AudioSource (Session& s, const XMLNode& node) peak_leftover_size = 0; peak_leftovers = 0; - if (set_state (node)) { + if (set_state (node, Stateful::loading_state_version)) { throw failed_constructor(); } } @@ -91,7 +93,7 @@ AudioSource::AudioSource (Session& s, const XMLNode& node) AudioSource::~AudioSource () { /* shouldn't happen but make sure we don't leak file descriptors anyway */ - + if (peak_leftover_cnt) { cerr << "AudioSource destroyed with leftover peak data pending" << endl; } @@ -116,7 +118,7 @@ AudioSource::get_state () } int -AudioSource::set_state (const XMLNode& node) +AudioSource::set_state (const XMLNode& node, int /*version*/) { const XMLProperty* prop; @@ -147,7 +149,7 @@ AudioSource::update_length (sframes_t pos, sframes_t cnt) ***********************************************************************/ bool -AudioSource::peaks_ready (sigc::slot the_slot, sigc::connection& conn) const +AudioSource::peaks_ready (boost::function doThisWhenReady, Connection& connect_here_if_not, EventLoop* event_loop) const { bool ret; Glib::Mutex::Lock lm (_peaks_ready_lock); @@ -157,7 +159,7 @@ AudioSource::peaks_ready (sigc::slot the_slot, sigc::connection& conn) con */ if (!(ret = _peaks_built)) { - conn = PeaksReady.connect (the_slot); + PeaksReady.connect (connect_here_if_not, doThisWhenReady, event_loop); } return ret; @@ -171,12 +173,12 @@ AudioSource::touch_peakfile () if (stat (peakpath.c_str(), &statbuf) != 0 || statbuf.st_size == 0) { return; } - + struct utimbuf tbuf; - + tbuf.actime = statbuf.st_atime; tbuf.modtime = time ((time_t) 0); - + utime (peakpath.c_str(), &tbuf); } @@ -207,7 +209,7 @@ AudioSource::initialize_peakfile (bool newfile, ustring audio_path) peakpath = peak_path (audio_path); /* if the peak file should be there, but isn't .... */ - + if (!newfile && !Glib::file_test (peakpath.c_str(), Glib::FILE_TEST_EXISTS)) { peakpath = find_broken_peakfile (peakpath, audio_path); } @@ -215,19 +217,19 @@ AudioSource::initialize_peakfile (bool newfile, ustring audio_path) if (stat (peakpath.c_str(), &statbuf)) { if (errno != ENOENT) { /* it exists in the peaks dir, but there is some kind of error */ - + error << string_compose(_("AudioSource: cannot stat peakfile \"%1\""), peakpath) << endmsg; return -1; } /* peakfile does not exist */ - + _peaks_built = false; - + } else { - + /* we found it in the peaks dir, so check it out */ - + if (statbuf.st_size == 0 || ((nframes_t) statbuf.st_size < ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) { // empty _peaks_built = false; @@ -235,7 +237,7 @@ AudioSource::initialize_peakfile (bool newfile, ustring audio_path) // Check if the audio file has changed since the peakfile was built. struct stat stat_file; int err = stat (audio_path.c_str(), &stat_file); - + if (err) { _peaks_built = false; _peak_byte_max = 0; @@ -258,8 +260,8 @@ AudioSource::initialize_peakfile (bool newfile, ustring audio_path) if (!newfile && !_peaks_built && _build_missing_peakfiles && _build_peakfiles) { build_peaks_from_scratch (); - } - + } + return 0; } @@ -274,6 +276,8 @@ nframes_t AudioSource::write (Sample *dst, nframes_t cnt) { Glib::Mutex::Lock lm (_lock); + /* any write makes the fill not removable */ + _flags = Flag (_flags & ~Removable); return write_unlocked (dst, cnt); } @@ -287,8 +291,8 @@ AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, sframes_t start, nfr * @param npeaks Number of peaks to write. */ -int -AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, sframes_t start, nframes_t cnt, +int +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); @@ -309,15 +313,15 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, sframes_t s #undef DEBUG_READ_PEAKS #ifdef DEBUG_READ_PEAKS - cerr << "======>RP: npeaks = " << npeaks - << " start = " << start - << " cnt = " << cnt - << " len = " << _length - << " samples_per_visual_peak =" << samples_per_visual_peak + cerr << "======>RP: npeaks = " << npeaks + << " start = " << start + << " cnt = " << cnt + << " len = " << _length + << " samples_per_visual_peak =" << samples_per_visual_peak << " expected was " << expected_peaks << " ... scale = " << scale << " PD ptr = " << peaks < _peak_byte_max) { ftruncate (peakfile, _peak_byte_max); } } -bool -AudioSource::file_changed (ustring path) -{ - struct stat stat_file; - struct stat stat_peak; - - int e1 = stat (path.c_str(), &stat_file); - int e2 = stat (peak_path(path).c_str(), &stat_peak); - - if (!e1 && !e2 && stat_file.st_mtime > stat_peak.st_mtime){ - return true; - } else { - return false; - } -} - nframes_t AudioSource::available_peaks (double zoom_factor) const { if (zoom_factor < _FPP) { return length(_timeline_position); // peak data will come from the audio file - } - + } + /* peak data comes from peakfile, but the filesize might not represent the valid data due to ftruncate optimizations, so use _peak_byte_max state. XXX - there might be some atomicity issues here, we should probably add a lock,