summaryrefslogtreecommitdiffstats
path: root/src/server/events/Copy.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-02-08 07:02:59 +0000
committerDavid Robillard <d@drobilla.net>2015-02-08 07:02:59 +0000
commit0f9c8151d5b42b243a499bb31a1e1f0b2e8c5f6f (patch)
tree1ed4df4df4c3f160120544d92c681f1b4519e1aa /src/server/events/Copy.cpp
parent8733afb7ae9a04f46ac6318667182da16eca9fe5 (diff)
downloadingen-0f9c8151d5b42b243a499bb31a1e1f0b2e8c5f6f.tar.gz
ingen-0f9c8151d5b42b243a499bb31a1e1f0b2e8c5f6f.tar.bz2
ingen-0f9c8151d5b42b243a499bb31a1e1f0b2e8c5f6f.zip
Server-side copy paste with LV2 state support.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5541 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server/events/Copy.cpp')
-rw-r--r--src/server/events/Copy.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/server/events/Copy.cpp b/src/server/events/Copy.cpp
new file mode 100644
index 00000000..67ab4747
--- /dev/null
+++ b/src/server/events/Copy.cpp
@@ -0,0 +1,130 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2015 David Robillard <http://drobilla.net/>
+
+ Ingen is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or any later version.
+
+ Ingen 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 Affero General Public License for details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with Ingen. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "ingen/Store.hpp"
+#include "raul/Path.hpp"
+
+#include "BlockImpl.hpp"
+#include "Broadcaster.hpp"
+#include "Driver.hpp"
+#include "Engine.hpp"
+#include "EnginePort.hpp"
+#include "GraphImpl.hpp"
+#include "events/Copy.hpp"
+
+namespace Ingen {
+namespace Server {
+namespace Events {
+
+Copy::Copy(Engine& engine,
+ SPtr<Interface> client,
+ int32_t id,
+ SampleCount timestamp,
+ const Raul::Path& old_path,
+ const Raul::URI& new_uri)
+ : Event(engine, client, id, timestamp)
+ , _old_path(old_path)
+ , _new_uri(new_uri)
+ , _parent(NULL)
+ , _block(NULL)
+ , _compiled_graph(NULL)
+{}
+
+bool
+Copy::pre_process()
+{
+ if (_old_path.empty() ||
+ !Node::uri_is_path(_new_uri) ||
+ _new_uri == Node::root_uri()) {
+ return Event::pre_process_done(Status::BAD_REQUEST);
+ }
+
+ // Only support a single source for now
+ const Raul::Path new_path = Node::uri_to_path(_new_uri);
+ if (!Raul::Symbol::is_valid(new_path.symbol())) {
+ return Event::pre_process_done(Status::BAD_REQUEST);
+ }
+
+ std::unique_lock<std::mutex> lock(_engine.store()->mutex());
+
+ // Find the old node
+ const Store::iterator i = _engine.store()->find(_old_path);
+ if (i == _engine.store()->end()) {
+ return Event::pre_process_done(Status::NOT_FOUND, _old_path);
+ }
+
+ // Ensure the new node doesn't already exists
+ if (_engine.store()->find(new_path) != _engine.store()->end()) {
+ return Event::pre_process_done(Status::EXISTS, new_path);
+ }
+
+ // Get old node block, or fail (ports not supported for now)
+ BlockImpl* old_block = dynamic_cast<BlockImpl*>(i->second.get());
+ if (!old_block) {
+ return Event::pre_process_done(Status::BAD_OBJECT_TYPE, _old_path);
+ }
+
+ // Find new parent graph
+ const Raul::Path parent_path = new_path.parent();
+ const Store::iterator p = _engine.store()->find(parent_path);
+ if (p == _engine.store()->end()) {
+ return Event::pre_process_done(Status::NOT_FOUND, parent_path);
+ }
+ if (!(_parent = dynamic_cast<GraphImpl*>(p->second.get()))) {
+ return Event::pre_process_done(Status::BAD_OBJECT_TYPE, parent_path);
+ }
+
+ // Create new block
+ if (!(_block = dynamic_cast<BlockImpl*>(
+ old_block->duplicate(_engine, Raul::Symbol(new_path.symbol()), _parent)))) {
+ return Event::pre_process_done(Status::INTERNAL_ERROR);
+ }
+
+ _block->activate(*_engine.buffer_factory());
+
+ // Add block to the store and the graph's pre-processor only block list
+ _parent->add_block(*_block);
+ _engine.store()->add(_block);
+
+ // Compile graph with new block added for insertion in audio thread
+ if (_parent->enabled()) {
+ _compiled_graph = _parent->compile();
+ }
+
+ return Event::pre_process_done(Status::SUCCESS);
+}
+
+void
+Copy::execute(ProcessContext& context)
+{
+ if (_block) {
+ _parent->set_compiled_graph(_compiled_graph);
+ _compiled_graph = NULL; // Graph takes ownership
+ }
+}
+
+void
+Copy::post_process()
+{
+ Broadcaster::Transfer t(*_engine.broadcaster());
+ if (respond() == Status::SUCCESS) {
+ _engine.broadcaster()->copy(_old_path, _new_uri);
+ }
+}
+
+} // namespace Events
+} // namespace Server
+} // namespace Ingen