2 Copyright (C) 2011 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.
20 #include "libardour-config.h"
26 #include <glibmm/fileutils.h>
27 #include <glibmm/miscutils.h>
29 #include "pbd/error.h"
30 #include "pbd/convert.h"
31 #include "pbd/enumwriter.h"
33 #include "ardour/playlist.h"
34 #include "ardour/playlist_source.h"
35 #include "ardour/playlist_factory.h"
36 #include "ardour/session.h"
37 #include "ardour/session_playlists.h"
38 #include "ardour/source_factory.h"
43 using namespace ARDOUR;
46 PlaylistSource::PlaylistSource (Session& s, const ID& orig, const std::string& name, boost::shared_ptr<Playlist> p, DataType type,
47 frameoffset_t begin, framecnt_t len, Source::Flag /*flags*/)
48 : Source (s, type, name)
52 /* PlaylistSources are never writable, renameable, removable or destructive */
53 _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
56 _playlist_offset = begin;
57 _playlist_length = len;
59 _level = _playlist->max_source_level () + 1;
62 PlaylistSource::PlaylistSource (Session& s, const XMLNode& node)
63 : Source (s, DataType::AUDIO, "toBeRenamed")
65 /* PlaylistSources are never writable, renameable, removable or destructive */
66 _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
69 if (set_state (node, Stateful::loading_state_version)) {
70 throw failed_constructor ();
74 PlaylistSource::~PlaylistSource ()
79 PlaylistSource::add_state (XMLNode& node)
83 _playlist->id().print (buf, sizeof (buf));
84 node.add_property ("playlist", buf);
85 snprintf (buf, sizeof (buf), "%" PRIi64, _playlist_offset);
86 node.add_property ("offset", buf);
87 snprintf (buf, sizeof (buf), "%" PRIu64, _playlist_length);
88 node.add_property ("length", buf);
89 node.add_property ("original", id().to_s());
91 node.add_child_nocopy (_playlist->get_state());
95 PlaylistSource::set_state (const XMLNode& node, int /*version*/)
97 /* check that we have a playlist ID */
99 const XMLProperty *prop = node.property (X_("playlist"));
102 error << _("No playlist ID in PlaylistSource XML!") << endmsg;
103 throw failed_constructor ();
106 /* create playlist from child node */
109 XMLNodeConstIterator niter;
111 nlist = node.children();
113 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
114 if ((*niter)->name() == "Playlist") {
115 _playlist = PlaylistFactory::create (_session, **niter, true, false);
121 error << _("Could not construct playlist for PlaylistSource from session data!") << endmsg;
122 throw failed_constructor ();
125 /* other properties */
127 if ((prop = node.property (X_("name"))) == 0) {
128 throw failed_constructor ();
131 set_name (prop->value());
133 if ((prop = node.property (X_("offset"))) == 0) {
134 throw failed_constructor ();
136 sscanf (prop->value().c_str(), "%" PRIi64, &_playlist_offset);
138 if ((prop = node.property (X_("length"))) == 0) {
139 throw failed_constructor ();
142 sscanf (prop->value().c_str(), "%" PRIu64, &_playlist_length);
144 /* XXX not quite sure why we set our ID back to the "original" one
145 here. october 2011, paul
148 if ((prop = node.property (X_("original"))) == 0) {
149 throw failed_constructor ();
152 set_id (prop->value());
154 _level = _playlist->max_source_level () + 1;