summaryrefslogtreecommitdiff
path: root/libs/ardour/playlist_source.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-05-16 15:49:26 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-05-16 15:49:26 +0000
commit4b5bd4ca46fe00a473682bf21927a0d67ac1a3a4 (patch)
tree290d12cefb2ec876d922b88deb2800b73d67a38a /libs/ardour/playlist_source.cc
parentad5a326694fb29303bd23dc7a36e500211c621d3 (diff)
refactor playlist sources to allow for MIDI and upcoming work on save/restore
git-svn-id: svn://localhost/ardour2/branches/3.0@9521 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/playlist_source.cc')
-rw-r--r--libs/ardour/playlist_source.cc132
1 files changed, 132 insertions, 0 deletions
diff --git a/libs/ardour/playlist_source.cc b/libs/ardour/playlist_source.cc
new file mode 100644
index 0000000000..7ac175959c
--- /dev/null
+++ b/libs/ardour/playlist_source.cc
@@ -0,0 +1,132 @@
+/*
+ Copyright (C) 2011 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifdef WAF_BUILD
+#include "libardour-config.h"
+#endif
+
+#include <vector>
+#include <cstdio>
+
+#include <glibmm/fileutils.h>
+#include <glibmm/miscutils.h>
+
+#include "pbd/error.h"
+#include "pbd/convert.h"
+#include "pbd/enumwriter.h"
+
+#include "ardour/playlist.h"
+#include "ardour/playlist_source.h"
+#include "ardour/session.h"
+#include "ardour/session_playlists.h"
+#include "ardour/source_factory.h"
+
+#include "i18n.h"
+
+using namespace std;
+using namespace ARDOUR;
+using namespace PBD;
+
+PlaylistSource::PlaylistSource (Session& s, const std::string& name, boost::shared_ptr<Playlist> p, DataType type,
+ frameoffset_t begin, framecnt_t len, Source::Flag flags)
+ : Source (s, type, name)
+ , _playlist (p)
+{
+ /* PlaylistSources are never writable, renameable, removable or destructive */
+ _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
+
+ _playlist = p;
+ _playlist_offset = begin;
+ _playlist_length = len;
+
+ _level = _playlist->max_source_level () + 1;
+}
+
+PlaylistSource::PlaylistSource (Session& s, const XMLNode& node)
+ : Source (s, DataType::AUDIO, "toBeRenamed")
+{
+ /* PlaylistSources are never writable, renameable, removable or destructive */
+ _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
+
+
+ if (set_state (node, Stateful::loading_state_version)) {
+ throw failed_constructor ();
+ }
+}
+
+PlaylistSource::~PlaylistSource ()
+{
+}
+
+void
+PlaylistSource::add_state (XMLNode& node)
+{
+ char buf[64];
+
+ _playlist->id().print (buf, sizeof (buf));
+ node.add_property ("playlist", buf);
+ snprintf (buf, sizeof (buf), "%" PRIi64, _playlist_offset);
+ node.add_property ("offset", buf);
+ snprintf (buf, sizeof (buf), "%" PRIu64, _playlist_length);
+ node.add_property ("length", buf);
+}
+
+int
+PlaylistSource::set_state (const XMLNode& node, int version)
+{
+ /* get playlist ID */
+
+ const XMLProperty *prop = node.property (X_("playlist"));
+
+ if (!prop) {
+ throw failed_constructor ();
+ }
+
+ PBD::ID id (prop->value());
+
+ /* get playlist */
+
+ boost::shared_ptr<Playlist> p = _session.playlists->by_id (id);
+
+ if (!_playlist) {
+ throw failed_constructor ();
+ }
+
+ /* other properties */
+
+ if ((prop = node.property (X_("name"))) == 0) {
+ throw failed_constructor ();
+ }
+
+ set_name (prop->value());
+
+ if ((prop = node.property (X_("offset"))) == 0) {
+ throw failed_constructor ();
+ }
+ sscanf (prop->value().c_str(), "%" PRIi64, &_playlist_offset);
+
+ if ((prop = node.property (X_("length"))) == 0) {
+ throw failed_constructor ();
+ }
+
+ sscanf (prop->value().c_str(), "%" PRIu64, &_playlist_length);
+
+ _level = _playlist->max_source_level () + 1;
+
+ return 0;
+}