+ for (uint n = 0; n < channels; ++n) {
+
+ const DataType type = SMFSource::safe_midi_file_extension (import_file_path) ? DataType::MIDI : DataType::AUDIO;
+
+ std::string filepath = (type == DataType::MIDI)
+ ? sdir.midi_path().to_string() : sdir.sound_path().to_string();
+
+ filepath = Glib::build_filename (filepath,
+ get_non_existent_filename (hf, type, allow_replacing, filepath, basename, n, channels));
+ new_paths.push_back (filepath);
+ }
+
+ return new_paths;
+}
+
+static bool
+map_existing_mono_sources (const vector<string>& new_paths, Session& /*sess*/,
+ uint /*samplerate*/, vector<boost::shared_ptr<Source> >& newfiles, Session *session)
+{
+ for (vector<string>::const_iterator i = new_paths.begin();
+ i != new_paths.end(); ++i)
+ {
+ boost::shared_ptr<Source> source = session->source_by_path_and_channel(*i, 0);
+
+ if (source == 0) {
+ error << string_compose(_("Could not find a source for %1 even though we are updating this file!"), (*i)) << endl;
+ return false;
+ }
+
+ newfiles.push_back(boost::dynamic_pointer_cast<Source>(source));
+ }
+ return true;
+}
+
+static bool
+create_mono_sources_for_writing (const string& origin,
+ const vector<string>& new_paths,
+ Session& sess, uint samplerate,
+ vector<boost::shared_ptr<Source> >& newfiles,
+ framepos_t timeline_position)
+{
+ for (vector<string>::const_iterator i = new_paths.begin(); i != new_paths.end(); ++i) {
+
+ boost::shared_ptr<Source> source;
+
+ try {
+ const DataType type = SMFSource::safe_midi_file_extension (*i) ? DataType::MIDI : DataType::AUDIO;
+
+ source = SourceFactory::createWritable (type, sess,
+ i->c_str(),
+ origin,
+ false, // destructive
+ samplerate);