Expose virtual-keyboard port as async-port
[ardour.git] / libs / ardour / playlist_source.cc
1 /*
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>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #ifdef WAF_BUILD
22 #include "libardour-config.h"
23 #endif
24
25 #include <vector>
26 #include <cstdio>
27
28 #include <glibmm/fileutils.h>
29 #include <glibmm/miscutils.h>
30
31 #include "pbd/error.h"
32 #include "pbd/types_convert.h"
33 #include "pbd/enumwriter.h"
34
35 #include "ardour/playlist.h"
36 #include "ardour/playlist_source.h"
37 #include "ardour/playlist_factory.h"
38
39 #include "pbd/i18n.h"
40
41 using namespace std;
42 using namespace ARDOUR;
43 using namespace PBD;
44
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)
48         , _playlist (p)
49         , _original (orig)
50 {
51         /* PlaylistSources are never writable, renameable, removable or destructive */
52         _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
53
54         _playlist = p;
55         _playlist_offset = begin;
56         _playlist_length = len;
57
58         _level = _playlist->max_source_level () + 1;
59 }
60
61 PlaylistSource::PlaylistSource (Session& s, const XMLNode& node)
62         : Source (s, DataType::AUDIO, "toBeRenamed")
63 {
64         /* PlaylistSources are never writable, renameable, removable or destructive */
65         _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
66
67
68         if (set_state (node, Stateful::loading_state_version)) {
69                 throw failed_constructor ();
70         }
71 }
72
73 PlaylistSource::~PlaylistSource ()
74 {
75 }
76
77 void
78 PlaylistSource::add_state (XMLNode& node)
79 {
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());
84
85         node.add_child_nocopy (_playlist->get_state());
86 }
87
88 int
89 PlaylistSource::set_state (const XMLNode& node, int /*version*/)
90 {
91         /* check that we have a playlist ID */
92
93         XMLProperty const * prop = node.property (X_("playlist"));
94
95         if (!prop) {
96                 error << _("No playlist ID in PlaylistSource XML!") << endmsg;
97                 throw failed_constructor ();
98         }
99
100         /* create playlist from child node */
101
102         XMLNodeList nlist;
103         XMLNodeConstIterator niter;
104
105         nlist = node.children();
106
107         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
108                 if ((*niter)->name() == "Playlist") {
109                         _playlist = PlaylistFactory::create (_session, **niter, true, false);
110                         break;
111                 }
112         }
113
114         if (!_playlist) {
115                 error << _("Could not construct playlist for PlaylistSource from session data!") << endmsg;
116                 throw failed_constructor ();
117         }
118
119         /* other properties */
120
121         std::string name;
122         if (!node.get_property (X_("name"), name)) {
123                 throw failed_constructor ();
124         }
125
126         set_name (name);
127
128         if (!node.get_property (X_("offset"), _playlist_offset)) {
129                 throw failed_constructor ();
130         }
131
132         if (!node.get_property (X_("length"), _playlist_length)) {
133                 throw failed_constructor ();
134         }
135
136         /* XXX not quite sure why we set our ID back to the "original" one
137            here. october 2011, paul
138         */
139
140         std::string str;
141         if (!node.get_property (X_("original"), str)) {
142                 throw failed_constructor ();
143         }
144
145         set_id (str);
146
147         _level = _playlist->max_source_level () + 1;
148
149         return 0;
150 }