From 3aa346b253d515c3d0715ec5e0fa8b6ad477c4e5 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 22 Mar 2006 17:03:00 +0000 Subject: significant changes in code to handle import/embedding - much cleaner and less code, plus the import progress bar now works; unify response handling for Gtkmm2ext::Choice git-svn-id: svn://localhost/trunk/ardour2@415 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor_ops.cc | 491 +--------------------------------------------- 1 file changed, 4 insertions(+), 487 deletions(-) (limited to 'gtk2_ardour/editor_ops.cc') diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index f5baecb373..ba40d63fe7 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -198,12 +198,8 @@ Do you really want to destroy %1 ?"), choices.push_back (_("No, do nothing.")); Gtkmm2ext::Choice prompter (prompt, choices); - - if (prompter.run () != RESPONSE_ACCEPT) { - return; - } - - if (prompter.get_choice() != 0) { + + if (prompter.run() != 0) { /* first choice */ return; } @@ -1972,483 +1968,6 @@ Editor::interthread_cancel_clicked () } } -void * -Editor::_import_thread (void *arg) -{ - PBD::ThreadCreated (pthread_self(), X_("Import")); - - Editor *ed = (Editor *) arg; - return ed->import_thread (); -} - -void * -Editor::import_thread () -{ - session->import_audiofile (import_status); - return 0; -} - -gint -Editor::import_progress_timeout (void *arg) -{ - interthread_progress_label.set_text (import_status.doing_what); - - if (import_status.freeze) { - interthread_cancel_button.set_sensitive(false); - } else { - interthread_cancel_button.set_sensitive(true); - } - - if (import_status.doing_what == "building peak files") { - interthread_progress_bar.pulse (); - return FALSE; - } else { - interthread_progress_bar.set_fraction (import_status.progress/100); - } - - return !(import_status.done || import_status.cancel); -} - -void -Editor::import_audio (bool as_tracks) -{ - if (session == 0) { - warning << _("You can't import an audiofile until you have a session loaded.") << endmsg; - return; - } - - string str; - - if (as_tracks) { - str =_("Import selected as tracks"); - } else { - str = _("Import selected to region list"); - } - - SoundFileOmega sfdb (str); - sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks)); - - sfdb.run(); -} - -void -Editor::catch_new_audio_region (AudioRegion* ar) -{ - last_audio_region = ar; -} - -void -Editor::do_import (vector paths, bool split, bool as_tracks) -{ - 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::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, SoundFileInfo& finfo, const string & action, bool multiple_pending) -{ - if (!session) { - return 1; - } - - if (finfo.samplerate != (int) session->frame_rate()) { - vector 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); - - int response = rate_choice.run(); - - switch (response) { - case RESPONSE_ACCEPT: - break; - default: - /* stop all that might come after this */ - return -2; - break; - } - - 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 paths, bool split) -{ - bool multiple_files = paths.size() > 1; - bool check_sample_rate = true; - - for (vector::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) -{ - ExternalSource *source = 0; /* keep g++ quiet */ - AudioRegion::SourceList sources; - string idspec; - string linked_path; - SoundFileInfo 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; - } - - /* note that we temporarily truncated _id at the colon */ - string error_msg; - if (!ExternalSource::get_soundfile_info (path, finfo, error_msg)) { - error << string_compose(_("Editor: cannot open file \"%1\", (%2)"), selection, error_msg ) << endmsg; - return; - } - - 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 = ExternalSource::create (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 paths, bool split) -{ - SoundFileInfo finfo; - bool multiple_files; - bool check_sample_rate = true; - string error_msg; - - multiple_files = paths.size() > 1; - - for (vector::iterator p = paths.begin(); p != paths.end(); ++p) { - - if (!ExternalSource::get_soundfile_info((*p), finfo, error_msg)) { - error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), error_msg) << endmsg; - continue; - } - - /* 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(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 paths, bool split, jack_nframes_t pos) -{ - for (vector::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) -{ - ExternalSource *source = 0; /* keep g++ quiet */ - AudioRegion::SourceList sources; - string idspec; - SoundFileInfo finfo; - string error_msg; - - /* note that we temporarily truncated _id at the colon */ - - if (!ExternalSource::get_soundfile_info (path, finfo, error_msg)) { - error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, error_msg) << endmsg; - return; - } - - 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 = ExternalSource::create (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; -} - void Editor::region_from_selection () { @@ -3552,10 +3071,8 @@ Editor::remove_last_capture () Gtkmm2ext::Choice prompter (prompt, choices); - if (prompter.run () == RESPONSE_ACCEPT) { - if (prompter.get_choice() == 0) { - session->remove_last_capture (); - } + if (prompter.run () == 0) { + session->remove_last_capture (); } } else { -- cgit v1.2.3