From dbb0a6385b54bb3b768cd98de7349aa5587dcffd Mon Sep 17 00:00:00 2001 From: YPozdnyakov Date: Fri, 26 Dec 2014 10:57:40 +0200 Subject: [PATCH] [Summary]: ProgressDialog for Tracks creation and removal --- gtk2_ardour/ardour_ui.cc | 39 ++++++++++++++++++++------ gtk2_ardour/editor.cc | 11 ++++++++ gtk2_ardour/editor.h | 2 ++ gtk2_ardour/editor_routes.cc | 1 + gtk2_ardour/progress_dialog.cc | 44 ++++++++++++++++++++++++++++-- gtk2_ardour/progress_dialog.h | 11 +++++++- gtk2_ardour/route_time_axis.cc | 14 ++++++---- gtk2_ardour/route_ui.cc | 9 ++---- gtk2_ardour/route_ui.h | 1 - gtk2_ardour/ui/progress_dialog.xml | 6 ++-- libs/ardour/ardour/session.h | 2 ++ libs/ardour/session.cc | 2 ++ 12 files changed, 115 insertions(+), 27 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 4925eb51cc..4441648986 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -66,6 +66,7 @@ #include "ardour/ardour.h" #include "ardour/audio_backend.h" +#include "ardour/audio_track.h" #include "ardour/audioengine.h" #include "ardour/audiofilesource.h" #include "ardour/automation_watch.h" @@ -2972,13 +2973,9 @@ ARDOUR_UI::close_session() int ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name, std::string mix_template) { - ProgressDialog::instance()->set_top_label ("Loading session: "+path); + ProgressDialog::instance()->set_top_label ("Loading session: "+snap_name); ProgressDialog::instance()->update_info (0.0, NULL, NULL, "Loading audio..."); ProgressDialog::instance()->show (); - /* Make sure the progress dialog is drawn */ - while (Glib::MainContext::get_default()->iteration (false)) { - /* do nothing */ - } Session *new_session; int unload_status; @@ -3473,7 +3470,7 @@ ARDOUR_UI::add_route (Gtk::Window* float_window) setup_order_hint(); ChanCount input_chan = _add_tracks_dialog->input_channels (); - DisplaySuspender ds; + //DisplaySuspender ds; ChanCount output_chan; // NP: output_channels amount will be validated and changed accordingly to Master BUS config in Session::reconnect_existing_routes @@ -3484,15 +3481,41 @@ ARDOUR_UI::add_route (Gtk::Window* float_window) } else */ { output_chan = input_chan; } + + ProgressDialog::instance()->set_top_label ("Adding tracks..."); + ProgressDialog::instance()->set_num_of_steps (_add_tracks_dialog->count () * 2); + ProgressDialog::instance()->show (); - session_add_audio_track (input_chan.n_audio(), output_chan.n_audio(), ARDOUR::Normal, NULL, _add_tracks_dialog->count(), ""); + session_add_audio_route (true, input_chan.n_audio(), output_chan.n_audio(), ARDOUR::Normal, NULL, _add_tracks_dialog->count(), ""); + ProgressDialog::instance()->hide (); } void ARDOUR_UI::delete_selected_tracks() { + DisplaySuspender ds; + TrackSelection& track_selection = ARDOUR_UI::instance()->the_editor().get_selection().tracks; - track_selection.foreach_route_ui (boost::bind (&RouteUI::remove_this_route, _1, false)); + boost::shared_ptr routes_to_remove(new RouteList); + for (list::iterator i = track_selection.begin(); i != track_selection.end(); ++i) { + RouteUI* t = dynamic_cast (*i); + if (t) { + if ( t->route()->is_master() || t->route()->is_monitor() ) + continue; + + AudioTrack* audio_track = dynamic_cast( t->route().get() ); + if ( audio_track && audio_track->is_master_track() ) + continue; + + routes_to_remove->push_back(t->route() ); + } + } + ProgressDialog::instance()->set_top_label ("Removing tracks..."); + ProgressDialog::instance()->set_num_of_steps (routes_to_remove->size ()); + ProgressDialog::instance()->show (); + + ARDOUR_UI::instance()->the_session()->remove_routes (routes_to_remove); + ProgressDialog::instance()->hide (); } void diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index f61b6b124f..ef3e971e45 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1487,6 +1487,9 @@ Editor::set_session (Session *t) // if new tracks is added, they must effect on Global Record button and Master Mute button _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&Editor::connect_routes_and_update_global_rec_button, this, _1), gui_context()); + // one route was removed/added + _session->RouteAddedOrRemoved.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_progress_dialog_of_changing_tracks, this, _1), gui_context()); + // connect existing tracks to Global Record button connect_routes_and_update_global_rec_button( *(_session->get_tracks().get()) ); @@ -5034,6 +5037,7 @@ Editor::add_routes (RouteList& routes) rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added)); rtv->view()->RegionViewRemoved.connect (sigc::mem_fun (*this, &Editor::region_view_removed)); + ProgressDialog::instance()->add_progress_step (); } if (new_views.size() > 0) { @@ -5944,3 +5948,10 @@ Editor::port_connection_handler (boost::weak_ptr wa, std::string, boost::w // add actions here } + + +void // true - track was added, false - track was removed +Editor::update_progress_dialog_of_changing_tracks (bool operation) +{ + ProgressDialog::instance()->add_progress_step (); +} diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index b0e9978678..13caa2c797 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -2166,6 +2166,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void port_connection_handler (boost::weak_ptr wa, std::string, boost::weak_ptr wb, std::string, bool connected); PBD::ScopedConnectionList port_state_connection_list; + + void update_progress_dialog_of_changing_tracks (bool); /* members and methods associated with MIDI + markers */ diff --git a/gtk2_ardour/editor_routes.cc b/gtk2_ardour/editor_routes.cc index 9d3c19cf3a..f1260fb258 100644 --- a/gtk2_ardour/editor_routes.cc +++ b/gtk2_ardour/editor_routes.cc @@ -564,6 +564,7 @@ EditorRoutes::redisplay () */ _editor->vertical_adjustment.set_value (_editor->_full_canvas_height - _editor->_visible_canvas_height); } + ProgressDialog::instance()->add_progress_step (); } void diff --git a/gtk2_ardour/progress_dialog.cc b/gtk2_ardour/progress_dialog.cc index ba301550a5..94594d05dc 100644 --- a/gtk2_ardour/progress_dialog.cc +++ b/gtk2_ardour/progress_dialog.cc @@ -33,6 +33,9 @@ ProgressDialog::ProgressDialog (const std::string& title, , _top_label ( get_label ("top_label") ) , _bottom_label ( get_label ("bottom_label") ) , _progress_bar (get_progressbar ("progress_bar")) +, num_of_steps (0) +, cur_step (0) +, hide_automatically(false) { init (title, top_message, progress_message, bottom_message); } @@ -53,8 +56,6 @@ ProgressDialog::init (const std::string& title, set_modal (true); set_resizable (false); set_position (Gtk::WIN_POS_CENTER_ALWAYS); - set_type_hint (Gdk::WINDOW_TYPE_HINT_NORMAL); - set_title (title); set_top_label (top_message); @@ -92,6 +93,45 @@ ProgressDialog::update_info (double new_progress, const char* top_message, const set_bottom_label (bottom_message); } +void +ProgressDialog::set_num_of_steps (unsigned int n, bool hide_automatically) +{ + num_of_steps = n; + cur_step = 0; + this->hide_automatically = hide_automatically; + _progress_bar.set_fraction (0.0); + set_bottom_label("0 %"); +} +void +ProgressDialog::add_progress_step () +{ + unsigned int this_thread_cur_step; + { //thread unsafe, so + std::lock_guard lock (_m); + if (cur_step == num_of_steps) + return; + + ++cur_step; + this_thread_cur_step = cur_step; + } + set_bottom_label (string_compose ("%1 %", int ( ( float (cur_step) / (num_of_steps)) * 100))); + set_progress (float (this_thread_cur_step) / (num_of_steps)); + + if (hide_automatically && this_thread_cur_step == num_of_steps){ + hide (); + } +} + +void +ProgressDialog::show () +{ + WavesDialog::show (); + /* Make sure the progress dialog is drawn */ + while (Glib::MainContext::get_default()->iteration (false)) { + /* do nothing */ + } +} + void ProgressDialog::update_progress_gui (float p) { diff --git a/gtk2_ardour/progress_dialog.h b/gtk2_ardour/progress_dialog.h index f7c825330e..a299472d7e 100644 --- a/gtk2_ardour/progress_dialog.h +++ b/gtk2_ardour/progress_dialog.h @@ -34,7 +34,13 @@ public: void set_top_label (std::string message); void set_progress_label (std::string message); void set_bottom_label (std::string message); + // initialize num of processing steps (thread-unsafe method) + void set_num_of_steps (unsigned int, bool hide_automatically = false); + // increment cur_step of progress process (thread-safe method) + // it's expected that set_num_of_steps () was called previously + void add_progress_step (); void update_info (double new_progress, const char* top_message, const char* progress_message, const char* bottom_message); + void show (); private: ProgressDialog (const std::string& title="", @@ -48,10 +54,13 @@ private: const std::string& progress_message, const std::string& bottom_message); - + mutable std::mutex _m; Gtk::Label& _top_label; Gtk::Label& _bottom_label; Gtk::ProgressBar& _progress_bar; + unsigned int num_of_steps; + unsigned int cur_step; + bool hide_automatically; }; #endif /* __progress_dialog_h__ */ \ No newline at end of file diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index d590e0d548..d2c6176a7b 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -56,6 +56,7 @@ #include "canvas/debug.h" +#include "actions.h" #include "ardour_ui.h" #include "ardour_button.h" #include "debug.h" @@ -436,10 +437,12 @@ RouteTimeAxisView::build_display_menu () items.push_back (SeparatorElem()); if (!Profile->get_sae()) { - items.push_back (MenuElem (_("Remove"), sigc::bind (sigc::mem_fun(*this, &RouteUI::remove_this_route), true))); + items.push_back (*manage (ActionManager::get_action_from_name ("DeleteSelectedTracks")->create_menu_item ())); + items.back().set_label ("Remove"); } else { items.push_front (SeparatorElem()); - items.push_front (MenuElem (_("Delete"), sigc::bind (sigc::mem_fun(*this, &RouteUI::remove_this_route), true))); + items.push_back (*manage (ActionManager::get_action_from_name ("DeleteSelectedTracks")->create_menu_item ())); + items.back().set_label ("Delete"); } } @@ -727,11 +730,12 @@ RouteTimeAxisView::build_display_menu () items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Hide"), sigc::bind (sigc::mem_fun(_editor, &PublicEditor::hide_track_in_display), this, true))); if (!Profile->get_sae()) { - items.push_back (MenuElem (_("Remove"), sigc::bind (sigc::mem_fun(*this, &RouteUI::remove_this_route), true))); + items.push_back (*manage (ActionManager::get_action_from_name ("DeleteSelectedTracks")->create_menu_item ())); + items.back().set_label ("Remove"); } else { items.push_front (SeparatorElem()); - items.push_front (MenuElem (_("Delete"), sigc::bind (sigc::mem_fun(*this, &RouteUI::remove_this_route), true))); - } + items.push_back (*manage (ActionManager::get_action_from_name ("DeleteSelectedTracks")->create_menu_item ())); + items.back().set_label ("Delete"); } } void diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 61088dbcf8..472197a662 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -1407,7 +1407,8 @@ RouteUI::remove_this_route (bool apply_to_selection) routes_to_remove->push_back(this->route() ); } - Glib::signal_idle().connect (sigc::bind (sigc::ptr_fun (&RouteUI::idle_remove_routes), ARDOUR_UI::instance()->the_session(), routes_to_remove) ); + ARDOUR_UI::instance()->the_session()->remove_routes (routes_to_remove); + ProgressDialog::instance()->hide (); } gint @@ -1417,12 +1418,6 @@ RouteUI::idle_remove_this_route (RouteUI *rui) return false; } -gint -RouteUI::idle_remove_routes (Session* sess, boost::shared_ptr& rlist) -{ - sess->remove_routes (rlist); - return false; -} /** @return true if this name should be used for the route, otherwise false */ bool diff --git a/gtk2_ardour/route_ui.h b/gtk2_ardour/route_ui.h index 927c37eee8..cdf1901951 100644 --- a/gtk2_ardour/route_ui.h +++ b/gtk2_ardour/route_ui.h @@ -217,7 +217,6 @@ class RouteUI : public Gtk::EventBox, public WavesUI, public virtual AxisView void remove_this_route (bool apply_to_selection = false); static gint idle_remove_this_route (RouteUI *); - static gint idle_remove_routes (ARDOUR::Session*, boost::shared_ptr &); void route_rename(); diff --git a/gtk2_ardour/ui/progress_dialog.xml b/gtk2_ardour/ui/progress_dialog.xml index df00d63e3a..bffd51f853 100644 --- a/gtk2_ardour/ui/progress_dialog.xml +++ b/gtk2_ardour/ui/progress_dialog.xml @@ -1,6 +1,5 @@ - +