/*
- 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);
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();
_path = file;
if (build_peak) {
- if (initialize_peakfile (false, file)) {
+ if (initialize_peakfile (false, _path)) {
sf_close (sf);
sf = 0;
throw failed_constructor ();
SndFileSource::~SndFileSource ()
{
- GoingAway (this); /* EMIT SIGNAL */
+ GoingAway (this); /* EMIT SIGNAL */
if (sf) {
sf_close (sf);
}
}
-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;
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;
}
real_cnt = cnt * _info.channels;
{
- LockMonitor lm (_tmpbuf_lock, __LINE__, __FILE__);
+ Glib::Mutex::Lock lm (_tmpbuf_lock);
if (tmpbufsize < real_cnt) {
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);
-}