From 4b5bd4ca46fe00a473682bf21927a0d67ac1a3a4 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 16 May 2011 15:49:26 +0000 Subject: 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 --- libs/ardour/playlist_source.cc | 132 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 libs/ardour/playlist_source.cc (limited to 'libs/ardour/playlist_source.cc') 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 +#include + +#include +#include + +#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 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 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; +} -- cgit v1.2.3