13
0

Use boost::shared_ptr for RAII with a SNDFILE handle in Session::import_audiofile

A scoped_ptr would be more suitable and efficient but scoped_ptr doesn't support
a custom deleter function(sf_close in this case), there are ways around that
limitation but I don't think it is worth doing at this point as it requires more
code etc.


git-svn-id: svn://localhost/ardour2/trunk@2656 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Tim Mayberry 2007-11-15 02:31:09 +00:00
parent 108e924ad5
commit 1c70e4393e

View File

@ -53,7 +53,6 @@ using namespace PBD;
int
Session::import_audiofile (import_status& status)
{
SNDFILE *in;
vector<boost::shared_ptr<AudioFileSource> > newfiles;
SF_INFO info;
float *data = 0;
@ -74,7 +73,9 @@ Session::import_audiofile (import_status& status)
for (vector<Glib::ustring>::iterator p = status.paths.begin(); p != status.paths.end(); ++p, ++cnt) {
if ((in = sf_open ((*p).c_str(), SFM_READ, &info)) == 0) {
boost::shared_ptr<SNDFILE> in (sf_open (p->c_str(), SFM_READ, &info), sf_close);
if (!in) {
error << string_compose(_("Import: cannot open input sound file \"%1\""), (*p)) << endmsg;
status.done = 1;
status.cancel = 1;
@ -82,9 +83,9 @@ Session::import_audiofile (import_status& status)
}
if ((nframes_t) info.samplerate != frame_rate()) {
importable = new ResampledImportableSource (in, &info, frame_rate(), status.quality);
importable = new ResampledImportableSource (in.get(), &info, frame_rate(), status.quality);
} else {
importable = new ImportableSource (in, &info);
importable = new ImportableSource (in.get(), &info);
}
newfiles.clear ();
@ -261,7 +262,6 @@ Session::import_audiofile (import_status& status)
delete importable;
}
sf_close (in);
status.done = true;
return ret;