+ } catch (...) {
+ error << string_compose (_("MIDI file %1 was not readable (no reason available)"), source->file_path()) << endmsg;
+ }
+
+ if (buf) {
+ free (buf);
+ }
+}
+
+static void
+remove_file_source (boost::shared_ptr<Source> source)
+{
+ boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (source);
+
+ if (fs) {
+ ::unlink (fs->path().c_str());
+ }
+}
+
+// This function is still unable to cleanly update an existing source, even though
+// it is possible to set the ImportStatus flag accordingly. The functinality
+// is disabled at the GUI until the Source implementations are able to provide
+// the necessary API.
+void
+Session::import_files (ImportStatus& status)
+{
+ typedef vector<boost::shared_ptr<Source> > Sources;
+ Sources all_new_sources;
+ boost::shared_ptr<AudioFileSource> afs;
+ boost::shared_ptr<SMFSource> smfs;
+ uint channels = 0;
+
+ status.sources.clear ();
+
+ for (vector<string>::iterator p = status.paths.begin();
+ p != status.paths.end() && !status.cancel;
+ ++p)
+ {
+ boost::shared_ptr<ImportableSource> source;
+ std::auto_ptr<Evoral::SMF> smf_reader;
+ const DataType type = SMFSource::safe_midi_file_extension (*p) ? DataType::MIDI : DataType::AUDIO;
+
+ if (type == DataType::AUDIO) {
+ try {
+ source = open_importable_source (*p, frame_rate(), status.quality);
+ channels = source->channels();
+ } catch (const failed_constructor& err) {
+ error << string_compose(_("Import: cannot open input sound file \"%1\""), (*p)) << endmsg;
+ status.done = status.cancel = true;
+ return;
+ }
+
+ } else {
+ try {
+ smf_reader = std::auto_ptr<Evoral::SMF>(new Evoral::SMF());
+ smf_reader->open(*p);
+ channels = smf_reader->num_tracks();
+ } catch (...) {
+ error << _("Import: error opening MIDI file") << endmsg;
+ status.done = status.cancel = true;
+ return;
+ }