2 Copyright (C) 2015 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "gtkmm/stock.h"
22 #include "ardour/route.h"
23 #include "ardour/session.h"
26 #include "duplicate_routes_dialog.h"
27 #include "selection.h"
31 using namespace ARDOUR;
34 DuplicateRouteDialog::DuplicateRouteDialog ()
35 : ArdourDialog (_("Duplicate Tracks & Busses"), false, false)
36 , copy_playlists_button (playlist_button_group, _("Copy playlists"))
37 , new_playlists_button (playlist_button_group, _("Create new (empty) playlists"))
38 , share_playlists_button (playlist_button_group, _("Share playlists"))
39 , count_adjustment (1.0, 1.0, 999, 1.0, 10.0)
40 , count_spinner (count_adjustment)
41 , count_label (_("Duplicate each track/bus this number of times:"))
43 count_box.pack_start (count_label, false, false);
44 count_box.pack_start (count_spinner, false, false, 5);
45 get_vbox()->pack_start (count_box, false, false, 10);
47 playlist_button_box.pack_start (copy_playlists_button, false, false);
48 playlist_button_box.pack_start (new_playlists_button, false, false);
49 playlist_button_box.pack_start (share_playlists_button, false, false);
50 playlist_button_box.show_all ();
52 get_vbox()->show_all ();
54 add_button (Stock::CANCEL, RESPONSE_CANCEL);
55 add_button (Stock::OK, RESPONSE_OK);
59 DuplicateRouteDialog::restart (Session* s)
67 TrackSelection& tracks (PublicEditor::instance().get_selection().tracks);
71 for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
73 RouteUI* rui = dynamic_cast<RouteUI*> (*t);
76 /* some other type of timeaxis view, not a route */
80 boost::shared_ptr<Route> r (rui->route());
82 if (boost::dynamic_pointer_cast<Track> (r)) {
85 if (!r->is_master() && !r->is_monitor()) {
91 if (ntracks == 0 && nbusses == 0) {
92 std::cerr << "You can't do this\n";
96 /* XXX grrr. Gtk Boxes do not shrink when children are removed,
97 which is what we really want to happen here.
100 if (playlist_button_box.get_parent()) {
101 get_vbox()->remove (playlist_button_box);
105 get_vbox()->pack_end (playlist_button_box, false, false);
112 DuplicateRouteDialog::count() const
114 return count_adjustment.get_value ();
117 ARDOUR::PlaylistDisposition
118 DuplicateRouteDialog::playlist_disposition() const
120 if (new_playlists_button.get_active()) {
121 return ARDOUR::NewPlaylist;
122 } else if (copy_playlists_button.get_active()) {
123 return ARDOUR::CopyPlaylist;
126 return ARDOUR::SharePlaylist;
130 DuplicateRouteDialog::on_response (int response)
134 if (response != RESPONSE_OK) {
138 ARDOUR::PlaylistDisposition playlist_action = playlist_disposition ();
139 uint32_t cnt = count ();
141 /* Copy the track selection because it will/may change as we add new ones */
142 TrackSelection tracks (PublicEditor::instance().get_selection().tracks);
145 for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
147 RouteUI* rui = dynamic_cast<RouteUI*> (*t);
150 /* some other type of timeaxis view, not a route */
154 if (rui->route()->is_master() || rui->route()->is_monitor()) {
155 /* no option to duplicate these */
159 XMLNode& state (rui->route()->get_state());
160 RouteList rl = _session->new_route_from_template (cnt, state, std::string(), playlist_action);
162 /* normally the state node would be added to a parent, and
163 * ownership would transfer. Because we don't do that here,
164 * we need to delete the node ourselves.
176 MessageDialog msg (_("1 or more tracks/busses could not be duplicated"),
177 true, MESSAGE_ERROR, BUTTONS_OK, true);
178 msg.set_position (WIN_POS_MOUSE);