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>
24 #include <ardour/session_playlist.h>
25 #include <ardour/audio_diskstream.h>
26 #include <ardour/playlist.h>
27 #include <ardour/audio_track.h>
28 #include <ardour/audioplaylist.h>
29 #include <ardour/configuration.h>
31 #include <gtkmm2ext/gtk_ui.h>
33 #include "playlist_selector.h"
35 #include "gui_thread.h"
42 using namespace ARDOUR;
45 PlaylistSelector::PlaylistSelector ()
46 : ArdourDialog ("playlist selector")
50 set_position (WIN_POS_MOUSE);
51 set_name ("PlaylistSelectorWindow");
52 set_title (_("ardour: playlists"));
54 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
55 set_size_request (300, 200);
57 model = TreeStore::create (columns);
58 tree.set_model (model);
59 tree.append_column (_("Playlists grouped by track"), columns.text);
62 scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
64 // GTK2FIX do we need this stuff or is GTK applying some policy now?
65 //set_border_width (6);
68 get_vbox()->pack_start (scroller);
70 Button* b = add_button (_("close"), RESPONSE_CANCEL);
71 b->signal_clicked().connect (mem_fun(*this, &PlaylistSelector::close_button_click));
75 PlaylistSelector::~PlaylistSelector ()
81 PlaylistSelector::clear_map ()
83 for (DSPL_Map::iterator x = dspl_map.begin(); x != dspl_map.end(); ++x) {
90 PlaylistSelector::show_for (RouteUI* ruix)
92 vector<const char*> item;
93 boost::shared_ptr<Diskstream> this_ds;
98 str = _("ardour: playlist for ");
99 str += rui->route()->name();
104 select_connection.disconnect ();
108 session->foreach_playlist (this, &PlaylistSelector::add_playlist_to_map);
110 this_ds = rui->get_diskstream();
112 TreeModel::Row others = *(model->append ());
114 others[columns.text] = _("Other tracks");
115 others[columns.playlist] = 0;
117 for (DSPL_Map::iterator x = dspl_map.begin(); x != dspl_map.end(); ++x) {
119 boost::shared_ptr<Diskstream> ds = session->diskstream_by_id (x->first);
125 /* add a node for the diskstream */
129 if (ds->name().empty()) {
130 nodename = _("unassigned");
132 nodename = ds->name().c_str();
136 TreeModel::Row* selected_row = 0;
140 row = *(model->prepend());
141 row[columns.text] = nodename;
142 row[columns.playlist] = 0;
144 row = *(model->append (others.children()));
145 row[columns.text] = nodename;
146 row[columns.playlist] = 0;
149 /* Now insert all the playlists for this diskstream/track in a subtree */
151 list<Playlist*> *pls = x->second;
153 for (list<Playlist*>::iterator p = pls->begin(); p != pls->end(); ++p) {
155 TreeModel::Row child_row;
157 child_row = *(model->append (row.children()));
158 child_row[columns.text] = (*p)->name();
159 child_row[columns.playlist] = *p;
161 if (*p == this_ds->playlist()) {
162 selected_row = &child_row;
166 if (selected_row != 0) {
167 tree.get_selection()->select (*selected_row);
172 select_connection = tree.get_selection()->signal_changed().connect (mem_fun(*this, &PlaylistSelector::selection_changed));
176 PlaylistSelector::add_playlist_to_map (Playlist *pl)
184 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
188 DSPL_Map::iterator x;
190 if ((x = dspl_map.find (apl->get_orig_diskstream_id())) == dspl_map.end()) {
192 pair<PBD::ID,list<Playlist*>*> newp (apl->get_orig_diskstream_id(), new list<Playlist*>);
194 x = dspl_map.insert (dspl_map.end(), newp);
197 x->second->push_back (pl);
201 PlaylistSelector::set_session (Session* s)
203 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlaylistSelector::set_session), s));
208 session->GoingAway.connect (bind (mem_fun(*this, &PlaylistSelector::set_session), static_cast<Session*> (0)));
213 PlaylistSelector::close_button_click ()
220 PlaylistSelector::selection_changed ()
224 TreeModel::iterator iter = tree.get_selection()->get_selected();
226 if (!iter || rui == 0) {
227 /* nothing selected */
231 if ((playlist = ((*iter)[columns.playlist])) != 0) {
236 if ((at = rui->audio_track()) == 0) {
241 if ((apl = dynamic_cast<AudioPlaylist*> (playlist)) == 0) {
246 at->diskstream()->use_playlist (apl);