+
+ newfiles.push_back(boost::dynamic_pointer_cast<Source>(source));
+
+ /* for audio files, reset the timeline position so that any BWF-ish
+ information in the original files we are importing from is maintained.
+ */
+
+ boost::shared_ptr<AudioFileSource> afs;
+ if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(source)) != 0) {
+ afs->set_timeline_position(timeline_position);
+ }
+ }
+ return true;
+}
+
+static string
+compose_status_message (const string& path,
+ uint file_samplerate,
+ uint session_samplerate,
+ uint /* current_file */,
+ uint /* total_files */)
+{
+ if (file_samplerate != session_samplerate) {
+ return string_compose (_("Resampling %1 from %2kHz to %3kHz"),
+ Glib::path_get_basename (path),
+ file_samplerate/1000.0f,
+ session_samplerate/1000.0f);
+ }
+
+ return string_compose (_("Copying %1"), Glib::path_get_basename (path));
+}
+
+static void
+write_audio_data_to_new_files (ImportableSource* source, ImportStatus& status,
+ vector<boost::shared_ptr<Source> >& newfiles)
+{
+ const framecnt_t nframes = ResampledImportableSource::blocksize;
+ boost::shared_ptr<AudioFileSource> afs;
+ uint channels = source->channels();
+
+ boost::scoped_array<float> data(new float[nframes * channels]);
+ vector<boost::shared_array<Sample> > channel_data;
+
+ for (uint n = 0; n < channels; ++n) {
+ channel_data.push_back(boost::shared_array<Sample>(new Sample[nframes]));
+ }
+
+ float gain = 1;
+
+ boost::shared_ptr<AudioSource> s = boost::dynamic_pointer_cast<AudioSource> (newfiles[0]);
+ assert (s);
+
+ status.progress = 0.0f;
+ float progress_multiplier = 1;
+ float progress_base = 0;
+
+ if (!source->clamped_at_unity() && s->clamped_at_unity()) {
+
+ /* The source we are importing from can return sample values with a magnitude greater than 1,
+ and the file we are writing the imported data to cannot handle such values. Compute the gain
+ factor required to normalize the input sources to have a magnitude of less than 1.
+ */
+
+ float peak = 0;
+ uint read_count = 0;