#include <pbd/basename.h>
#include <ardour/ardour.h>
+#include <ardour/types.h>
#include <ardour/session.h>
+#include <ardour/session_directory.h>
#include <ardour/audio_diskstream.h>
#include <ardour/sndfilesource.h>
#include <ardour/sndfile_helpers.h>
float *data = 0;
Sample **channel_data = 0;
long nfiles = 0;
- long n;
string basepath;
string sounds_dir;
nframes_t so_far;
if ((in = sf_open (status.paths.front().c_str(), SFM_READ, &info)) == 0) {
error << string_compose(_("Import: cannot open input sound file \"%1\""), status.paths.front()) << endmsg;
+ status.done = 1;
+ status.cancel = 1;
return -1;
}
importable = new ImportableSource (in, &info);
}
- for (n = 0; n < info.channels; ++n) {
+ for (int n = 0; n < info.channels; ++n) {
newfiles.push_back (boost::shared_ptr<AudioFileSource>());
}
- sounds_dir = discover_best_sound_dir ();
+ SessionDirectory sdir(get_best_session_directory_for_new_source ());
+ sounds_dir = sdir.sound_path().to_string();
+
basepath = PBD::basename_nosuffix (status.paths.front());
- for (n = 0; n < info.channels; ++n) {
+ for (int n = 0; n < info.channels; ++n) {
bool goodfile = false;
snprintf (buf, sizeof(buf), "%s/%s-R.wav", sounds_dir.c_str(), basepath.c_str());
}
} else if (info.channels > 1) {
- snprintf (buf, sizeof(buf), "%s/%s-c%lu.wav", sounds_dir.c_str(), basepath.c_str(), n+1);
+ snprintf (buf, sizeof(buf), "%s/%s-c%d.wav", sounds_dir.c_str(), basepath.c_str(), n+1);
} else {
snprintf (buf, sizeof(buf), "%s/%s.wav", sounds_dir.c_str(), basepath.c_str());
}
- if (::access (buf, F_OK) == 0) {
+ if (Glib::file_test (buf, Glib::FILE_TEST_EXISTS)) {
/* if the file already exists, we must come up with
* a new name for it. for now we just keep appending
} while ( !goodfile);
try {
- newfiles[n] = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createWritable (*this, buf, false, frame_rate()));
+ newfiles[n] = boost::dynamic_pointer_cast<AudioFileSource> (
+ SourceFactory::createWritable (DataType::AUDIO, *this, buf, false, frame_rate()));
}
catch (failed_constructor& err) {
data = new float[nframes * info.channels];
channel_data = new Sample * [ info.channels ];
- for (n = 0; n < info.channels; ++n) {
+ for (int n = 0; n < info.channels; ++n) {
channel_data[n] = new Sample[nframes];
}
while (!status.cancel) {
- nframes_t nread;
+ nframes_t nread, nfread;
long x;
long chn;
if ((nread = importable->read (data, nframes)) == 0) {
break;
}
+ nfread = nread / info.channels;
/* de-interleave */
for (chn = 0; chn < info.channels; ++chn) {
-
- for (x = chn, n = 0; n < nframes; x += info.channels, ++n) {
+
+ nframes_t n;
+ for (x = chn, n = 0; n < nfread; x += info.channels, ++n) {
channel_data[chn][n] = (Sample) data[x];
}
}
/* flush to disk */
for (chn = 0; chn < info.channels; ++chn) {
- newfiles[chn]->write (channel_data[chn], nread / info.channels);
+ newfiles[chn]->write (channel_data[chn], nfread);
}
so_far += nread;
if (status.multichan) {
/* all sources are used in a single multichannel region */
- for (n = 0; n < nfiles && !status.cancel; ++n) {
+ for (int n = 0; n < nfiles && !status.cancel; ++n) {
/* flush the final length to the header */
newfiles[n]->update_header(0, *now, xnow);
sources.push_back(newfiles[n]);
status.new_regions.push_back (r);
} else {
- for (n = 0; n < nfiles && !status.cancel; ++n) {
+ for (int n = 0; n < nfiles && !status.cancel; ++n) {
/* flush the final length to the header */
}
if (channel_data) {
- for (n = 0; n < info.channels; ++n) {
+ for (int n = 0; n < info.channels; ++n) {
delete [] channel_data[n];
}
delete [] channel_data;
}
if (status.cancel) {
-
status.new_regions.clear ();
for (vector<string>::iterator i = new_paths.begin(); i != new_paths.end(); ++i) {
if ((err = src_process (src_state, &src_data))) {
error << string_compose(_("Import: %1"), src_strerror (err)) << endmsg ;
- return false ;
+ return 0 ;
}
/* Terminate if at end */
src_data.data_in += src_data.input_frames_used * sf_info->channels ;
src_data.input_frames -= src_data.input_frames_used ;
- return nframes;
+ return src_data.output_frames_gen * sf_info->channels;
}