move logic of track/bus duplication into DuplicateRouteDialog
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 14 Nov 2015 20:21:20 +0000 (15:21 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 14 Nov 2015 20:25:52 +0000 (15:25 -0500)
gtk2_ardour/ardour_ui.cc
gtk2_ardour/duplicate_routes_dialog.cc
gtk2_ardour/duplicate_routes_dialog.h

index 31b79d1657e2444c83382ce42a1c7147c9478d99..eb4730a545810209c98f3f80f1e2c8a0e397386f 100644 (file)
@@ -3757,98 +3757,10 @@ ARDOUR_UI::start_duplicate_routes ()
 {
        if (!duplicate_routes_dialog) {
                duplicate_routes_dialog = new DuplicateRouteDialog;
-               duplicate_routes_dialog->signal_response().connect (sigc::mem_fun (*this, &ARDOUR_UI::finish_duplicate_routes));
        }
 
-       TrackSelection& tracks  (editor->get_selection().tracks);
-       uint32_t ntracks = 0;
-       uint32_t nbusses = 0;
-
-       for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
-
-               RouteUI* rui = dynamic_cast<RouteUI*> (*t);
-
-               if (!rui) {
-                       /* some other type of timeaxis view, not a route */
-                       continue;
-               }
-
-               boost::shared_ptr<Route> r (rui->route());
-
-               if (boost::dynamic_pointer_cast<Track> (r)) {
-                       ntracks++;
-               } else {
-                       if (!r->is_master() && !r->is_monitor()) {
-                               nbusses++;
-                       }
-               }
-       }
-
-       if (ntracks == 0 && nbusses == 0) {
-               cerr << "You can't do this\n";
-               return;
-       }
-
-       duplicate_routes_dialog->setup (ntracks, nbusses);
-       duplicate_routes_dialog->present ();
-}
-
-void
-ARDOUR_UI::finish_duplicate_routes (int response)
-{
-       if (!duplicate_routes_dialog) {
-               /* how could this happen? */
-               return;
-       }
-
-       duplicate_routes_dialog->hide ();
-
-       if (response != Gtk::RESPONSE_OK) {
-               return;
-       }
-
-       ARDOUR::PlaylistDisposition playlist_disposition = duplicate_routes_dialog->playlist_disposition ();
-       uint32_t count = duplicate_routes_dialog->count ();
-
-       /* Copy the track selection because it will/may change as we add new ones */
-       TrackSelection tracks  (editor->get_selection().tracks);
-       int err = 0;
-
-       for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
-
-               RouteUI* rui = dynamic_cast<RouteUI*> (*t);
-
-               if (!rui) {
-                       /* some other type of timeaxis view, not a route */
-                       continue;
-               }
-
-               if (rui->route()->is_master() || rui->route()->is_monitor()) {
-                       /* no option to duplicate these */
-                       continue;
-               }
-
-               XMLNode& state (rui->route()->get_state());
-               RouteList rl = _session->new_route_from_template (count, state, string(), playlist_disposition);
-
-               /* normally the state node would be added to a parent, and
-                * ownership would transfer. Because we don't do that here,
-                * we need to delete the node ourselves.
-                */
-
-               delete &state;
-
-               if (rl.empty()) {
-                       err++;
-                       break;
-               }
-       }
-
-       if (err) {
-               MessageDialog msg (_("1 or more tracks/busses could not be duplicated"),
-                                    true, MESSAGE_ERROR, BUTTONS_OK, true);
-               msg.set_position (WIN_POS_MOUSE);
-               msg.run ();
+       if (duplicate_routes_dialog->restart ()) {
+               duplicate_routes_dialog->present ();
        }
 }
 
index d6a90cf57c30e79c3b7c5afe7c46207ee5e4102c..6db5b158a145b77a8d7ca9afe5f416e2f36358ca 100644 (file)
 
 #include "gtkmm/stock.h"
 
+#include "ardour/route.h"
+#include "ardour/session.h"
+
+#include "editor.h"
 #include "duplicate_routes_dialog.h"
+#include "selection.h"
 
 #include "i18n.h"
 
+using namespace ARDOUR;
+using namespace Gtk;
+
 DuplicateRouteDialog::DuplicateRouteDialog ()
        : ArdourDialog (_("Duplicate Tracks & Busses"), false, false)
        , copy_playlists_button (playlist_button_group, _("Copy playlists"))
@@ -43,17 +51,42 @@ DuplicateRouteDialog::DuplicateRouteDialog ()
 
        get_vbox()->show_all ();
 
-       add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-       add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
+       add_button (Stock::CANCEL, RESPONSE_CANCEL);
+       add_button (Stock::OK, RESPONSE_OK);
 }
 
-DuplicateRouteDialog::~DuplicateRouteDialog ()
+int
+DuplicateRouteDialog::restart ()
 {
-}
+       TrackSelection& tracks  (PublicEditor::instance().get_selection().tracks);
+       uint32_t ntracks = 0;
+       uint32_t nbusses = 0;
+
+       for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
+
+               RouteUI* rui = dynamic_cast<RouteUI*> (*t);
+
+               if (!rui) {
+                       /* some other type of timeaxis view, not a route */
+                       continue;
+               }
+
+               boost::shared_ptr<Route> r (rui->route());
+
+               if (boost::dynamic_pointer_cast<Track> (r)) {
+                       ntracks++;
+               } else {
+                       if (!r->is_master() && !r->is_monitor()) {
+                               nbusses++;
+                       }
+               }
+       }
+
+       if (ntracks == 0 && nbusses == 0) {
+               std::cerr << "You can't do this\n";
+               return -1;
+       }
 
-void
-DuplicateRouteDialog::setup (uint32_t ntracks, uint32_t nbusses)
-{
        /* XXX grrr. Gtk Boxes do not shrink when children are removed,
           which is what we really want to happen here.
        */
@@ -63,6 +96,8 @@ DuplicateRouteDialog::setup (uint32_t ntracks, uint32_t nbusses)
        } else {
                get_vbox()->pack_end (playlist_button_box, false, false);
        }
+
+       return 0;
 }
 
 uint32_t
@@ -82,3 +117,57 @@ DuplicateRouteDialog::playlist_disposition() const
 
        return ARDOUR::SharePlaylist;
 }
+
+void
+DuplicateRouteDialog::on_response (int response)
+{
+       hide ();
+
+       if (response != RESPONSE_OK) {
+               return;
+       }
+
+       ARDOUR::PlaylistDisposition playlist_action = playlist_disposition ();
+       uint32_t cnt = count ();
+
+       /* Copy the track selection because it will/may change as we add new ones */
+       TrackSelection tracks  (PublicEditor::instance().get_selection().tracks);
+       int err = 0;
+
+       for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
+
+               RouteUI* rui = dynamic_cast<RouteUI*> (*t);
+
+               if (!rui) {
+                       /* some other type of timeaxis view, not a route */
+                       continue;
+               }
+
+               if (rui->route()->is_master() || rui->route()->is_monitor()) {
+                       /* no option to duplicate these */
+                       continue;
+               }
+
+               XMLNode& state (rui->route()->get_state());
+               RouteList rl = _session->new_route_from_template (cnt, state, std::string(), playlist_action);
+
+               /* normally the state node would be added to a parent, and
+                * ownership would transfer. Because we don't do that here,
+                * we need to delete the node ourselves.
+                */
+
+               delete &state;
+
+               if (rl.empty()) {
+                       err++;
+                       break;
+               }
+       }
+
+       if (err) {
+               MessageDialog msg (_("1 or more tracks/busses could not be duplicated"),
+                                    true, MESSAGE_ERROR, BUTTONS_OK, true);
+               msg.set_position (WIN_POS_MOUSE);
+               msg.run ();
+       }
+}
index d1423a337bbab83a900952e1cbcefecd431efa0c..9dee8a6e3198d49acb1a6a65113323aa4cd976c9 100644 (file)
@@ -38,10 +38,7 @@ class DuplicateRouteDialog : public ArdourDialog
        DuplicateRouteDialog ();
        ~DuplicateRouteDialog ();
 
-       void setup (uint32_t ntracks, uint32_t nbusses);
-
-       uint32_t count() const;
-       ARDOUR::PlaylistDisposition playlist_disposition() const;
+       int restart ();
 
   private:
        Gtk::Entry name_template_entry;
@@ -54,6 +51,11 @@ class DuplicateRouteDialog : public ArdourDialog
        Gtk::SpinButton count_spinner;
        Gtk::HBox count_box;
        Gtk::Label count_label;
+
+       void on_response (int);
+
+       uint32_t count() const;
+       ARDOUR::PlaylistDisposition playlist_disposition() const;
 };
 
 #endif /* __gtk_ardour_duplicate_route_dialog_h__ */