2 * Copyright (C) 2015-2019 Paul Davis <paul@linuxaudiosystems.com>
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "gtkmm/stock.h"
21 #include "ardour/route.h"
22 #include "ardour/session.h"
24 #include "ardour_ui.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 , playlist_option_label (_("For each Track:"))
37 , copy_playlists_button (playlist_button_group, _("Copy playlist"))
38 , new_playlists_button (playlist_button_group, _("New playlist"))
39 , share_playlists_button (playlist_button_group, _("Share playlist"))
40 , count_adjustment (1.0, 1.0, 999, 1.0, 10.0)
41 , count_spinner (count_adjustment)
42 , count_label (_("Duplicate each track/bus this number of times:"))
44 count_box.pack_start (count_label, false, false);
45 count_box.pack_start (count_spinner, false, false, 5);
46 get_vbox()->pack_start (count_box, false, false, 10);
48 Gtk::HBox* hb = manage (new HBox);
49 hb->pack_start (playlist_option_label, false, false);
50 get_vbox()->pack_start (*hb, false, false, 10);
52 playlist_button_box.pack_start (copy_playlists_button, false, false);
53 playlist_button_box.pack_start (new_playlists_button, false, false);
54 playlist_button_box.pack_start (share_playlists_button, false, false);
55 playlist_button_box.show_all ();
57 insert_at_combo.append_text (_("First"));
58 insert_at_combo.append_text (_("Before Selection"));
59 insert_at_combo.append_text (_("After Selection"));
60 insert_at_combo.append_text (_("Last"));
61 insert_at_combo.set_active (3);
63 Gtk::Label* l = manage (new Label (_("Insert duplicates at: ")));
64 Gtk::HBox* b = manage (new HBox);
65 b->pack_start (*l, false, false, 10);
66 b->pack_start (insert_at_combo, true, true);
68 get_vbox()->pack_end (*b, false, false, 10);
70 get_vbox()->show_all ();
72 add_button (Stock::CANCEL, RESPONSE_CANCEL);
73 add_button (Stock::OK, RESPONSE_OK);
77 DuplicateRouteDialog::restart (Session* s)
85 TrackSelection& tracks (PublicEditor::instance().get_selection().tracks);
89 for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
91 RouteUI* rui = dynamic_cast<RouteUI*> (*t);
94 /* some other type of timeaxis view, not a route */
98 boost::shared_ptr<Route> r (rui->route());
100 if (boost::dynamic_pointer_cast<Track> (r)) {
103 if (!r->is_master() && !r->is_monitor()) {
109 if (ntracks == 0 && nbusses == 0) {
110 std::cerr << "You can't do this\n";
114 /* XXX grrr. Gtk Boxes do not shrink when children are removed,
115 which is what we really want to happen here.
118 if (playlist_button_box.get_parent()) {
119 get_vbox()->remove (playlist_button_box);
123 get_vbox()->pack_end (playlist_button_box, false, false);
130 DuplicateRouteDialog::count() const
132 return count_adjustment.get_value ();
135 ARDOUR::PlaylistDisposition
136 DuplicateRouteDialog::playlist_disposition() const
138 if (new_playlists_button.get_active()) {
139 return ARDOUR::NewPlaylist;
140 } else if (copy_playlists_button.get_active()) {
141 return ARDOUR::CopyPlaylist;
144 return ARDOUR::SharePlaylist;
148 DuplicateRouteDialog::on_response (int response)
152 if (response != RESPONSE_OK) {
156 ARDOUR::PlaylistDisposition playlist_action = playlist_disposition ();
157 uint32_t cnt = count ();
159 /* Copy the track selection because it will/may change as we add new ones */
160 TrackSelection tracks (PublicEditor::instance().get_selection().tracks);
163 /* Track Selection should be sorted into presentation order before
164 * duplicating, so that new tracks appear in same order as the
170 for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
171 RouteUI* rui = dynamic_cast<RouteUI*> (*t);
173 sl.push_back (rui->route());
177 sl.sort (Stripable::Sorter());
179 for (StripableList::iterator s = sl.begin(); s != sl.end(); ++s) {
181 boost::shared_ptr<Route> r;
183 if ((r = boost::dynamic_pointer_cast<Route> (*s)) == 0) {
184 /* some other type of Stripable, not a route */
188 if ((*s)->is_master() || (*s)->is_monitor()) {
189 /* no option to duplicate these */
193 XMLNode& state (r->get_state());
194 RouteList rl = _session->new_route_from_template (cnt, ARDOUR_UI::instance()->translate_order (insert_at()), state, std::string(), playlist_action);
196 /* normally the state node would be added to a parent, and
197 * ownership would transfer. Because we don't do that here,
198 * we need to delete the node ourselves.
210 MessageDialog msg (_("1 or more tracks/busses could not be duplicated"),
211 true, MESSAGE_ERROR, BUTTONS_OK, true);
212 msg.set_position (WIN_POS_MOUSE);
217 RouteDialogs::InsertAt
218 DuplicateRouteDialog::insert_at ()
220 using namespace RouteDialogs;
222 std::string str = insert_at_combo.get_active_text();
224 if (str == _("First")) {
226 } else if (str == _("After Selection")) {
227 return AfterSelection;
228 } else if (str == _("Before Selection")){
229 return BeforeSelection;