ExternalSource refactoring.

git-svn-id: svn://localhost/trunk/ardour2@373 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Taybin Rutkin
2006-03-10 17:09:59 +00:00
parent 0896e2e63f
commit 1e668dfaf2
18 changed files with 322 additions and 277 deletions

View File

@@ -37,6 +37,7 @@ cycle_timer.cc
default_click.cc
destructive_filesource.cc
diskstream.cc
externalsource.cc
filesource.cc
gain.cc
gdither.cc

View File

@@ -20,36 +20,26 @@
#ifndef __coreaudio_source_h__
#define __coreaudio_source_h__
#include <ardour/source.h>
#include <ardour/externalsource.h>
#include <AudioToolbox/ExtendedAudioFile.h>
namespace ARDOUR {
class CoreAudioSource : public Source {
class CoreAudioSource : public ExternalSource {
public:
CoreAudioSource (const string& path_plus_channel, bool build_peak = true);
CoreAudioSource (const XMLNode&);
~CoreAudioSource ();
jack_nframes_t length() const { return _length; }
jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
void mark_for_remove() {} // we never remove external sndfiles
string peak_path(string audio_path);
string old_peak_path(string audio_path);
string path() const { return _path; }
static void set_peak_dir (string dir) { peak_dir = dir; }
private:
static string peak_dir;
ExtAudioFileRef af;
uint16_t channel;
uint16_t n_channels;
mutable float *tmpbuf;
mutable jack_nframes_t tmpbufsize;
mutable PBD::Lock _tmpbuf_lock;
string _path;
void init (const string &str, bool build_peak);
jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;

View File

@@ -0,0 +1,68 @@
/*
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __external_source_h__
#define __external_source_h__
#include <ardour/source.h>
namespace ARDOUR {
struct SoundFileInfo {
float samplerate;
uint16_t channels;
int64_t length;
std::string format_name;
};
class ExternalSource : public Source {
public:
virtual ~ExternalSource ();
string path() const { return _path; }
virtual jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const = 0;
void mark_for_remove() {} // we never remove external sndfiles
string peak_path(string audio_path);
string old_peak_path(string audio_path);
static void set_peak_dir (string dir) { peak_dir = dir; }
static ExternalSource* create (const string& path_plus_channel, bool build_peak = true);
static ExternalSource* create (const XMLNode& node);
static bool get_soundfile_info (string path, SoundFileInfo& _info, string& error);
protected:
ExternalSource (const string& path_plus_channel, bool build_peak = true);
ExternalSource (const XMLNode&);
static string peak_dir;
uint16_t channel;
string _path;
virtual void init (const string &str, bool build_peak) = 0;
virtual jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
};
}; /* namespace ARDOUR */
#endif /* __external_source_h__ */

View File

@@ -36,13 +36,4 @@ int sndfile_data_width (int format);
string sndfile_major_format(int);
string sndfile_minor_format(int);
struct SoundFileInfo {
float samplerate;
uint16_t channels;
int64_t length;
std::string format_name;
};
bool get_soundfile_info (string path, SoundFileInfo& _info);
#endif /* __sndfile_helpers_h__ */

View 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
@@ -18,46 +18,38 @@
$Id$
*/
#ifndef __playlist_snd_file_buffer_h__
#define __playlist_snd_file_buffer_h__
#ifndef __sndfile_source_h__
#define __sndfile_source_h__
#include <sndfile.h>
#include <ardour/source.h>
#include <ardour/externalsource.h>
namespace ARDOUR {
class SndFileSource : public Source {
class SndFileSource : public ExternalSource {
public:
SndFileSource (const string& path_plus_channel, bool build_peak = true);
SndFileSource (const XMLNode&);
~SndFileSource ();
jack_nframes_t length() const { return _info.frames; }
jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
void mark_for_remove() {} // we never remove external sndfiles
string peak_path(string audio_path);
string old_peak_path(string audio_path);
string path() const { return _path; }
jack_nframes_t length() const { return _info.frames; }
static void set_peak_dir (string dir) { peak_dir = dir; }
jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
private:
static string peak_dir;
SNDFILE *sf;
SF_INFO _info;
uint16_t channel;
mutable float *tmpbuf;
mutable jack_nframes_t tmpbufsize;
mutable PBD::Lock _tmpbuf_lock;
string _path;
void init (const string &str, bool build_peak);
jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
};
}; /* namespace EDL */
}; /* namespace ARDOUR */
#endif /* __playlist_snd_file_buffer_h__ */
#endif /* __sndfile_source_h__ */

View File

@@ -17,33 +17,21 @@
*/
#include <string>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/time.h>
#include <pbd/mountpoint.h>
#include <ardour/coreaudio_source.h>
#include "i18n.h"
using namespace ARDOUR;
string CoreAudioSource::peak_dir = "";
CoreAudioSource::CoreAudioSource (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 */
}
CoreAudioSource::CoreAudioSource (const string& idstr, bool build_peak)
: Source(build_peak)
: ExternalSource(idstr, build_peak)
{
init (idstr, build_peak);
@@ -73,7 +61,6 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
file = idstr.substr (0, pos);
}
/* note that we temporarily truncated _id at the colon */
FSRef ref;
err = FSPathMakeRef ((UInt8*)file.c_str(), &ref, 0);
@@ -125,9 +112,8 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
}
CoreAudioSource::~CoreAudioSource ()
{
GoingAway (this); /* EMIT SIGNAL */
GoingAway (this); /* EMIT SIGNAL */
if (af) {
ExtAudioFileDispose (af);
@@ -138,12 +124,6 @@ CoreAudioSource::~CoreAudioSource ()
}
}
jack_nframes_t
CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
{
return read (dst, start, cnt, workbuf);
}
jack_nframes_t
CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
{
@@ -204,31 +184,3 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, ch
return real_cnt;
}
string
CoreAudioSource::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), "%u-%u-%d.peak", stat_mount.st_ino, stat_file.st_ino, channel);
string res = peak_dir;
res += buf;
return res;
}
string
CoreAudioSource::old_peak_path (string audio_path)
{
return peak_path (audio_path);
}

View File

@@ -0,0 +1,203 @@
/*
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sys/stat.h>
#include <unistd.h>
#include <sys/time.h>
#include <sndfile.h>
#include <pbd/mountpoint.h>
#include <ardour/externalsource.h>
#include <ardour/sndfilesource.h>
#include <ardour/sndfile_helpers.h>
// if these headers come before sigc++ is included
// the parser throws ObjC++ errors. (nil is a keyword)
#ifdef HAVE_COREAUDIO
#include <ardour/coreaudio_source.h>
#include <AudioToolbox/ExtendedAudioFile.h>
#include <AudioToolbox/AudioFormat.h>
#endif // HAVE_COREAUDIO
#include "i18n.h"
using namespace ARDOUR;
string ExternalSource::peak_dir = "";
ExternalSource::ExternalSource (const XMLNode& node)
: Source (node)
{
}
ExternalSource::ExternalSource (const string& idstr, bool build_peak)
: Source(build_peak)
{
}
ExternalSource::~ExternalSource ()
{
}
jack_nframes_t
ExternalSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
{
return read (dst, start, cnt, workbuf);
}
string
ExternalSource::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
ExternalSource::old_peak_path (string audio_path)
{
return peak_path (audio_path);
}
ExternalSource*
ExternalSource::create (const XMLNode& node)
{
return new SndFileSource (node);
}
ExternalSource*
ExternalSource::create (const string& idstr, bool build_peak)
{
return new SndFileSource (idstr, build_peak);
}
#ifdef HAVE_COREAUDIO
std::string
CFStringRefToStdString(CFStringRef stringRef)
{
CFIndex size =
CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) ,
kCFStringEncodingASCII);
char *buf = new char[size];
std::string result;
if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingASCII)) {
result = buf;
}
delete [] buf;
return result;
}
#endif // HAVE_COREAUDIO
bool
ExternalSource::get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg)
{
#ifdef HAVE_COREAUDIO
OSStatus err = noErr;
FSRef ref;
ExtAudioFileRef af = 0;
size_t size;
CFStringRef name;
err = FSPathMakeRef ((UInt8*)path.c_str(), &ref, 0);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
err = ExtAudioFileOpen(&ref, &af);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
AudioStreamBasicDescription absd;
memset(&absd, 0, sizeof(absd));
size = sizeof(AudioStreamBasicDescription);
err = ExtAudioFileGetProperty(af,
kExtAudioFileProperty_FileDataFormat, &size, &absd);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
_info.samplerate = absd.mSampleRate;
_info.channels = absd.mChannelsPerFrame;
size = sizeof(_info.length);
err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &size, &_info.length);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
size = sizeof(CFStringRef);
err = AudioFormatGetProperty(
kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
_info.format_name = CFStringRefToStdString(name);
ExtAudioFileDispose (af);
return true;
libsndfile:
#endif // HAVE_COREAUDIO
SNDFILE *sf;
SF_INFO sf_info;
sf_info.format = 0; // libsndfile says to clear this before sf_open().
if ((sf = sf_open ((char*) path.c_str(), SFM_READ, &sf_info)) == 0) {
char errbuf[256];
error_msg = sf_error_str (0, errbuf, sizeof (errbuf) - 1);
return false;
}
sf_close (sf);
_info.samplerate = sf_info.samplerate;
_info.channels = sf_info.channels;
_info.length = sf_info.frames;
_info.format_name = string_compose("Format: %1, %2",
sndfile_major_format(sf_info.format),
sndfile_minor_format(sf_info.format));
return true;
}

View File

@@ -282,7 +282,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
int
Session::second_stage_init (bool new_session)
{
SndFileSource::set_peak_dir (peak_dir());
ExternalSource::set_peak_dir (peak_dir());
if (!new_session) {
if (load_state (_current_snapshot_name)) {
@@ -1802,7 +1802,6 @@ Session::XMLSourceFactory (const XMLNode& node)
return 0;
}
try {
if (node.property (X_("destructive")) != 0) {
src = new DestructiveFileSource (node, frame_rate());
@@ -1814,7 +1813,7 @@ Session::XMLSourceFactory (const XMLNode& node)
catch (failed_constructor& err) {
try {
src = new SndFileSource (node);
src = ExternalSource::create (node);
}
catch (failed_constructor& err) {
@@ -2946,11 +2945,11 @@ Session::cleanup_sources (Session::cleanup_report& rep)
for (SourceList::iterator i = sources.begin(); i != sources.end(); ++i) {
FileSource* fs;
SndFileSource* sfs;
ExternalSource* sfs;
if ((fs = dynamic_cast<FileSource*> ((*i).second)) != 0) {
all_sources.insert (fs->path());
} else if ((sfs = dynamic_cast<SndFileSource*> ((*i).second)) != 0) {
} else if ((sfs = dynamic_cast<ExternalSource*> ((*i).second)) != 0) {
all_sources.insert (sfs->path());
}
}

View File

@@ -4,11 +4,6 @@
#include <sndfile.h>
#include <ardour/sndfile_helpers.h>
#ifdef HAVE_COREAUDIO
#include <AudioToolbox/ExtendedAudioFile.h>
#include <AudioToolbox/AudioFormat.h>
#endif // HAVE_COREAUDIO
#include "i18n.h"
using std::map;
@@ -197,101 +192,3 @@ sndfile_minor_format(int format)
}
}
#ifdef HAVE_COREAUDIO
std::string
CFStringRefToStdString(CFStringRef stringRef)
{
CFIndex size =
CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) ,
kCFStringEncodingASCII);
char *buf = new char[size];
std::string result;
if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingASCII)) {
result = buf;
}
delete [] buf;
return result;
}
#endif // HAVE_COREAUDIO
bool
get_soundfile_info (string path, SoundFileInfo& _info)
{
#ifdef HAVE_COREAUDIO
OSStatus err = noErr;
FSRef ref;
ExtAudioFileRef af = 0;
size_t size;
CFStringRef name;
err = FSPathMakeRef ((UInt8*)path.c_str(), &ref, 0);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
err = ExtAudioFileOpen(&ref, &af);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
AudioStreamBasicDescription absd;
memset(&absd, 0, sizeof(absd));
size = sizeof(AudioStreamBasicDescription);
err = ExtAudioFileGetProperty(af,
kExtAudioFileProperty_FileDataFormat, &size, &absd);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
_info.samplerate = absd.mSampleRate;
_info.channels = absd.mChannelsPerFrame;
size = sizeof(_info.length);
err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &size, &_info.length);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
size = sizeof(CFStringRef);
err = AudioFormatGetProperty(
kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name);
if (err != noErr) {
ExtAudioFileDispose (af);
goto libsndfile;
}
_info.format_name = CFStringRefToStdString(name);
ExtAudioFileDispose (af);
return true;
libsndfile:
#endif // HAVE_COREAUDIO
SNDFILE *sf;
SF_INFO sf_info;
sf_info.format = 0; // libsndfile says to clear this before sf_open().
if ((sf = sf_open ((char*) path.c_str(), SFM_READ, &sf_info)) == 0) {
return false;
}
sf_close (sf);
_info.samplerate = sf_info.samplerate;
_info.channels = sf_info.channels;
_info.length = sf_info.frames;
_info.format_name = string_compose("Format: %1, %2",
sndfile_major_format(sf_info.format),
sndfile_minor_format(sf_info.format));
return true;
}

View 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
@@ -18,33 +18,21 @@
$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);
@@ -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,12 +109,6 @@ SndFileSource::~SndFileSource ()
}
}
jack_nframes_t
SndFileSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
{
return read (dst, start, cnt, workbuf);
}
jack_nframes_t
SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
{
@@ -178,30 +160,3 @@ SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char
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);
}

View File

@@ -34,8 +34,6 @@
#include <pbd/pthread_utils.h>
#include <ardour/source.h>
#include <ardour/filesource.h>
#include <ardour/sndfilesource.h>
#include "i18n.h"