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"
25 #include "ardour_ui.h"
27 #include "duplicate_routes_dialog.h"
28 #include "selection.h"
32 using namespace ARDOUR;
35 DuplicateRouteDialog::DuplicateRouteDialog ()
36 : ArdourDialog (_("Duplicate Tracks & Busses"), false, false)
37 , playlist_option_label (_("For each Track:"))
38 , copy_playlists_button (playlist_button_group, _("Copy playlist"))
39 , new_playlists_button (playlist_button_group, _("New playlist"))
40 , share_playlists_button (playlist_button_group, _("Share playlist"))
41 , count_adjustment (1.0, 1.0, 999, 1.0, 10.0)
42 , count_spinner (count_adjustment)
43 , count_label (_("Duplicate each track/bus this number of times:"))
45 count_box.pack_start (count_label, false, false);
46 count_box.pack_start (count_spinner, false, false, 5);
47 get_vbox()->pack_start (count_box, false, false, 10);
49 Gtk::HBox* hb = manage (new HBox);
50 hb->pack_start (playlist_option_label, false, false);
51 get_vbox()->pack_start (*hb, false, false, 10);
53 playlist_button_box.pack_start (copy_playlists_button, false, false);
54 playlist_button_box.pack_start (new_playlists_button, false, false);
55 playlist_button_box.pack_start (share_playlists_button, false, false);
56 playlist_button_box.show_all ();
58 insert_at_combo.append_text (_("First"));
59 insert_at_combo.append_text (_("Before Selection"));
60 insert_at_combo.append_text (_("After Selection"));
61 insert_at_combo.append_text (_("Last"));
62 insert_at_combo.set_active (3);
64 Gtk::Label* l = manage (new Label (_("Insert duplicates at: ")));
65 Gtk::HBox* b = manage (new HBox);
66 b->pack_start (*l, false, false, 10);
67 b->pack_start (insert_at_combo, true, true);
69 get_vbox()->pack_end (*b, false, false, 10);
71 get_vbox()->show_all ();
73 add_button (Stock::CANCEL, RESPONSE_CANCEL);
74 add_button (Stock::OK, RESPONSE_OK);
78 DuplicateRouteDialog::restart (Session* s)
86 TrackSelection& tracks (PublicEditor::instance().get_selection().tracks);
90 for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
92 RouteUI* rui = dynamic_cast<RouteUI*> (*t);
95 /* some other type of timeaxis view, not a route */
99 boost::shared_ptr<Route> r (rui->route());
101 if (boost::dynamic_pointer_cast<Track> (r)) {
104 if (!r->is_master() && !r->is_monitor()) {
110 if (ntracks == 0 && nbusses == 0) {
111 std::cerr << "You can't do this\n";
115 /* XXX grrr. Gtk Boxes do not shrink when children are removed,
116 which is what we really want to happen here.
119 if (playlist_button_box.get_parent()) {
120 get_vbox()->remove (playlist_button_box);
124 get_vbox()->pack_end (playlist_button_box, false, false);
131 DuplicateRouteDialog::count() const
133 return count_adjustment.get_value ();
136 ARDOUR::PlaylistDisposition
137 DuplicateRouteDialog::playlist_disposition() const
139 if (new_playlists_button.get_active()) {
140 return ARDOUR::NewPlaylist;
141 } else if (copy_playlists_button.get_active()) {
142 return ARDOUR::CopyPlaylist;
145 return ARDOUR::SharePlaylist;
149 DuplicateRouteDialog::on_response (int response)
153 if (response != RESPONSE_OK) {
157 ARDOUR::PlaylistDisposition playlist_action = playlist_disposition ();
158 uint32_t cnt = count ();
160 /* Copy the track selection because it will/may change as we add new ones */
161 TrackSelection tracks (PublicEditor::instance().get_selection().tracks);
164 for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
166 RouteUI* rui = dynamic_cast<RouteUI*> (*t);
169 /* some other type of timeaxis view, not a route */
173 if (rui->route()->is_master() || rui->route()->is_monitor()) {
174 /* no option to duplicate these */
178 XMLNode& state (rui->route()->get_state());
179 RouteList rl = _session->new_route_from_template (cnt, ARDOUR_UI::instance()->translate_order (insert_at()), state, std::string(), playlist_action);
181 /* normally the state node would be added to a parent, and
182 * ownership would transfer. Because we don't do that here,
183 * we need to delete the node ourselves.
195 MessageDialog msg (_("1 or more tracks/busses could not be duplicated"),
196 true, MESSAGE_ERROR, BUTTONS_OK, true);
197 msg.set_position (WIN_POS_MOUSE);
202 RouteDialogs::InsertAt
203 DuplicateRouteDialog::insert_at ()
205 using namespace RouteDialogs;
207 std::string str = insert_at_combo.get_active_text();
209 if (str == _("First")) {
211 } else if (str == _("After Selection")) {
212 return AfterSelection;
213 } else if (str == _("Before Selection")){
214 return BeforeSelection;