2015-11-14 10:29:50 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2015-2019 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2015-11-14 10:29:50 -05:00
|
|
|
|
|
|
|
#include "gtkmm/stock.h"
|
|
|
|
|
2015-11-14 15:21:20 -05:00
|
|
|
#include "ardour/route.h"
|
|
|
|
#include "ardour/session.h"
|
|
|
|
|
2016-08-22 09:41:53 -04:00
|
|
|
#include "ardour_ui.h"
|
2015-11-14 15:21:20 -05:00
|
|
|
#include "editor.h"
|
2015-11-14 10:29:50 -05:00
|
|
|
#include "duplicate_routes_dialog.h"
|
2015-11-14 15:21:20 -05:00
|
|
|
#include "selection.h"
|
2015-11-14 10:29:50 -05:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2015-11-14 10:29:50 -05:00
|
|
|
|
2015-11-14 15:21:20 -05:00
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace Gtk;
|
|
|
|
|
2015-11-14 10:29:50 -05:00
|
|
|
DuplicateRouteDialog::DuplicateRouteDialog ()
|
2020-04-15 12:02:21 -04:00
|
|
|
: ArdourDialog (_("Duplicate Tracks/Busses"), false, false)
|
2017-01-05 08:03:22 -05:00
|
|
|
, playlist_option_label (_("For each Track:"))
|
|
|
|
, copy_playlists_button (playlist_button_group, _("Copy playlist"))
|
|
|
|
, new_playlists_button (playlist_button_group, _("New playlist"))
|
|
|
|
, share_playlists_button (playlist_button_group, _("Share playlist"))
|
2015-11-14 10:29:50 -05:00
|
|
|
, count_adjustment (1.0, 1.0, 999, 1.0, 10.0)
|
|
|
|
, count_spinner (count_adjustment)
|
2015-12-03 15:13:45 -05:00
|
|
|
, count_label (_("Duplicate each track/bus this number of times:"))
|
2015-11-14 10:29:50 -05:00
|
|
|
{
|
2015-11-14 10:35:07 -05:00
|
|
|
count_box.pack_start (count_label, false, false);
|
2015-12-03 15:13:45 -05:00
|
|
|
count_box.pack_start (count_spinner, false, false, 5);
|
|
|
|
get_vbox()->pack_start (count_box, false, false, 10);
|
2015-11-14 10:35:07 -05:00
|
|
|
|
2017-01-05 08:03:22 -05:00
|
|
|
Gtk::HBox* hb = manage (new HBox);
|
|
|
|
hb->pack_start (playlist_option_label, false, false);
|
|
|
|
get_vbox()->pack_start (*hb, false, false, 10);
|
|
|
|
|
2015-11-14 11:05:15 -05:00
|
|
|
playlist_button_box.pack_start (copy_playlists_button, false, false);
|
|
|
|
playlist_button_box.pack_start (new_playlists_button, false, false);
|
|
|
|
playlist_button_box.pack_start (share_playlists_button, false, false);
|
|
|
|
playlist_button_box.show_all ();
|
|
|
|
|
2022-01-26 15:11:15 -05:00
|
|
|
insert_at_combo.append (_("First"));
|
|
|
|
insert_at_combo.append (_("Before Selection"));
|
|
|
|
insert_at_combo.append (_("After Selection"));
|
|
|
|
insert_at_combo.append (_("Last"));
|
2016-08-22 09:06:13 -04:00
|
|
|
insert_at_combo.set_active (3);
|
|
|
|
|
|
|
|
Gtk::Label* l = manage (new Label (_("Insert duplicates at: ")));
|
|
|
|
Gtk::HBox* b = manage (new HBox);
|
|
|
|
b->pack_start (*l, false, false, 10);
|
|
|
|
b->pack_start (insert_at_combo, true, true);
|
|
|
|
|
|
|
|
get_vbox()->pack_end (*b, false, false, 10);
|
|
|
|
|
2015-11-14 10:29:50 -05:00
|
|
|
get_vbox()->show_all ();
|
|
|
|
|
2015-11-14 15:21:20 -05:00
|
|
|
add_button (Stock::CANCEL, RESPONSE_CANCEL);
|
|
|
|
add_button (Stock::OK, RESPONSE_OK);
|
2015-11-14 10:29:50 -05:00
|
|
|
}
|
|
|
|
|
2015-11-14 15:21:20 -05:00
|
|
|
int
|
2015-11-14 16:02:05 -05:00
|
|
|
DuplicateRouteDialog::restart (Session* s)
|
2015-11-14 10:29:50 -05:00
|
|
|
{
|
2015-11-14 16:02:05 -05:00
|
|
|
if (!s) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_session (s);
|
|
|
|
|
2015-11-14 15:21:20 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Route> r (rui->route());
|
2015-11-14 15:21:20 -05:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::dynamic_pointer_cast<Track> (r)) {
|
2015-11-14 15:21:20 -05:00
|
|
|
ntracks++;
|
2023-11-26 22:26:46 -05:00
|
|
|
} else if (!r->is_main_bus()) {
|
|
|
|
nbusses++;
|
2015-11-14 15:21:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntracks == 0 && nbusses == 0) {
|
|
|
|
std::cerr << "You can't do this\n";
|
|
|
|
return -1;
|
|
|
|
}
|
2015-11-14 10:29:50 -05:00
|
|
|
|
2015-11-14 11:05:15 -05:00
|
|
|
/* XXX grrr. Gtk Boxes do not shrink when children are removed,
|
|
|
|
which is what we really want to happen here.
|
|
|
|
*/
|
|
|
|
|
2015-11-14 16:02:05 -05:00
|
|
|
if (playlist_button_box.get_parent()) {
|
2015-11-14 11:05:15 -05:00
|
|
|
get_vbox()->remove (playlist_button_box);
|
2015-11-14 16:02:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ntracks > 0) {
|
2015-11-14 11:05:15 -05:00
|
|
|
get_vbox()->pack_end (playlist_button_box, false, false);
|
|
|
|
}
|
2015-11-14 15:21:20 -05:00
|
|
|
|
|
|
|
return 0;
|
2015-11-14 11:05:15 -05:00
|
|
|
}
|
|
|
|
|
2015-11-14 10:29:50 -05:00
|
|
|
uint32_t
|
|
|
|
DuplicateRouteDialog::count() const
|
|
|
|
{
|
|
|
|
return count_adjustment.get_value ();
|
|
|
|
}
|
|
|
|
|
|
|
|
ARDOUR::PlaylistDisposition
|
|
|
|
DuplicateRouteDialog::playlist_disposition() const
|
|
|
|
{
|
|
|
|
if (new_playlists_button.get_active()) {
|
|
|
|
return ARDOUR::NewPlaylist;
|
|
|
|
} else if (copy_playlists_button.get_active()) {
|
|
|
|
return ARDOUR::CopyPlaylist;
|
2015-11-14 10:35:07 -05:00
|
|
|
}
|
2015-11-14 10:29:50 -05:00
|
|
|
|
|
|
|
return ARDOUR::SharePlaylist;
|
|
|
|
}
|
2015-11-14 15:21:20 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-03-20 23:42:02 -04:00
|
|
|
/* Track Selection should be sorted into presentation order before
|
|
|
|
* duplicating, so that new tracks appear in same order as the
|
|
|
|
* originals.
|
|
|
|
*/
|
|
|
|
|
|
|
|
StripableList sl;
|
2015-11-14 15:21:20 -05:00
|
|
|
|
2019-03-20 23:42:02 -04:00
|
|
|
for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
|
2015-11-14 15:21:20 -05:00
|
|
|
RouteUI* rui = dynamic_cast<RouteUI*> (*t);
|
2019-03-20 23:50:29 -04:00
|
|
|
if (rui) {
|
|
|
|
sl.push_back (rui->route());
|
|
|
|
}
|
2019-03-20 23:42:02 -04:00
|
|
|
}
|
2015-11-14 15:21:20 -05:00
|
|
|
|
2019-03-20 23:42:02 -04:00
|
|
|
sl.sort (Stripable::Sorter());
|
|
|
|
|
|
|
|
for (StripableList::iterator s = sl.begin(); s != sl.end(); ++s) {
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Route> r;
|
2019-03-20 23:42:02 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if ((r = std::dynamic_pointer_cast<Route> (*s)) == 0) {
|
2019-03-20 23:42:02 -04:00
|
|
|
/* some other type of Stripable, not a route */
|
2015-11-14 15:21:20 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:26:46 -05:00
|
|
|
if ((*s)->is_main_bus ()) {
|
2015-11-14 15:21:20 -05:00
|
|
|
/* no option to duplicate these */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:42:02 -04:00
|
|
|
XMLNode& state (r->get_state());
|
2016-08-22 09:41:53 -04:00
|
|
|
RouteList rl = _session->new_route_from_template (cnt, ARDOUR_UI::instance()->translate_order (insert_at()), state, std::string(), playlist_action);
|
2015-11-14 15:21:20 -05:00
|
|
|
|
|
|
|
/* 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 ();
|
|
|
|
}
|
|
|
|
}
|
2016-08-22 09:06:13 -04:00
|
|
|
|
|
|
|
RouteDialogs::InsertAt
|
|
|
|
DuplicateRouteDialog::insert_at ()
|
|
|
|
{
|
|
|
|
using namespace RouteDialogs;
|
|
|
|
|
|
|
|
std::string str = insert_at_combo.get_active_text();
|
|
|
|
|
|
|
|
if (str == _("First")) {
|
|
|
|
return First;
|
|
|
|
} else if (str == _("After Selection")) {
|
|
|
|
return AfterSelection;
|
|
|
|
} else if (str == _("Before Selection")){
|
|
|
|
return BeforeSelection;
|
|
|
|
}
|
|
|
|
return Last;
|
|
|
|
}
|