2 * Copyright (C) 2011-2012 David Robillard <d@drobilla.net>
3 * Copyright (C) 2011-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "libardour-config.h"
28 #include <glibmm/fileutils.h>
29 #include <glibmm/miscutils.h>
31 #include "pbd/error.h"
32 #include "pbd/types_convert.h"
33 #include "pbd/enumwriter.h"
35 #include "ardour/playlist.h"
36 #include "ardour/playlist_source.h"
37 #include "ardour/playlist_factory.h"
42 using namespace ARDOUR;
45 PlaylistSource::PlaylistSource (Session& s, const ID& orig, const std::string& name, boost::shared_ptr<Playlist> p, DataType type,
46 sampleoffset_t begin, samplecnt_t len, Source::Flag /*flags*/)
47 : Source (s, type, name)
51 /* PlaylistSources are never writable, renameable, removable or destructive */
52 _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
55 _playlist_offset = begin;
56 _playlist_length = len;
58 _level = _playlist->max_source_level () + 1;
61 PlaylistSource::PlaylistSource (Session& s, const XMLNode& node)
62 : Source (s, DataType::AUDIO, "toBeRenamed")
64 /* PlaylistSources are never writable, renameable, removable or destructive */
65 _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
68 if (set_state (node, Stateful::loading_state_version)) {
69 throw failed_constructor ();
73 PlaylistSource::~PlaylistSource ()
78 PlaylistSource::add_state (XMLNode& node)
80 node.set_property ("playlist", _playlist->id ());
81 node.set_property ("offset", _playlist_offset);
82 node.set_property ("length", _playlist_length);
83 node.set_property ("original", id());
85 node.add_child_nocopy (_playlist->get_state());
89 PlaylistSource::set_state (const XMLNode& node, int /*version*/)
91 /* check that we have a playlist ID */
93 XMLProperty const * prop = node.property (X_("playlist"));
96 error << _("No playlist ID in PlaylistSource XML!") << endmsg;
97 throw failed_constructor ();
100 /* create playlist from child node */
103 XMLNodeConstIterator niter;
105 nlist = node.children();
107 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
108 if ((*niter)->name() == "Playlist") {
109 _playlist = PlaylistFactory::create (_session, **niter, true, false);
115 error << _("Could not construct playlist for PlaylistSource from session data!") << endmsg;
116 throw failed_constructor ();
119 /* other properties */
122 if (!node.get_property (X_("name"), name)) {
123 throw failed_constructor ();
128 if (!node.get_property (X_("offset"), _playlist_offset)) {
129 throw failed_constructor ();
132 if (!node.get_property (X_("length"), _playlist_length)) {
133 throw failed_constructor ();
136 /* XXX not quite sure why we set our ID back to the "original" one
137 here. october 2011, paul
141 if (!node.get_property (X_("original"), str)) {
142 throw failed_constructor ();
147 _level = _playlist->max_source_level () + 1;