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"
34 #include "gui_thread.h"
40 using namespace Gtkmm2ext
;
41 using namespace ARDOUR
;
44 PlaylistSelector::PlaylistSelector ()
45 : ArdourDialog (_("Playlists"))
49 set_position (WIN_POS_MOUSE
);
50 set_name ("PlaylistSelectorWindow");
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
);
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 ()
78 PlaylistSelector::clear_map ()
80 for (TrackPlaylistMap::iterator x
= trpl_map
.begin(); x
!= trpl_map
.end(); ++x
) {
87 PlaylistSelector::on_unmap_event (GdkEventAny
* ev
)
93 return Dialog::on_unmap_event (ev
);
97 PlaylistSelector::show_for (RouteUI
* ruix
)
99 vector
<const char*> item
;
104 set_title (string_compose (_("Playlist for %1"), rui
->route()->name()));
107 select_connection
.disconnect ();
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
];
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
));
129 /* add a node for the track */
133 if (tr
->name().empty()) {
134 nodename
= _("unassigned");
136 nodename
= tr
->name().c_str();
140 TreeModel::Row
* selected_row
= 0;
143 if (tr
== this_track
) {
144 row
= *(model
->prepend());
145 row
[columns
.text
] = nodename
;
146 boost::shared_ptr
<Playlist
> proxy
= row
[columns
.playlist
];
149 row
= *(model
->append (others
.children()));
150 row
[columns
.text
] = nodename
;
151 boost::shared_ptr
<Playlist
> proxy
= row
[columns
.playlist
];
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
);
182 TreeModel::Row
* selected_row
= 0;
185 row
= *(model
->append (others
.children()));
186 row
[columns
.text
] = _("Imported");
187 proxy
= row
[columns
.playlist
];
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
);
207 select_connection
= tree
.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PlaylistSelector::selection_changed
));
211 PlaylistSelector::add_playlist_to_map (boost::shared_ptr
<Playlist
> pl
)
213 boost::shared_ptr
<AudioPlaylist
> apl
;
219 if ((apl
= boost::dynamic_pointer_cast
<AudioPlaylist
> (pl
)) == 0) {
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
);
233 PlaylistSelector::close_button_click ()
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 */
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) {
261 if ((apl
= boost::dynamic_pointer_cast
<AudioPlaylist
> (playlist
)) == 0) {
266 at
->use_playlist (apl
);