+ boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (*x);
+
+ if (sources.size() > 1 && disposition == ImportDistinctChannels) {
+
+ /* generate a per-channel region name so that things work as
+ * intended
+ */
+
+ string path;
+
+ if (fs) {
+ region_name = basename_nosuffix (fs->path());
+ } else {
+ region_name = (*x)->name();
+ }
+
+ if (sources.size() == 2) {
+ if (n == 0) {
+ region_name += "-L";
+ } else {
+ region_name += "-R";
+ }
+ } else if (sources.size() > 2) {
+ region_name += string_compose ("-%1", n+1);
+ }
+
+ track_names.push_back (region_name);
+
+ } else {
+ if (fs) {
+ region_name = region_name_from_path (fs->path(), false, false, sources.size(), n);
+ } else {
+ region_name = (*x)->name();
+ }
+
+ if (SMFSource::safe_midi_file_extension (paths.front())) {
+ string track_name = string_compose ("%1-t%2", PBD::basename_nosuffix (fs->path()), (n + 1));
+ track_names.push_back (track_name);
+ } else {
+ track_names.push_back (PBD::basename_nosuffix (paths[n]));
+ }
+ }
+
+ PropertyList plist;
+
+ /* Fudge region length to ensure it is non-zero; make it 1 beat at 120bpm
+ for want of a better idea. It can't be too small, otherwise if this
+ is a MIDI region the conversion from frames -> beats -> frames will
+ round it back down to 0 again.
+ */
+ framecnt_t len = (*x)->length (pos);
+ if (len == 0) {
+ len = (60.0 / 120.0) * _session->frame_rate ();
+ }
+
+ plist.add (ARDOUR::Properties::start, 0);
+ plist.add (ARDOUR::Properties::length, len);
+ plist.add (ARDOUR::Properties::name, region_name);
+ plist.add (ARDOUR::Properties::layer, 0);
+ plist.add (ARDOUR::Properties::whole_file, true);
+ plist.add (ARDOUR::Properties::external, true);
+
+ boost::shared_ptr<Region> r = RegionFactory::create (just_one, plist);