#include <ardour/sndfile_helpers.h>
#include <ardour/audioregion.h>
#include <ardour/region_factory.h>
+#include <ardour/source_factory.h>
+
#include "i18n.h"
Session::import_audiofile (import_status& status)
{
SNDFILE *in;
- AudioFileSource **newfiles = 0;
+ vector<boost::shared_ptr<AudioFileSource> > newfiles;
SourceList sources;
SF_INFO info;
float *data = 0;
long n;
string basepath;
string sounds_dir;
- jack_nframes_t so_far;
+ nframes_t so_far;
char buf[PATH_MAX+1];
int ret = -1;
vector<string> new_paths;
}
}
- newfiles = new AudioFileSource *[info.channels];
for (n = 0; n < info.channels; ++n) {
- newfiles[n] = 0;
+ newfiles.push_back (boost::shared_ptr<AudioFileSource>());
}
-
+
sounds_dir = discover_best_sound_dir ();
basepath = PBD::basename_nosuffix (status.pathname);
} while ( !goodfile);
-
try {
- newfiles[n] = new SndFileSource (buf,
- Config->get_native_file_data_format(),
- Config->get_native_file_header_format(),
- frame_rate ());
+ newfiles[n] = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createWritable (*this, buf, false, frame_rate()));
}
catch (failed_constructor& err) {
did not bother to create whole-file AudioRegions for them. Do it now.
*/
- boost::shared_ptr<AudioRegion> r (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (*newfiles[n], 0, newfiles[n]->length(), region_name_from_path (Glib::path_get_basename (newfiles[n]->name())),
- 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile | AudioRegion::Import))));
-
- status.new_regions.push_back (r);
+ status.new_regions.push_back (boost::dynamic_pointer_cast<AudioRegion>
+ (RegionFactory::create (boost::static_pointer_cast<Source> (newfiles[n]), 0, newfiles[n]->length(),
+ region_name_from_path (Glib::path_get_basename (newfiles[n]->name())),
+ 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile | AudioRegion::Import))));
}
}
}
}
- if (newfiles) {
- delete [] newfiles;
- }
-
if (tmp_convert_file.length()) {
unlink(tmp_convert_file.c_str());
}
sf_count_t input_count = 0;
SNDFILE* in = sf_open(infile.c_str(), SFM_READ, &sf_info);
+ if (!in) {
+ error << string_compose(_("Import/SRC: could not open input file: %1"), outfile) << endmsg;
+ return false;
+ }
sf_count_t total_input_frames = sf_info.frames;
outfile = build_tmp_convert_name(infile);
SNDFILE* out = sf_open(outfile.c_str(), SFM_RDWR, &sf_info);
- if(!out) {
- error << string_compose(_("Import: could not open temp file: %1"), outfile) << endmsg;
- return false;
- }
+ if (!out) {
+ error << string_compose(_("Import/SRC: could not open output file: %1"), outfile) << endmsg;
+ return false;
+ }
sf_seek (in, 0, SEEK_SET) ;
sf_seek (out, 0, SEEK_SET) ;
sf_close(in);
sf_close(out);
- status.done = true;
-
if (status.cancel) {
return false;
} else {