+ ret = add_sources (paths, sources, pos, mode, target_regions, target_tracks, track, true);
+
+ out:
+ set_canvas_cursor (current_canvas_cursor);
+ return ret;
+}
+
+int
+Editor::add_sources (vector<string> paths, SourceList& sources, framepos_t& pos, ImportMode mode,
+ int target_regions, int target_tracks, boost::shared_ptr<Track>& track, bool /*add_channel_suffix*/)
+{
+ vector<boost::shared_ptr<Region> > regions;
+ string region_name;
+ uint32_t input_chan = 0;
+ uint32_t output_chan = 0;
+ bool use_timestamp;
+
+ use_timestamp = (pos == -1);
+
+ // kludge (for MIDI we're abusing "channel" for "track" here)
+ if (SMFSource::safe_midi_file_extension (paths.front())) {
+ target_regions = -1;
+ }
+
+ if (target_regions == 1) {
+
+ /* take all the sources we have and package them up as a region */
+
+ region_name = region_name_from_path (paths.front(), (sources.size() > 1), false);
+
+ /* we checked in import_sndfiles() that there were not too many */
+
+ while (RegionFactory::region_by_name (region_name)) {
+ region_name = bump_name_once (region_name, '.');
+ }
+
+ PropertyList plist;
+
+ plist.add (ARDOUR::Properties::start, 0);
+ plist.add (ARDOUR::Properties::length, sources[0]->length (pos));
+ 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 (sources, plist);
+
+ if (use_timestamp && boost::dynamic_pointer_cast<AudioRegion>(r)) {
+ boost::dynamic_pointer_cast<AudioRegion>(r)->special_set_position(sources[0]->natural_position());
+ }
+
+ regions.push_back (r);
+
+
+ } else if (target_regions == -1 || target_regions > 1) {
+
+ /* take each source and create a region for each one */
+
+ SourceList just_one;
+ SourceList::iterator x;
+ uint32_t n;
+
+ for (n = 0, x = sources.begin(); x != sources.end(); ++x, ++n) {
+
+ just_one.clear ();
+ just_one.push_back (*x);
+
+ boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (*x);
+
+ if (fs) {
+ region_name = region_name_from_path (fs->path(), false, false, sources.size(), n);
+ } else{
+ region_name = (*x)->name();
+ }
+
+ 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);
+
+ if (use_timestamp && boost::dynamic_pointer_cast<AudioRegion>(r)) {
+ boost::dynamic_pointer_cast<AudioRegion>(r)->special_set_position((*x)->natural_position());
+ }
+
+ regions.push_back (r);
+ }
+ }
+
+ if (target_regions == 1) {
+ input_chan = regions.front()->n_channels();
+ } else {
+ if (target_tracks == 1) {
+ input_chan = regions.size();
+ } else {
+ input_chan = 1;
+ }
+ }