ardour
playlist_source.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 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 
19 #ifdef WAF_BUILD
20 #include "libardour-config.h"
21 #endif
22 
23 #include <vector>
24 #include <cstdio>
25 
26 #include <glibmm/fileutils.h>
27 #include <glibmm/miscutils.h>
28 
29 #include "pbd/error.h"
30 #include "pbd/convert.h"
31 #include "pbd/enumwriter.h"
32 
33 #include "ardour/playlist.h"
34 #include "ardour/playlist_source.h"
36 
37 #include "i18n.h"
38 
39 using namespace std;
40 using namespace ARDOUR;
41 using namespace PBD;
42 
43 PlaylistSource::PlaylistSource (Session& s, const ID& orig, const std::string& name, boost::shared_ptr<Playlist> p, DataType type,
44  frameoffset_t begin, framecnt_t len, Source::Flag /*flags*/)
45  : Source (s, type, name)
46  , _playlist (p)
47  , _original (orig)
48 {
49  /* PlaylistSources are never writable, renameable, removable or destructive */
51 
52  _playlist = p;
53  _playlist_offset = begin;
54  _playlist_length = len;
55 
57 }
58 
60  : Source (s, DataType::AUDIO, "toBeRenamed")
61 {
62  /* PlaylistSources are never writable, renameable, removable or destructive */
64 
65 
67  throw failed_constructor ();
68  }
69 }
70 
72 {
73 }
74 
75 void
77 {
78  char buf[64];
79 
80  _playlist->id().print (buf, sizeof (buf));
81  node.add_property ("playlist", buf);
82  snprintf (buf, sizeof (buf), "%" PRIi64, _playlist_offset);
83  node.add_property ("offset", buf);
84  snprintf (buf, sizeof (buf), "%" PRIu64, _playlist_length);
85  node.add_property ("length", buf);
86  node.add_property ("original", id().to_s());
87 
89 }
90 
91 int
92 PlaylistSource::set_state (const XMLNode& node, int /*version*/)
93 {
94  /* check that we have a playlist ID */
95 
96  const XMLProperty *prop = node.property (X_("playlist"));
97 
98  if (!prop) {
99  error << _("No playlist ID in PlaylistSource XML!") << endmsg;
100  throw failed_constructor ();
101  }
102 
103  /* create playlist from child node */
104 
105  XMLNodeList nlist;
106  XMLNodeConstIterator niter;
107 
108  nlist = node.children();
109 
110  for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
111  if ((*niter)->name() == "Playlist") {
112  _playlist = PlaylistFactory::create (_session, **niter, true, false);
113  break;
114  }
115  }
116 
117  if (!_playlist) {
118  error << _("Could not construct playlist for PlaylistSource from session data!") << endmsg;
119  throw failed_constructor ();
120  }
121 
122  /* other properties */
123 
124  if ((prop = node.property (X_("name"))) == 0) {
125  throw failed_constructor ();
126  }
127 
128  set_name (prop->value());
129 
130  if ((prop = node.property (X_("offset"))) == 0) {
131  throw failed_constructor ();
132  }
133  sscanf (prop->value().c_str(), "%" PRIi64, &_playlist_offset);
134 
135  if ((prop = node.property (X_("length"))) == 0) {
136  throw failed_constructor ();
137  }
138 
139  sscanf (prop->value().c_str(), "%" PRIu64, &_playlist_length);
140 
141  /* XXX not quite sure why we set our ID back to the "original" one
142  here. october 2011, paul
143  */
144 
145  if ((prop = node.property (X_("original"))) == 0) {
146  throw failed_constructor ();
147  }
148 
149  set_id (prop->value());
150 
152 
153  return 0;
154 }
Flag _flags
Definition: source.h:119
frameoffset_t _playlist_offset
ARDOUR::Session & _session
int set_state(const XMLNode &, int version)
const std::string & value() const
Definition: xml++.h:159
XMLNode & get_state()
Definition: playlist.cc:2184
Definition: Beats.hpp:239
LIBPBD_API Transmitter error
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
Definition: id.h:32
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
#define _(Text)
Definition: i18n.h:11
boost::shared_ptr< Playlist > _playlist
PlaylistSource(Session &, const PBD::ID &, const std::string &name, boost::shared_ptr< Playlist >, DataType, frameoffset_t begin, framecnt_t len, Source::Flag flags)
#define X_(Text)
Definition: i18n.h:13
int64_t framecnt_t
Definition: types.h:76
XMLProperty * property(const char *)
Definition: xml++.cc:413
Definition: amp.h:29
const PBD::ID & id() const
Definition: stateful.h:68
virtual bool set_name(const std::string &str)
void print(char *buf, uint32_t bufsize) const
Definition: id.cc:73
bool set_id(const XMLNode &)
Definition: stateful.cc:381
void add_state(XMLNode &)
int64_t frameoffset_t
Definition: types.h:71
static int loading_state_version
Definition: stateful.h:90
uint32_t max_source_level() const
Definition: playlist.cc:3202
XMLProperty * add_property(const char *name, const std::string &value)
const char * name
void add_child_nocopy(XMLNode &)
Definition: xml++.cc:357
uint32_t _level
Definition: source.h:126
Definition: xml++.h:95
Definition: debug.h:30
XMLNodeList::const_iterator XMLNodeConstIterator
Definition: xml++.h:49
static boost::shared_ptr< Playlist > create(Session &, const XMLNode &, bool hidden=false, bool unused=false)