2 Copyright (C) 2003 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 <pbd/failed_constructor.h>
22 #include <pbd/error.h>
24 #include <ardour/session.h>
25 #include <ardour/utils.h>
26 #include <ardour/playlist.h>
27 #include <ardour/named_selection.h>
31 using namespace ARDOUR;
34 sigc::signal<void,NamedSelection*> NamedSelection::NamedSelectionCreated;
36 typedef std::list<boost::shared_ptr<Playlist> > PlaylistList;
38 NamedSelection::NamedSelection (string n, PlaylistList& l)
42 for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) {
45 NamedSelectionCreated (this);
48 NamedSelection::NamedSelection (Session& session, const XMLNode& node)
51 const XMLProperty* property;
53 if ((property = node.property ("name")) == 0) {
54 throw failed_constructor();
57 name = property->value();
59 if ((lists_node = find_named_node (node, "Playlists")) == 0) {
63 XMLNodeList nlist = lists_node->children();
64 XMLNodeConstIterator niter;
66 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
68 const XMLNode* plnode;
70 boost::shared_ptr<Playlist> playlist;
74 if ((property = plnode->property ("name")) != 0) {
75 if ((playlist = session.playlist_by_name (property->value())) != 0) {
77 playlists.push_back (playlist);
79 warning << string_compose (_("Chunk %1 uses an unknown playlist \"%2\""), name, property->value()) << endmsg;
82 error << string_compose (_("Chunk %1 contains misformed playlist information"), name) << endmsg;
83 throw failed_constructor();
87 NamedSelectionCreated (this);
90 NamedSelection::~NamedSelection ()
92 for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) {
98 NamedSelection::set_state (const XMLNode& node)
104 NamedSelection::get_state ()
106 XMLNode* root = new XMLNode ("NamedSelection");
109 root->add_property ("name", name);
110 child = root->add_child ("Playlists");
112 for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) {
113 XMLNode* plnode = new XMLNode ("Playlist");
115 plnode->add_property ("name", (*i)->name());
116 child->add_child_nocopy (*plnode);