use -r argument with JACK if realtime is not requested in engine dialog (also applied...
[ArdourMidi.git] / gtk2_ardour / editor_audio_import.cc
blob2145b24352ba4a48c34fddb48072ab355b96c491
1 /*
2 Copyright (C) 2000-2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/time.h>
23 #include <errno.h>
24 #include <unistd.h>
25 #include <algorithm>
27 #include <sndfile.h>
29 #include "pbd/pthread_utils.h"
30 #include "pbd/basename.h"
31 #include "pbd/shortpath.h"
32 #include "pbd/stateful_diff_command.h"
34 #include <gtkmm2ext/choice.h>
36 #include "ardour/session.h"
37 #include "ardour/session_directory.h"
38 #include "ardour/audioplaylist.h"
39 #include "ardour/audioregion.h"
40 #include "ardour/audio_diskstream.h"
41 #include "ardour/midi_track.h"
42 #include "ardour/midi_region.h"
43 #include "ardour/utils.h"
44 #include "ardour/audio_track.h"
45 #include "ardour/audioplaylist.h"
46 #include "ardour/audiofilesource.h"
47 #include "ardour/region_factory.h"
48 #include "ardour/source_factory.h"
49 #include "ardour/session.h"
50 #include "ardour/smf_source.h"
51 #include "pbd/memento_command.h"
53 #include "ardour_ui.h"
54 #include "editor.h"
55 #include "sfdb_ui.h"
56 #include "editing.h"
57 #include "audio_time_axis.h"
58 #include "midi_time_axis.h"
59 #include "session_import_dialog.h"
60 #include "utils.h"
61 #include "gui_thread.h"
62 #include "interthread_progress_window.h"
64 #include "i18n.h"
66 using namespace std;
67 using namespace ARDOUR;
68 using namespace PBD;
69 using namespace Gtk;
70 using namespace Gtkmm2ext;
71 using namespace Editing;
72 using Glib::ustring;
74 /* Functions supporting the incorporation of external (non-captured) audio material into ardour */
76 void
77 Editor::add_external_audio_action (ImportMode mode_hint)
79 if (_session == 0) {
80 MessageDialog msg (_("You can't import or embed an audiofile until you have a session loaded."));
81 msg.run ();
82 return;
85 if (sfbrowser == 0) {
86 sfbrowser = new SoundFileOmega (*this, _("Add Existing Media"), _session, 0, true, mode_hint);
87 } else {
88 sfbrowser->set_mode (mode_hint);
91 external_audio_dialog ();
94 void
95 Editor::external_audio_dialog ()
97 vector<Glib::ustring> paths;
98 uint32_t track_cnt;
100 if (_session == 0) {
101 MessageDialog msg (_("You can't import or embed an audiofile until you have a session loaded."));
102 msg.run ();
103 return;
106 track_cnt = 0;
108 for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) {
109 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*x);
111 if (!atv) {
112 continue;
113 } else if (atv->is_audio_track()) {
114 track_cnt++;
118 if (sfbrowser == 0) {
119 sfbrowser = new SoundFileOmega (*this, _("Add Existing Media"), _session, track_cnt, true);
120 } else {
121 sfbrowser->reset (track_cnt);
124 sfbrowser->show_all ();
127 bool keepRunning;
129 do {
130 keepRunning = false;
132 int response = sfbrowser->run ();
134 switch (response) {
135 case RESPONSE_APPLY:
136 // leave the dialog open
137 break;
139 case RESPONSE_OK:
140 sfbrowser->hide ();
141 break;
143 default:
144 // cancel from the browser - we are done
145 sfbrowser->hide ();
146 return;
149 /* lets do it */
151 paths = sfbrowser->get_paths ();
153 ImportPosition pos = sfbrowser->get_position ();
154 ImportMode mode = sfbrowser->get_mode ();
155 ImportDisposition chns = sfbrowser->get_channel_disposition ();
156 nframes64_t where;
158 switch (pos) {
159 case ImportAtEditPoint:
160 where = get_preferred_edit_position ();
161 break;
162 case ImportAtTimestamp:
163 where = -1;
164 break;
165 case ImportAtPlayhead:
166 where = playhead_cursor->current_frame;
167 break;
168 case ImportAtStart:
169 where = _session->current_start_frame();
170 break;
173 SrcQuality quality = sfbrowser->get_src_quality();
176 if (sfbrowser->copy_files_btn.get_active()) {
177 do_import (paths, chns, mode, quality, where);
178 } else {
179 do_embed (paths, chns, mode, where);
182 if (response == RESPONSE_APPLY) {
183 sfbrowser->clear_selection ();
184 keepRunning = true;
187 } while (keepRunning);
190 void
191 Editor::session_import_dialog ()
193 SessionImportDialog dialog (_session);
194 ensure_float (dialog);
195 dialog.run ();
198 typedef std::map<PBD::ID,boost::shared_ptr<ARDOUR::Source> > SourceMap;
201 * Updating is still disabled, see note in libs/ardour/import.cc Session::import_audiofiles()
203 * all_or_nothing:
204 * true = show "Update", "Import" and "Skip"
205 * false = show "Import", and "Cancel"
207 * Returns:
208 * 0 To update an existing source of the same name
209 * 1 To import/embed the file normally (make sure the new name will be unique)
210 * 2 If the user wants to skip this file
213 Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
215 string wave_name (Glib::path_get_basename(path));
217 SourceMap all_sources = _session->get_sources();
218 bool wave_name_exists = false;
220 for (SourceMap::iterator i = all_sources.begin(); i != all_sources.end(); ++i) {
221 string tmp (Glib::path_get_basename (i->second->path()));
222 if (tmp == wave_name) {
223 wave_name_exists = true;
224 break;
228 int function = 1;
230 if (wave_name_exists) {
231 string message;
232 if (all_or_nothing) {
233 // updating is still disabled
234 //message = string_compose(_("The session already contains a source file named %1. Do you want to update that file (and thus all regions using the file) or import this file as a new file?"),wave_name);
235 message = string_compose (_("The session already contains a source file named %1. Do you want to import %1 as a new file, or skip it?"), wave_name);
236 } else {
237 message = string_compose (_("The session already contains a source file named %1. Do you want to import %2 as a new source, or skip it?"), wave_name, wave_name);
240 MessageDialog dialog(message, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);
242 if (all_or_nothing) {
243 // disabled
244 //dialog.add_button("Update", 0);
245 dialog.add_button("Import", 1);
246 dialog.add_button("Skip", 2);
247 } else {
248 dialog.add_button("Import", 1);
249 dialog.add_button("Cancel", 2);
252 //dialog.add_button("Skip all", 4); // All or rest?
254 dialog.show();
256 function = dialog.run ();
258 dialog.hide();
261 return function;
264 boost::shared_ptr<AudioTrack>
265 Editor::get_nth_selected_audio_track (int nth) const
267 AudioTimeAxisView* atv;
268 TrackSelection::iterator x;
270 for (x = selection->tracks.begin(); nth > 0 && x != selection->tracks.end(); ++x) {
272 atv = dynamic_cast<AudioTimeAxisView*>(*x);
274 if (!atv) {
275 continue;
276 } else if (atv->is_audio_track()) {
277 --nth;
281 if (x == selection->tracks.end()) {
282 atv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.back());
283 } else {
284 atv = dynamic_cast<AudioTimeAxisView*>(*x);
287 if (!atv || !atv->is_audio_track()) {
288 return boost::shared_ptr<AudioTrack>();
291 return atv->audio_track();
294 boost::shared_ptr<MidiTrack>
295 Editor::get_nth_selected_midi_track (int nth) const
297 MidiTimeAxisView* mtv;
298 TrackSelection::iterator x;
300 for (x = selection->tracks.begin(); nth > 0 && x != selection->tracks.end(); ++x) {
302 mtv = dynamic_cast<MidiTimeAxisView*>(*x);
304 if (!mtv) {
305 continue;
306 } else if (mtv->is_midi_track()) {
307 --nth;
311 if (x == selection->tracks.end()) {
312 mtv = dynamic_cast<MidiTimeAxisView*>(selection->tracks.back());
313 } else {
314 mtv = dynamic_cast<MidiTimeAxisView*>(*x);
317 if (!mtv || !mtv->is_midi_track()) {
318 return boost::shared_ptr<MidiTrack>();
321 return mtv->midi_track();
324 void
325 Editor::do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mode, SrcQuality quality, nframes64_t& pos)
327 boost::shared_ptr<Track> track;
328 vector<ustring> to_import;
329 int nth = 0;
331 current_interthread_info = &import_status;
332 import_status.current = 1;
333 import_status.total = paths.size ();
335 ImportProgressWindow ipw (&import_status, _("Import"), _("Cancel Import"));
337 if (chns == Editing::ImportMergeFiles) {
339 /* create 1 region from all paths, add to 1 track,
340 ignore "track"
343 bool cancel = false;
344 for (vector<ustring>::iterator a = paths.begin(); a != paths.end(); ++a) {
345 int check = check_whether_and_how_to_import(*a, false);
346 if (check == 2) {
347 cancel = true;
348 break;
352 if (!cancel) {
353 import_sndfiles (paths, mode, quality, pos, 1, 1, track, false);
356 } else {
358 bool replace = false;
359 bool ok = true;
361 for (vector<ustring>::iterator a = paths.begin(); a != paths.end(); ++a) {
363 const int check = check_whether_and_how_to_import (*a, true);
365 switch (check) {
366 case 2:
367 // user said skip
368 continue;
369 case 0:
370 fatal << "Updating existing sources should be disabled!" << endmsg;
371 /* NOTREACHED*/
372 break;
373 case 1:
374 replace = false;
375 break;
376 default:
377 fatal << "Illegal return " << check << " from check_whether_and_how_to_import()!" << endmsg;
378 /* NOTREACHED*/
381 switch (chns) {
382 case Editing::ImportDistinctFiles:
384 to_import.clear ();
385 to_import.push_back (*a);
387 if (mode == Editing::ImportToTrack) {
388 track = get_nth_selected_audio_track (nth++);
391 ok = (import_sndfiles (to_import, mode, quality, pos, 1, -1, track, replace) == 0);
392 break;
394 case Editing::ImportDistinctChannels:
396 to_import.clear ();
397 to_import.push_back (*a);
399 ok = (import_sndfiles (to_import, mode, quality, pos, -1, -1, track, replace) == 0);
400 break;
402 case Editing::ImportSerializeFiles:
404 to_import.clear ();
405 to_import.push_back (*a);
407 ok = (import_sndfiles (to_import, mode, quality, pos, 1, 1, track, replace) == 0);
408 break;
410 case Editing::ImportMergeFiles:
411 // Not entered, handled in earlier if() branch
412 break;
418 void
419 Editor::do_embed (vector<ustring> paths, ImportDisposition chns, ImportMode mode, nframes64_t& pos)
421 boost::shared_ptr<Track> track;
422 bool check_sample_rate = true;
423 bool ok = false;
424 vector<ustring> to_embed;
425 bool multi = paths.size() > 1;
426 int nth = 0;
428 switch (chns) {
429 case Editing::ImportDistinctFiles:
430 for (vector<ustring>::iterator a = paths.begin(); a != paths.end(); ++a) {
432 to_embed.clear ();
433 to_embed.push_back (*a);
435 if (mode == Editing::ImportToTrack) {
436 track = get_nth_selected_audio_track (nth++);
439 if (embed_sndfiles (to_embed, multi, check_sample_rate, mode, pos, 1, -1, track) < -1) {
440 goto out;
443 break;
445 case Editing::ImportDistinctChannels:
446 for (vector<ustring>::iterator a = paths.begin(); a != paths.end(); ++a) {
448 to_embed.clear ();
449 to_embed.push_back (*a);
451 if (embed_sndfiles (to_embed, multi, check_sample_rate, mode, pos, -1, -1, track) < -1) {
452 goto out;
455 break;
457 case Editing::ImportMergeFiles:
458 if (embed_sndfiles (paths, multi, check_sample_rate, mode, pos, 1, 1, track) < -1) {
459 goto out;
461 break;
463 case Editing::ImportSerializeFiles:
464 for (vector<ustring>::iterator a = paths.begin(); a != paths.end(); ++a) {
466 to_embed.clear ();
467 to_embed.push_back (*a);
469 if (embed_sndfiles (to_embed, multi, check_sample_rate, mode, pos, 1, 1, track) < -1) {
470 goto out;
473 break;
476 ok = true;
478 out:
479 if (ok) {
480 _session->save_state ("");
485 Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality quality, nframes64_t& pos,
486 int target_regions, int target_tracks, boost::shared_ptr<Track>& track, bool replace)
488 import_status.paths = paths;
489 import_status.done = false;
490 import_status.cancel = false;
491 import_status.freeze = false;
492 import_status.done = 0.0;
493 import_status.quality = quality;
494 import_status.replace_existing_source = replace;
496 import_status.mode = mode;
497 import_status.pos = pos;
498 import_status.target_tracks = target_tracks;
499 import_status.target_regions = target_regions;
500 import_status.track = track;
501 import_status.replace = replace;
503 track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
504 gdk_flush ();
506 /* start import thread for this spec. this will ultimately call Session::import_audiofiles()
507 which, if successful, will add the files as regions to the region list. its up to us
508 (the GUI) to direct additional steps after that.
511 pthread_create_and_store ("import", &import_status.thread, _import_thread, this);
512 pthread_detach (import_status.thread);
514 while (!import_status.done && !import_status.cancel) {
515 gtk_main_iteration ();
518 import_status.done = true;
520 if (!import_status.cancel && !import_status.sources.empty()) {
521 if (add_sources (import_status.paths,
522 import_status.sources,
523 import_status.pos,
524 import_status.mode,
525 import_status.target_regions,
526 import_status.target_tracks,
527 track, false) == 0) {
528 _session->save_state ("");
531 /* update position from results */
533 pos = import_status.pos;
537 track_canvas->get_window()->set_cursor (*current_canvas_cursor);
538 return 0;
542 Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
543 bool& check_sample_rate, ImportMode mode, nframes64_t& pos, int target_regions, int target_tracks,
544 boost::shared_ptr<Track>& track)
546 boost::shared_ptr<AudioFileSource> source;
547 SourceList sources;
548 string linked_path;
549 SoundFileInfo finfo;
550 int ret = 0;
551 Glib::ustring path_to_use;
553 track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
554 gdk_flush ();
556 for (vector<Glib::ustring>::iterator p = paths.begin(); p != paths.end(); ++p) {
558 ustring path = *p;
560 if (Config->get_try_link_for_embed()) {
562 /* lets see if we can link it into the session */
564 sys::path tmp = _session->session_directory().sound_path() / Glib::path_get_basename(path);
565 linked_path = tmp.to_string();
567 path_to_use = linked_path;
569 if (link (path.c_str(), linked_path.c_str()) == 0) {
571 /* there are many reasons why link(2) might have failed.
572 but if it succeeds, we now have a link in the
573 session sound dir that will protect against
574 unlinking of the original path. nice.
577 path = linked_path;
578 path_to_use = Glib::path_get_basename (path);
580 } else {
582 /* one possible reason is that its already linked */
584 if (errno == EEXIST) {
585 struct stat sb;
587 if (stat (linked_path.c_str(), &sb) == 0) {
588 if (sb.st_nlink > 1) { // its a hard link, assume its the one we want
589 path = linked_path;
590 path_to_use = Glib::path_get_basename (path);
597 /* note that we temporarily truncated _id at the colon */
599 string error_msg;
601 if (!AudioFileSource::get_soundfile_info (path, finfo, error_msg)) {
602 error << string_compose(_("Editor: cannot open file \"%1\", (%2)"), path, error_msg ) << endmsg;
603 goto out;
606 if (check_sample_rate && (finfo.samplerate != (int) _session->frame_rate())) {
607 vector<string> choices;
609 if (multifile) {
610 choices.push_back (_("Cancel entire import"));
611 choices.push_back (_("Don't embed it"));
612 choices.push_back (_("Embed all without questions"));
614 Gtkmm2ext::Choice rate_choice (
615 _("Sample rate"),
616 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"),
617 short_path (path, 40)),
618 choices, false
621 int resx = rate_choice.run ();
623 switch (resx) {
624 case 0: /* stop a multi-file import */
625 ret = -2;
626 goto out;
627 case 1: /* don't embed this one */
628 ret = -1;
629 goto out;
630 case 2: /* do it, and the rest without asking */
631 check_sample_rate = false;
632 break;
633 case 3: /* do it */
634 break;
635 default:
636 ret = -2;
637 goto out;
639 } else {
640 choices.push_back (_("Cancel"));
641 choices.push_back (_("Embed it anyway"));
643 Gtkmm2ext::Choice rate_choice (
644 _("Sample rate"),
645 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
646 choices, false
649 int resx = rate_choice.run ();
651 switch (resx) {
652 case 0: /* don't import */
653 ret = -1;
654 goto out;
655 case 1: /* do it */
656 break;
657 default:
658 ret = -2;
659 goto out;
664 track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
666 for (int n = 0; n < finfo.channels; ++n) {
667 try {
669 /* check if we have this thing embedded already */
671 boost::shared_ptr<Source> s;
673 if ((s = _session->source_by_path_and_channel (path, n)) == 0) {
675 source = boost::dynamic_pointer_cast<AudioFileSource> (
676 SourceFactory::createReadable (DataType::AUDIO, *_session,
677 path_to_use, n,
678 (mode == ImportAsTapeTrack
679 ? Source::Destructive
680 : Source::Flag (0)),
681 true, true));
682 } else {
683 source = boost::dynamic_pointer_cast<AudioFileSource> (s);
686 sources.push_back(source);
689 catch (failed_constructor& err) {
690 error << string_compose(_("could not open %1"), path) << endmsg;
691 goto out;
694 ARDOUR_UI::instance()->flush_pending ();
698 if (sources.empty()) {
699 goto out;
702 ret = add_sources (paths, sources, pos, mode, target_regions, target_tracks, track, true);
704 out:
705 track_canvas->get_window()->set_cursor (*current_canvas_cursor);
706 return ret;
710 Editor::add_sources (vector<Glib::ustring> paths, SourceList& sources, nframes64_t& pos, ImportMode mode,
711 int target_regions, int target_tracks, boost::shared_ptr<Track>& track, bool /*add_channel_suffix*/)
713 vector<boost::shared_ptr<Region> > regions;
714 ustring region_name;
715 uint32_t input_chan = 0;
716 uint32_t output_chan = 0;
717 bool use_timestamp;
719 use_timestamp = (pos == -1);
721 if (use_timestamp) {
722 if (sources[0]->natural_position() != 0) {
723 pos = sources[0]->natural_position();
724 } else {
725 pos = _session->current_start_frame();
729 // kludge (for MIDI we're abusing "channel" for "track" here)
730 if (SMFSource::safe_midi_file_extension (paths.front())) {
731 target_regions = -1;
734 if (target_regions == 1) {
736 /* take all the sources we have and package them up as a region */
738 region_name = region_name_from_path (paths.front(), (sources.size() > 1), false);
740 PropertyList plist;
742 plist.add (ARDOUR::Properties::start, 0);
743 plist.add (ARDOUR::Properties::length, sources[0]->length (pos));
744 plist.add (ARDOUR::Properties::name, region_name);
745 plist.add (ARDOUR::Properties::layer, 0);
746 plist.add (ARDOUR::Properties::whole_file, true);
747 plist.add (ARDOUR::Properties::external, true);
749 boost::shared_ptr<Region> r = RegionFactory::create (sources, plist);
751 if (use_timestamp && boost::dynamic_pointer_cast<AudioRegion>(r)) {
752 boost::dynamic_pointer_cast<AudioRegion>(r)->special_set_position(sources[0]->natural_position());
755 regions.push_back (r);
758 } else if (target_regions == -1 || target_regions > 1) {
760 /* take each source and create a region for each one */
762 SourceList just_one;
763 SourceList::iterator x;
764 uint32_t n;
766 for (n = 0, x = sources.begin(); x != sources.end(); ++x, ++n) {
768 just_one.clear ();
769 just_one.push_back (*x);
771 region_name = region_name_from_path ((*x)->path(), false, false, sources.size(), n);
773 PropertyList plist;
775 plist.add (ARDOUR::Properties::start, 0);
776 plist.add (ARDOUR::Properties::length, (*x)->length (pos));
777 plist.add (ARDOUR::Properties::name, region_name);
778 plist.add (ARDOUR::Properties::layer, 0);
779 plist.add (ARDOUR::Properties::whole_file, true);
780 plist.add (ARDOUR::Properties::external, true);
782 boost::shared_ptr<Region> r = RegionFactory::create (just_one, plist);
784 if (use_timestamp && boost::dynamic_pointer_cast<AudioRegion>(r)) {
785 boost::dynamic_pointer_cast<AudioRegion>(r)->special_set_position((*x)->natural_position());
788 regions.push_back (r);
792 if (target_regions == 1) {
793 input_chan = regions.front()->n_channels();
794 } else {
795 if (target_tracks == 1) {
796 input_chan = regions.size();
797 } else {
798 input_chan = 1;
802 if (Config->get_output_auto_connect() & AutoConnectMaster) {
803 output_chan = (_session->master_out() ? _session->master_out()->n_inputs().n_audio() : input_chan);
804 } else {
805 output_chan = input_chan;
808 int n = 0;
810 for (vector<boost::shared_ptr<Region> >::iterator r = regions.begin(); r != regions.end(); ++r, ++n) {
812 finish_bringing_in_material (*r, input_chan, output_chan, pos, mode, track);
814 if (target_tracks != 1) {
815 track.reset ();
816 } else {
817 pos += (*r)->length();
821 /* setup peak file building in another thread */
823 for (SourceList::iterator x = sources.begin(); x != sources.end(); ++x) {
824 SourceFactory::setup_peakfile (*x, true);
827 return 0;
831 Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t in_chans, uint32_t out_chans, nframes64_t& pos,
832 ImportMode mode, boost::shared_ptr<Track>& existing_track)
834 boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion>(region);
835 boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(region);
837 switch (mode) {
838 case ImportAsRegion:
839 /* relax, its been done */
840 break;
842 case ImportToTrack:
844 if (!existing_track) {
846 if (ar) {
847 existing_track = get_nth_selected_audio_track (0);
848 } else if (mr) {
849 existing_track = get_nth_selected_midi_track (0);
852 if (!existing_track) {
853 return -1;
857 boost::shared_ptr<Playlist> playlist = existing_track->playlist();
858 boost::shared_ptr<Region> copy (RegionFactory::create (region, region->properties()));
859 begin_reversible_command (_("insert file"));
860 playlist->clear_history ();
861 playlist->add_region (copy, pos);
862 _session->add_command (new StatefulDiffCommand (playlist));
863 commit_reversible_command ();
864 break;
867 case ImportAsTrack:
869 if (!existing_track) {
870 if (ar) {
871 list<boost::shared_ptr<AudioTrack> > at (_session->new_audio_track (in_chans, out_chans, Normal, 0, 1));
873 if (at.empty()) {
874 return -1;
877 existing_track = at.front();
878 } else if (mr) {
879 list<boost::shared_ptr<MidiTrack> > mt (_session->new_midi_track (Normal, 0, 1));
881 if (mt.empty()) {
882 return -1;
885 existing_track = mt.front();
888 existing_track->set_name (region->name());
891 boost::shared_ptr<Region> copy (RegionFactory::create (region));
892 existing_track->playlist()->add_region (copy, pos);
893 break;
897 case ImportAsTapeTrack:
899 if (!ar)
900 return -1;
902 list<boost::shared_ptr<AudioTrack> > at (_session->new_audio_track (in_chans, out_chans, Destructive));
903 if (!at.empty()) {
904 boost::shared_ptr<Region> copy (RegionFactory::create (region));
905 at.front()->set_name (basename_nosuffix (copy->name()));
906 at.front()->playlist()->add_region (copy, pos);
908 break;
912 return 0;
915 void *
916 Editor::_import_thread (void *arg)
918 SessionEvent::create_per_thread_pool ("import events", 64);
920 Editor *ed = (Editor *) arg;
921 return ed->import_thread ();
924 void *
925 Editor::import_thread ()
927 _session->import_audiofiles (import_status);
928 pthread_exit_pbd (0);
929 /*NOTREACHED*/
930 return 0;