r59@gandalf: fugalh | 2006-06-15 12:16:20 -0600
[ardour.git] / libs / ardour / sndfilesource.cc
index 399f632caacebe1874f0575aea9898c69073dad1..87f7faf423dff8330f8c83f4a8976233044e2276 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000 Paul Davis 
+    Copyright (C) 2006 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
     $Id$
 */
 
-#include <string>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include <pbd/mountpoint.h>
 #include <ardour/sndfilesource.h>
 
 #include "i18n.h"
 
 using namespace ARDOUR;
 
-string SndFileSource::peak_dir = "";
-
 SndFileSource::SndFileSource (const XMLNode& node)
-       : Source (node)
+       : ExternalSource (node)
 {
-       if (set_state (node)) {
-               throw failed_constructor();
-       }
-
        init (_name, true);
-        SourceCreated (this); /* EMIT SIGNAL */
+       SourceCreated (this); /* EMIT SIGNAL */
 }
 
 SndFileSource::SndFileSource (const string& idstr, bool build_peak)
-       : Source(build_peak)
+       : ExternalSource(idstr, build_peak)
 {
        init (idstr, build_peak);
 
@@ -84,12 +72,12 @@ SndFileSource::init (const string& idstr, bool build_peak)
        if ((sf = sf_open (file.c_str(), SFM_READ, &_info)) == 0) {
                char errbuf[256];
                sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-               error << compose(_("SndFileSource: cannot open file \"%1\" (%2)"), file, errbuf) << endmsg;
+               error << string_compose(_("SndFileSource: cannot open file \"%1\" (%2)"), file, errbuf) << endmsg;
                throw failed_constructor();
        }
 
        if (channel >= _info.channels) {
-               error << compose(_("SndFileSource: file only contains %1 channels; %2 is invalid as a channel number"), _info.channels, channel) << endmsg;
+               error << string_compose(_("SndFileSource: file only contains %1 channels; %2 is invalid as a channel number"), _info.channels, channel) << endmsg;
                sf_close (sf);
                sf = 0;
                throw failed_constructor();
@@ -99,7 +87,7 @@ SndFileSource::init (const string& idstr, bool build_peak)
        _path = file;
 
        if (build_peak) {
-               if (initialize_peakfile (false, file)) {
+               if (initialize_peakfile (false, _path)) {
                        sf_close (sf);
                        sf = 0;
                        throw failed_constructor ();
@@ -110,7 +98,7 @@ SndFileSource::init (const string& idstr, bool build_peak)
 SndFileSource::~SndFileSource ()
 
 {
-        GoingAway (this); /* EMIT SIGNAL */
+       GoingAway (this); /* EMIT SIGNAL */
 
        if (sf) {
                sf_close (sf);
@@ -121,14 +109,14 @@ SndFileSource::~SndFileSource ()
        }
 }
 
-jack_nframes_t
-SndFileSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
+float
+SndFileSource::sample_rate () const 
 {
-       return read (dst, start, cnt);
+       return _info.samplerate;
 }
 
 jack_nframes_t
-SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
+SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
 {
        int32_t nread;
        float *ptr;
@@ -137,7 +125,7 @@ SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) cons
        if (sf_seek (sf, (off_t) start, SEEK_SET) < 0) {
                char errbuf[256];
                sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-               error << compose(_("SndFileSource: could not seek to frame %1 within %2 (%3)"), start, _name.substr (1), errbuf) << endmsg;
+               error << string_compose(_("SndFileSource: could not seek to frame %1 within %2 (%3)"), start, _name.substr (1), errbuf) << endmsg;
                return 0;
        }
 
@@ -150,7 +138,7 @@ SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) cons
        real_cnt = cnt * _info.channels;
 
        {
-               LockMonitor lm (_tmpbuf_lock, __LINE__, __FILE__);
+               Glib::Mutex::Lock lm (_tmpbuf_lock);
                
                if (tmpbufsize < real_cnt) {
                        
@@ -178,30 +166,3 @@ SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) cons
        return nread;
 }
 
-string
-SndFileSource::peak_path (string audio_path)
-{
-       /* XXX hardly bombproof! fix me */
-
-       struct stat stat_file;
-       struct stat stat_mount;
-
-       string mp = mountpoint (audio_path);
-
-       stat (audio_path.c_str(), &stat_file);
-       stat (mp.c_str(), &stat_mount);
-
-       char buf[32];
-       snprintf (buf, sizeof (buf), "%ld-%ld-%d.peak", stat_mount.st_ino, stat_file.st_ino, channel);
-
-       string res = peak_dir;
-       res += buf;
-
-       return res;
-}
-
-string
-SndFileSource::old_peak_path (string audio_path)
-{
-       return peak_path (audio_path);
-}