2 Copyright (C) 2004 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.
22 #include <gtkmm/button.h>
23 #include <gtkmm/ctree.h>
25 #include <ardour/session_playlist.h>
26 #include <ardour/diskstream.h>
27 #include <ardour/playlist.h>
28 #include <ardour/audio_track.h>
29 #include <ardour/audioplaylist.h>
30 #include <ardour/configuration.h>
32 #include <gtkmm2ext/gtk_ui.h>
34 #include "playlist_selector.h"
36 #include "gui_thread.h"
43 using namespace ARDOUR;
45 static const gchar *tree_display_titles[] = {
46 N_("Playlists grouped by track"),
50 PlaylistSelector::PlaylistSelector ()
51 : ArdourDialog ("playlist selector"),
52 tree (internationalize (tree_display_titles)),
53 close_button (_("close"))
57 set_position (Gtk::WIN_POS_MOUSE);
58 set_name ("PlaylistSelectorWindow");
59 set_title (_("ardour: playlists"));
61 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
62 set_size_request (300, 200);
64 scroller.add_with_viewport (tree);
65 scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
67 close_button.signal_clicked().connect (mem_fun(*this, &PlaylistSelector::close_button_click));
69 vpacker.set_border_width (6);
70 vpacker.set_spacing (12);
71 vpacker.pack_start (scroller);
72 vpacker.pack_start (close_button, false, false);
77 PlaylistSelector::~PlaylistSelector ()
83 PlaylistSelector::clear_map ()
85 for (DSPL_Map::iterator x = dspl_map.begin(); x != dspl_map.end(); ++x) {
92 PlaylistSelector::show_for (RouteUI* ruix)
94 using namespace CTree_Helpers;
95 vector<const char*> item;
97 RowList::iterator tmpi;
98 RowList::iterator others;
104 str = _("ardour: playlist for ");
105 str += rui->route().name();
110 select_connection.disconnect ();
112 /* ---------------------------------------- */
113 /* XXX MAKE ME A FUNCTION (no CTree::clear() in gtkmm 1.2) */
114 gtk_ctree_remove_node (tree.gobj(), NULL);
115 /* ---------------------------------------- */
117 session->foreach_playlist (this, &PlaylistSelector::add_playlist_to_map);
119 this_ds = rui->get_diskstream();
122 item.push_back (_("Other tracks"));
123 others = tree.rows().insert (tree.rows().begin(), Element (item));
125 for (DSPL_Map::iterator x = dspl_map.begin(); x != dspl_map.end(); ++x) {
127 DiskStream* ds = session->diskstream_by_id (x->first);
133 /* add a node for the diskstream */
137 if (ds->name().empty()) {
138 item.push_back (_("unassigned"));
140 item.push_back (ds->name().c_str());
144 i = tree.rows().insert (tree.rows().begin(),
145 Gtk::CTree_Helpers::Element (item));
147 i = others->subtree().insert (others->subtree().end(),
148 Gtk::CTree_Helpers::Element (item));
151 /* Now insert all the playlists for this diskstream/track in a subtree */
153 list<Playlist*> *pls = x->second;
155 for (list<Playlist*>::iterator p = pls->begin(); p != pls->end(); ++p) {
158 item.push_back ((*p)->name().c_str());
160 tmpi = i->subtree().insert (i->subtree().end(), Element (item));
162 if (*p == this_ds->playlist()) {
166 (*tmpi).set_data (*p);
176 select_connection = tree.tree_select_row.connect (mem_fun(*this, &PlaylistSelector::row_selected));
180 PlaylistSelector::add_playlist_to_map (Playlist *pl)
188 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
192 DSPL_Map::iterator x;
194 if ((x = dspl_map.find (apl->get_orig_diskstream_id())) == dspl_map.end()) {
196 pair<ARDOUR::id_t,list<Playlist*>*> newp (apl->get_orig_diskstream_id(), new list<Playlist*>);
198 x = dspl_map.insert (dspl_map.end(), newp);
201 x->second->push_back (pl);
205 PlaylistSelector::set_session (Session* s)
207 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlaylistSelector::set_session), s));
212 session->going_away.connect (bind (mem_fun(*this, &PlaylistSelector::set_session), static_cast<Session*> (0)));
217 PlaylistSelector::close_button_click ()
224 PlaylistSelector::row_selected (Gtk::CTree::Row row, gint col)
228 if ((playlist = (Playlist *) row.get_data()) != 0) {
233 if ((at = dynamic_cast<AudioTrack*> (&rui->route())) == 0) {
238 if ((apl = dynamic_cast<AudioPlaylist*> (playlist)) == 0) {
243 at->disk_stream().use_playlist (apl);