one more send zipper fix
[ardour.git] / libs / ardour / named_selection.cc
1 /*
2     Copyright (C) 2003 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <pbd/failed_constructor.h>
22 #include <pbd/error.h>
23
24 #include <ardour/session.h>
25 #include <ardour/utils.h>
26 #include <ardour/playlist.h>
27 #include <ardour/named_selection.h>
28
29 #include "i18n.h"
30
31 using namespace ARDOUR;
32
33 sigc::signal<void,NamedSelection*> NamedSelection::NamedSelectionCreated;
34
35 NamedSelection::NamedSelection (string n, list<Playlist*>& l) 
36         : name (n)
37 {
38         playlists = l;
39         for (list<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
40                 (*i)->ref();
41         }
42         NamedSelectionCreated (this);
43 }
44
45 NamedSelection::NamedSelection (Session& session, const XMLNode& node)
46 {
47         XMLNode* lists_node;
48         const XMLProperty* property;
49
50         if ((property = node.property ("name")) == 0) {
51                 throw failed_constructor();
52         }
53
54         name = property->value();
55         
56         if ((lists_node = find_named_node (node, "Playlists")) == 0) {
57                 return;
58         }
59
60         XMLNodeList nlist = lists_node->children();
61         XMLNodeConstIterator niter;
62
63         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
64
65                 const XMLNode* plnode;
66                 string playlist_name;
67                 Playlist* playlist;
68
69                 plnode = *niter;
70
71                 if ((property = plnode->property ("name")) != 0) {
72                         if ((playlist = session.playlist_by_name (property->value())) != 0) {
73                                 playlist->ref();
74                                 playlists.push_back (playlist);
75                         } else {
76                                 warning << string_compose (_("Chunk %1 uses an unknown playlist \"%2\""), name, property->value()) << endmsg;
77                         }
78                 } else {
79                         error << string_compose (_("Chunk %1 contains misformed playlist information"), name) << endmsg;
80                         throw failed_constructor();
81                 }
82         }
83
84         NamedSelectionCreated (this);
85 }
86
87 NamedSelection::~NamedSelection ()
88 {
89         for (list<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
90                 (*i)->unref();
91         }
92 }
93
94 int
95 NamedSelection::set_state (const XMLNode& node)
96 {
97         return 0;
98 }
99
100 XMLNode&
101 NamedSelection::get_state ()
102 {
103         XMLNode* root = new XMLNode ("NamedSelection");
104         XMLNode* child;
105
106         root->add_property ("name", name);
107         child = root->add_child ("Playlists");
108
109         for (list<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
110                 XMLNode* plnode = new XMLNode ("Playlist");
111
112                 plnode->add_property ("name", (*i)->name());
113                 child->add_child_nocopy (*plnode);
114         }
115         
116         return *root;
117 }