2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2004 Paul Davis
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
#include <gtkmm/button.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/audio_track.h"
|
|
|
|
#include "ardour/audioplaylist.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/playlist.h"
|
|
|
|
#include "ardour/session_playlist.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
#include <gtkmm2ext/gtk_ui.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "playlist_selector.h"
|
|
|
|
#include "route_ui.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
2007-03-18 12:45:43 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace ARDOUR;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
PlaylistSelector::PlaylistSelector ()
|
2010-05-02 19:54:25 -04:00
|
|
|
: ArdourDialog (_("Playlists"))
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
rui = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
set_name ("PlaylistSelectorWindow");
|
|
|
|
set_modal(true);
|
2005-09-25 16:33:00 -04:00
|
|
|
add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
|
|
|
|
set_size_request (300, 200);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-28 12:22:43 -04:00
|
|
|
model = TreeStore::create (columns);
|
|
|
|
tree.set_model (model);
|
|
|
|
tree.append_column (_("Playlists grouped by track"), columns.text);
|
|
|
|
|
|
|
|
scroller.add (tree);
|
2005-11-27 09:09:50 -05:00
|
|
|
scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2006-12-18 21:41:19 -05:00
|
|
|
get_vbox()->set_border_width (6);
|
|
|
|
get_vbox()->set_spacing (12);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-27 09:09:50 -05:00
|
|
|
get_vbox()->pack_start (scroller);
|
|
|
|
|
2012-06-01 11:19:19 -04:00
|
|
|
Button* b = add_button (_("Close"), RESPONSE_CANCEL);
|
2009-12-11 18:29:48 -05:00
|
|
|
b->signal_clicked().connect (sigc::mem_fun(*this, &PlaylistSelector::close_button_click));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PlaylistSelector::~PlaylistSelector ()
|
|
|
|
{
|
|
|
|
clear_map ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlaylistSelector::clear_map ()
|
|
|
|
{
|
2010-04-21 16:42:22 -04:00
|
|
|
for (TrackPlaylistMap::iterator x = trpl_map.begin(); x != trpl_map.end(); ++x) {
|
2005-09-25 14:42:24 -04:00
|
|
|
delete x->second;
|
|
|
|
}
|
2010-04-21 16:42:22 -04:00
|
|
|
trpl_map.clear ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2006-12-14 09:15:43 -05:00
|
|
|
bool
|
|
|
|
PlaylistSelector::on_unmap_event (GdkEventAny* ev)
|
|
|
|
{
|
|
|
|
clear_map ();
|
|
|
|
if (model) {
|
|
|
|
model->clear ();
|
|
|
|
}
|
|
|
|
return Dialog::on_unmap_event (ev);
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
|
|
|
PlaylistSelector::show_for (RouteUI* ruix)
|
|
|
|
{
|
|
|
|
vector<const char*> item;
|
|
|
|
string str;
|
|
|
|
|
|
|
|
rui = ruix;
|
|
|
|
|
2009-10-19 13:25:37 -04:00
|
|
|
set_title (string_compose (_("Playlist for %1"), rui->route()->name()));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
clear_map ();
|
|
|
|
select_connection.disconnect ();
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
model->clear ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
_session->playlists->foreach (this, &PlaylistSelector::add_playlist_to_map);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
boost::shared_ptr<Track> this_track = rui->track();
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-27 09:09:50 -05:00
|
|
|
TreeModel::Row others = *(model->append ());
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-28 12:22:43 -04:00
|
|
|
others[columns.text] = _("Other tracks");
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<Playlist> proxy = others[columns.playlist];
|
|
|
|
proxy.reset ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
for (TrackPlaylistMap::iterator x = trpl_map.begin(); x != trpl_map.end(); ++x) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (_session->route_by_id (x->first));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-12-10 14:20:15 -05:00
|
|
|
/* legacy sessions stored the diskstream ID as the original
|
|
|
|
* playlist owner. so try there instead.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tr == 0) {
|
|
|
|
tr = _session->track_by_diskstream_id (x->first);
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
if (tr == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
/* add a node for the track */
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-28 12:22:43 -04:00
|
|
|
string nodename;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
if (tr->name().empty()) {
|
2005-09-28 12:22:43 -04:00
|
|
|
nodename = _("unassigned");
|
2005-09-25 14:42:24 -04:00
|
|
|
} else {
|
2010-04-21 16:42:22 -04:00
|
|
|
nodename = tr->name().c_str();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-28 12:22:43 -04:00
|
|
|
TreeModel::Row row;
|
2012-04-06 21:53:56 -04:00
|
|
|
TreeModel::Row selected_row;
|
|
|
|
bool have_selected = false;
|
2005-09-28 12:22:43 -04:00
|
|
|
TreePath this_path;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
if (tr == this_track) {
|
2005-09-28 12:22:43 -04:00
|
|
|
row = *(model->prepend());
|
|
|
|
row[columns.text] = nodename;
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<Playlist> proxy = row[columns.playlist];
|
|
|
|
proxy.reset ();
|
2005-09-25 14:42:24 -04:00
|
|
|
} else {
|
2005-09-28 12:22:43 -04:00
|
|
|
row = *(model->append (others.children()));
|
|
|
|
row[columns.text] = nodename;
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<Playlist> proxy = row[columns.playlist];
|
|
|
|
proxy.reset ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2005-09-28 12:22:43 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
/* Now insert all the playlists for this diskstream/track in a subtree */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
list<boost::shared_ptr<Playlist> >* pls = x->second;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-12-14 09:15:43 -05:00
|
|
|
for (list<boost::shared_ptr<Playlist> >::iterator p = pls->begin(); p != pls->end(); ++p) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-28 12:22:43 -04:00
|
|
|
TreeModel::Row child_row;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-28 12:22:43 -04:00
|
|
|
child_row = *(model->append (row.children()));
|
|
|
|
child_row[columns.text] = (*p)->name();
|
|
|
|
child_row[columns.playlist] = *p;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
if (*p == this_track->playlist()) {
|
2012-04-06 21:53:56 -04:00
|
|
|
selected_row = child_row;
|
|
|
|
have_selected = true;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2012-04-06 21:53:56 -04:00
|
|
|
if (have_selected) {
|
|
|
|
tree.get_selection()->select (selected_row);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 04:29:30 -04:00
|
|
|
// Add unassigned (imported) playlists to the list
|
|
|
|
list<boost::shared_ptr<Playlist> > unassigned;
|
2009-12-17 13:24:23 -05:00
|
|
|
_session->playlists->unassigned (unassigned);
|
2008-09-26 04:29:30 -04:00
|
|
|
|
|
|
|
TreeModel::Row row;
|
2012-04-06 21:54:06 -04:00
|
|
|
TreeModel::Row selected_row;
|
|
|
|
bool have_selected = false;
|
2008-09-26 04:29:30 -04:00
|
|
|
TreePath this_path;
|
|
|
|
|
|
|
|
row = *(model->append (others.children()));
|
|
|
|
row[columns.text] = _("Imported");
|
|
|
|
proxy = row[columns.playlist];
|
|
|
|
proxy.reset ();
|
|
|
|
|
|
|
|
for (list<boost::shared_ptr<Playlist> >::iterator p = unassigned.begin(); p != unassigned.end(); ++p) {
|
|
|
|
TreeModel::Row child_row;
|
|
|
|
|
|
|
|
child_row = *(model->append (row.children()));
|
|
|
|
child_row[columns.text] = (*p)->name();
|
|
|
|
child_row[columns.playlist] = *p;
|
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
if (*p == this_track->playlist()) {
|
2012-04-06 21:54:06 -04:00
|
|
|
selected_row = child_row;
|
|
|
|
have_selected = true;
|
2008-09-26 04:29:30 -04:00
|
|
|
}
|
|
|
|
|
2012-04-06 21:54:06 -04:00
|
|
|
if (have_selected) {
|
|
|
|
tree.get_selection()->select (selected_row);
|
2008-09-26 04:29:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
show_all ();
|
2009-12-11 18:29:48 -05:00
|
|
|
select_connection = tree.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PlaylistSelector::selection_changed));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-12-14 09:15:43 -05:00
|
|
|
PlaylistSelector::add_playlist_to_map (boost::shared_ptr<Playlist> pl)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<AudioPlaylist> apl;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (pl->frozen()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-12-14 09:15:43 -05:00
|
|
|
if ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
TrackPlaylistMap::iterator x;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-12-10 14:20:15 -05:00
|
|
|
if ((x = trpl_map.find (apl->get_orig_track_id())) == trpl_map.end()) {
|
|
|
|
x = trpl_map.insert (trpl_map.end(), make_pair (apl->get_orig_track_id(), new list<boost::shared_ptr<Playlist> >));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
x->second->push_back (pl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlaylistSelector::close_button_click ()
|
|
|
|
{
|
|
|
|
rui = 0;
|
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-09-28 12:22:43 -04:00
|
|
|
PlaylistSelector::selection_changed ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<Playlist> playlist;
|
2005-09-28 12:22:43 -04:00
|
|
|
|
|
|
|
TreeModel::iterator iter = tree.get_selection()->get_selected();
|
|
|
|
|
2006-07-27 12:52:14 -04:00
|
|
|
if (!iter || rui == 0) {
|
2005-09-28 12:22:43 -04:00
|
|
|
/* nothing selected */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((playlist = ((*iter)[columns.playlist])) != 0) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-06-15 18:05:07 -04:00
|
|
|
boost::shared_ptr<AudioTrack> at;
|
2006-12-14 09:15:43 -05:00
|
|
|
boost::shared_ptr<AudioPlaylist> apl;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-07-27 12:52:14 -04:00
|
|
|
if ((at = rui->audio_track()) == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
/* eh? */
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-12-14 09:15:43 -05:00
|
|
|
if ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (playlist)) == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
/* eh? */
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-04-21 16:42:22 -04:00
|
|
|
at->use_playlist (apl);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|