- sigc::connection c;
-
- /* SFDB sets "multichan" to true to indicate "split channels"
- so reverse the setting to match the way libardour
- interprets it.
- */
-
- import_status.multichan = !split;
-
- if (interthread_progress_window == 0) {
- build_interthread_progress_window ();
- }
-
- interthread_progress_window->set_title (_("ardour: audio import in progress"));
- interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
- interthread_progress_window->show_all ();
- interthread_progress_bar.set_fraction (0.0f);
- interthread_cancel_label.set_text (_("Cancel Import"));
- current_interthread_info = &import_status;
-
- c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
-
- for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
-
- interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
-
- import_status.pathname = (*i);
- import_status.done = false;
- import_status.cancel = false;
- import_status.freeze = false;
- import_status.done = 0.0;
-
- interthread_progress_connection =
- Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
-
- last_audio_region = 0;
-
- pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
- pthread_detach (import_status.thread);
-
- while (!(import_status.done || import_status.cancel)) {
- gtk_main_iteration ();
- }
-
- import_status.done = true;
- interthread_progress_connection.disconnect ();
-
- if (as_tracks && last_audio_region != 0) {
- uint32_t channels = last_audio_region->n_channels();
-
- AudioTrack* at = session->new_audio_track (channels, channels);
- AudioRegion* copy = new AudioRegion (*last_audio_region);
- at->disk_stream().playlist()->add_region (*copy, 0);
- }
- }
-
- c.disconnect ();
- interthread_progress_window->hide_all ();
-}
-
-int
-Editor::reject_because_rate_differs (const string & path, SF_INFO& finfo, const string & action, bool multiple_pending)
-{
- if (!session) {
- return 1;
- }
-
- if (finfo.samplerate != (int) session->frame_rate()) {
- vector<string> choices;
-
- choices.push_back (string_compose (_("%1 it anyway"), action));
-
- if (multiple_pending) {
- /* XXX assumptions about sentence structure
- here for translators. Sorry.
- */
- choices.push_back (string_compose (_("Don't %1 it"), action));
- choices.push_back (string_compose (_("%1 all without questions"), action));
- choices.push_back (_("Cancel entire import"));
- } else {
- choices.push_back (_("Cancel"));
- }
-
- Gtkmm2ext::Choice rate_choice (
- string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
- choices);
-
- rate_choice.chosen.connect (ptr_fun (Main::quit));
- rate_choice.show_all ();
-
- Main::run ();
-
- switch (rate_choice.get_choice()) {
- case 0: /* do it anyway */
- return 0;
- case 1: /* don't import this one */
- return 1;
- case 2: /* do the rest without asking */
- return -1;
- case 3: /* stop a multi-file import */
- default:
- return -2;
- }
- }
-
- return 0;
-}
-
-void
-Editor::embed_audio ()
-{
- if (session == 0) {
- warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
- return;
- }
-
- SoundFileOmega sfdb (_("Add to External Region list"));
- sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
-
- sfdb.run ();
-}
-
-void
-Editor::do_embed_sndfiles (vector<string> paths, bool split)
-{
- bool multiple_files = paths.size() > 1;
- bool check_sample_rate = true;
-
- for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
- embed_sndfile (*i, split, multiple_files, check_sample_rate);
- }
-
- session->save_state ("");
-}
-
-void
-Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
-{
- SndFileSource *source = 0; /* keep g++ quiet */
- AudioRegion::SourceList sources;
- string idspec;
- string linked_path;
- SNDFILE *sf;
- SF_INFO finfo;
-
- /* lets see if we can link it into the session */
-
- linked_path = session->sound_dir();
- linked_path += PBD::basename (path);
-
- if (link (path.c_str(), linked_path.c_str()) == 0) {
-
- /* there are many reasons why link(2) might have failed.
- but if it succeeds, we now have a link in the
- session sound dir that will protect against
- unlinking of the original path. nice.
- */
-
- path = linked_path;
- }
-
- memset (&finfo, 0, sizeof(finfo));
-
- /* note that we temporarily truncated _id at the colon */
-
- if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
- char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
- return;
- }
- sf_close (sf);
- sf = 0;
-
- if (check_sample_rate) {
- switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
- case 0:
- break;
- case 1:
- return;
- case -1:
- check_sample_rate = false;
- break;
-
- case -2:
- default:
- return;
- }
- }
-
- track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
- ARDOUR_UI::instance()->flush_pending ();
-
- /* make the proper number of channels in the region */
-
- for (int n=0; n < finfo.channels; ++n)
- {
- idspec = path;
- idspec += string_compose(":%1", n);
-
- try {
- source = new SndFileSource (idspec.c_str());
- sources.push_back(source);
- }
-
- catch (failed_constructor& err) {
- error << string_compose(_("could not open %1"), path) << endmsg;
- goto out;
- }
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- if (sources.size() > 0) {
-
- string region_name = PBD::basename_nosuffix (path);
- region_name += "-0";
-
- /* The created region isn't dropped. It emits a signal
- that is picked up by the session.
- */
-
- new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
- Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
-
- /* make sure we can see it in the list */
-
- /* its the second node, always */
-
- // GTK2FIX ?? is it still always the 2nd node
-
- TreeModel::Path path ("2");
- region_list_display.expand_row (path, true);
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- out:
- track_canvas.get_window()->set_cursor (*current_canvas_cursor);
-}
-
-void
-Editor::insert_sndfile (bool as_tracks)
-{
-// SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
- sigc::connection c;
- string str;
-
- if (as_tracks) {
-
-// c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
- str = _("Insert selected as new tracks");
-
- } else {
-
- jack_nframes_t pos;
-
- if (clicked_audio_trackview == 0) {
- return;
- }
-
- if (ensure_cursor (&pos)) {
- return;
- }
-
-// c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
- str = _("Insert selected");
- }
-
-// sfdb.run (str, false);
-// c.disconnect ();
-}
-
-void
-Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
-{
- SNDFILE *sf;
- SF_INFO finfo;
- bool multiple_files;
- bool check_sample_rate = true;
-
- multiple_files = paths.size() > 1;
-
- for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
-
- memset (&finfo, 0, sizeof(finfo));
-
- if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
- char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
- continue;
- }
-
- sf_close (sf);
- sf = 0;
-
- /* add a new track */
-
- if (check_sample_rate) {
- switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
- case 0:
- break;
- case 1:
- continue;
- case -1:
- check_sample_rate = false;
- break;
-
- case -2:
- return;
- }
- }
-
- uint32_t input_chan = finfo.channels;
- uint32_t output_chan;
-
- if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
- output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
- } else {
- output_chan = input_chan;
- }
-
- (void) session->new_audio_track (input_chan, output_chan);
-
-
- /* get the last (most recently added) track view */
-
- AudioTimeAxisView* tv;
-
- if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
- fatal << _("programming error: ")
- << X_("last trackview after new_audio_track is not an audio track!")
- << endmsg;
- /*NOTREACHED*/
- }
-
- jack_nframes_t pos = 0;
- insert_sndfile_into (*p, true, tv, pos, false);
- }
-}
-
-void
-Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
-{
- for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
- insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
- }
-}
-
-void
-Editor::insert_sndfile_into (const string & path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
-{
- SndFileSource *source = 0; /* keep g++ quiet */
- AudioRegion::SourceList sources;
- string idspec;
- SNDFILE *sf;
- SF_INFO finfo;
-
- memset (&finfo, 0, sizeof(finfo));
-
- /* note that we temporarily truncated _id at the colon */
-
- if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
- char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
- return;
- }
- sf_close (sf);
- sf = 0;
-
- if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
- return;
- }
-
- track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
- ARDOUR_UI::instance()->flush_pending ();
-
- /* make the proper number of channels in the region */
-
- for (int n=0; n < finfo.channels; ++n)
- {
- idspec = path;
- idspec += string_compose(":%1", n);
-
- try {
- source = new SndFileSource (idspec.c_str());
- sources.push_back(source);
- }
-
- catch (failed_constructor& err) {
- error << string_compose(_("could not open %1"), path) << endmsg;
- goto out;
- }
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- if (sources.size() > 0) {
-
- string region_name = region_name_from_path (PBD::basename (path));
-
- AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
- 0, /* irrelevant these days */
- Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
-
- begin_reversible_command (_("insert sndfile"));
- session->add_undo (tv->playlist()->get_memento());
- tv->playlist()->add_region (*region, pos);
- session->add_redo_no_execute (tv->playlist()->get_memento());
- commit_reversible_command ();
-
- pos += sources[0]->length();
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- out:
- track_canvas.get_window()->set_cursor (*current_canvas_cursor);
- return;