summaryrefslogtreecommitdiff
path: root/gtk2_ardour/duplicate_routes_dialog.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2015-11-14 15:21:20 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2015-11-14 15:25:52 -0500
commitef810eacd8db1b4d0443c1b71cd6da3a272ef97f (patch)
tree685d66bcf4a959e5766b3df3691542364a37a397 /gtk2_ardour/duplicate_routes_dialog.cc
parentfb961701785996b01af023f9e0cb59e77fbcd87b (diff)
move logic of track/bus duplication into DuplicateRouteDialog
Diffstat (limited to 'gtk2_ardour/duplicate_routes_dialog.cc')
-rw-r--r--gtk2_ardour/duplicate_routes_dialog.cc103
1 files changed, 96 insertions, 7 deletions
diff --git a/gtk2_ardour/duplicate_routes_dialog.cc b/gtk2_ardour/duplicate_routes_dialog.cc
index d6a90cf57c..6db5b158a1 100644
--- a/gtk2_ardour/duplicate_routes_dialog.cc
+++ b/gtk2_ardour/duplicate_routes_dialog.cc
@@ -19,10 +19,18 @@
#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 ();
+ }
+}