Set mixbufs count in the case of a panner being used, as
[ardour2.git] / gtk2_ardour / playlist_selector.cc
blobe0c51082a1eeadaa5a19a1859e6893d2f3edec54
1 /*
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.
21 #include <gtkmm/button.h>
23 #include "ardour/session_playlist.h"
24 #include "ardour/audio_diskstream.h"
25 #include "ardour/playlist.h"
26 #include "ardour/audio_track.h"
27 #include "ardour/audioplaylist.h"
28 #include "ardour/configuration.h"
30 #include <gtkmm2ext/gtk_ui.h>
32 #include "playlist_selector.h"
33 #include "route_ui.h"
34 #include "gui_thread.h"
36 #include "i18n.h"
38 using namespace std;
39 using namespace Gtk;
40 using namespace Gtkmm2ext;
41 using namespace ARDOUR;
42 using namespace PBD;
44 PlaylistSelector::PlaylistSelector ()
45 : ArdourDialog (_("Playlists"))
47 rui = 0;
49 set_position (WIN_POS_MOUSE);
50 set_name ("PlaylistSelectorWindow");
51 set_modal(true);
52 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
53 set_size_request (300, 200);
55 model = TreeStore::create (columns);
56 tree.set_model (model);
57 tree.append_column (_("Playlists grouped by track"), columns.text);
59 scroller.add (tree);
60 scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
62 get_vbox()->set_border_width (6);
63 get_vbox()->set_spacing (12);
65 get_vbox()->pack_start (scroller);
67 Button* b = add_button (_("close"), RESPONSE_CANCEL);
68 b->signal_clicked().connect (sigc::mem_fun(*this, &PlaylistSelector::close_button_click));
72 PlaylistSelector::~PlaylistSelector ()
74 clear_map ();
77 void
78 PlaylistSelector::clear_map ()
80 for (TrackPlaylistMap::iterator x = trpl_map.begin(); x != trpl_map.end(); ++x) {
81 delete x->second;
83 trpl_map.clear ();
86 bool
87 PlaylistSelector::on_unmap_event (GdkEventAny* ev)
89 clear_map ();
90 if (model) {
91 model->clear ();
93 return Dialog::on_unmap_event (ev);
96 void
97 PlaylistSelector::show_for (RouteUI* ruix)
99 vector<const char*> item;
100 string str;
102 rui = ruix;
104 set_title (string_compose (_("Playlist for %1"), rui->route()->name()));
106 clear_map ();
107 select_connection.disconnect ();
109 model->clear ();
111 _session->playlists->foreach (this, &PlaylistSelector::add_playlist_to_map);
113 boost::shared_ptr<Track> this_track = rui->track();
115 TreeModel::Row others = *(model->append ());
117 others[columns.text] = _("Other tracks");
118 boost::shared_ptr<Playlist> proxy = others[columns.playlist];
119 proxy.reset ();
121 for (TrackPlaylistMap::iterator x = trpl_map.begin(); x != trpl_map.end(); ++x) {
123 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (_session->route_by_id (x->first));
125 if (tr == 0) {
126 continue;
129 /* add a node for the track */
131 string nodename;
133 if (tr->name().empty()) {
134 nodename = _("unassigned");
135 } else {
136 nodename = tr->name().c_str();
139 TreeModel::Row row;
140 TreeModel::Row* selected_row = 0;
141 TreePath this_path;
143 if (tr == this_track) {
144 row = *(model->prepend());
145 row[columns.text] = nodename;
146 boost::shared_ptr<Playlist> proxy = row[columns.playlist];
147 proxy.reset ();
148 } else {
149 row = *(model->append (others.children()));
150 row[columns.text] = nodename;
151 boost::shared_ptr<Playlist> proxy = row[columns.playlist];
152 proxy.reset ();
155 /* Now insert all the playlists for this diskstream/track in a subtree */
157 list<boost::shared_ptr<Playlist> >* pls = x->second;
159 for (list<boost::shared_ptr<Playlist> >::iterator p = pls->begin(); p != pls->end(); ++p) {
161 TreeModel::Row child_row;
163 child_row = *(model->append (row.children()));
164 child_row[columns.text] = (*p)->name();
165 child_row[columns.playlist] = *p;
167 if (*p == this_track->playlist()) {
168 selected_row = &child_row;
172 if (selected_row != 0) {
173 tree.get_selection()->select (*selected_row);
177 // Add unassigned (imported) playlists to the list
178 list<boost::shared_ptr<Playlist> > unassigned;
179 _session->playlists->unassigned (unassigned);
181 TreeModel::Row row;
182 TreeModel::Row* selected_row = 0;
183 TreePath this_path;
185 row = *(model->append (others.children()));
186 row[columns.text] = _("Imported");
187 proxy = row[columns.playlist];
188 proxy.reset ();
190 for (list<boost::shared_ptr<Playlist> >::iterator p = unassigned.begin(); p != unassigned.end(); ++p) {
191 TreeModel::Row child_row;
193 child_row = *(model->append (row.children()));
194 child_row[columns.text] = (*p)->name();
195 child_row[columns.playlist] = *p;
197 if (*p == this_track->playlist()) {
198 selected_row = &child_row;
201 if (selected_row != 0) {
202 tree.get_selection()->select (*selected_row);
206 show_all ();
207 select_connection = tree.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PlaylistSelector::selection_changed));
210 void
211 PlaylistSelector::add_playlist_to_map (boost::shared_ptr<Playlist> pl)
213 boost::shared_ptr<AudioPlaylist> apl;
215 if (pl->frozen()) {
216 return;
219 if ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) == 0) {
220 return;
223 TrackPlaylistMap::iterator x;
225 if ((x = trpl_map.find (apl->get_orig_diskstream_id())) == trpl_map.end()) {
226 x = trpl_map.insert (trpl_map.end(), make_pair (apl->get_orig_diskstream_id(), new list<boost::shared_ptr<Playlist> >));
229 x->second->push_back (pl);
232 void
233 PlaylistSelector::close_button_click ()
235 rui = 0;
236 hide ();
239 void
240 PlaylistSelector::selection_changed ()
242 boost::shared_ptr<Playlist> playlist;
244 TreeModel::iterator iter = tree.get_selection()->get_selected();
246 if (!iter || rui == 0) {
247 /* nothing selected */
248 return;
251 if ((playlist = ((*iter)[columns.playlist])) != 0) {
253 boost::shared_ptr<AudioTrack> at;
254 boost::shared_ptr<AudioPlaylist> apl;
256 if ((at = rui->audio_track()) == 0) {
257 /* eh? */
258 return;
261 if ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (playlist)) == 0) {
262 /* eh? */
263 return;
266 at->use_playlist (apl);
268 hide ();