summaryrefslogtreecommitdiffstats
path: root/src/libs/engine/events/CreateNodeEvent.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-10-01 00:13:02 +0000
committerDavid Robillard <d@drobilla.net>2007-10-01 00:13:02 +0000
commit8ebd59309b153e7337f2e6668b7e2cb4301cc34a (patch)
tree0a6c73fdbf8f67b7cd6e528af39b136224f3abac /src/libs/engine/events/CreateNodeEvent.cpp
parent8c633f6d1be4ad24ec6597bed151c0123bd7f11f (diff)
downloadingen-8ebd59309b153e7337f2e6668b7e2cb4301cc34a.tar.gz
ingen-8ebd59309b153e7337f2e6668b7e2cb4301cc34a.tar.bz2
ingen-8ebd59309b153e7337f2e6668b7e2cb4301cc34a.zip
Merge NoteOnEvent and NoteOffEvent.
Consistent naming for object creation events. git-svn-id: http://svn.drobilla.net/lad/ingen@792 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine/events/CreateNodeEvent.cpp')
-rw-r--r--src/libs/engine/events/CreateNodeEvent.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/src/libs/engine/events/CreateNodeEvent.cpp b/src/libs/engine/events/CreateNodeEvent.cpp
new file mode 100644
index 00000000..65296de6
--- /dev/null
+++ b/src/libs/engine/events/CreateNodeEvent.cpp
@@ -0,0 +1,145 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Ingen 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.
+ *
+ * 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 General Public License for 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <raul/Maid.hpp>
+#include <raul/Path.hpp>
+#include <raul/Path.hpp>
+#include "CreateNodeEvent.hpp"
+#include "Responder.hpp"
+#include "Patch.hpp"
+#include "Node.hpp"
+#include "Tree.hpp"
+#include "Plugin.hpp"
+#include "Engine.hpp"
+#include "Patch.hpp"
+#include "NodeFactory.hpp"
+#include "ClientBroadcaster.hpp"
+#include "ObjectStore.hpp"
+#include "Port.hpp"
+
+namespace Ingen {
+
+
+CreateNodeEvent::CreateNodeEvent(Engine& engine, SharedPtr<Responder> responder, SampleCount timestamp, const string& path,
+ const string& plugin_uri, bool poly)
+: QueuedEvent(engine, responder, timestamp),
+ _path(path),
+ _plugin_uri(plugin_uri),
+ _poly(poly),
+ _patch(NULL),
+ _node(NULL),
+ _compiled_patch(NULL),
+ _node_already_exists(false)
+{
+}
+
+
+/** DEPRECATED: Construct from type, library name, and plugin label.
+ *
+ * Do not use.
+ */
+CreateNodeEvent::CreateNodeEvent(Engine& engine, SharedPtr<Responder> responder, SampleCount timestamp, const string& path,
+ const string& plugin_type, const string& plugin_lib, const string& plugin_label, bool poly)
+: QueuedEvent(engine, responder, timestamp),
+ _path(path),
+ _plugin_type(plugin_type),
+ _plugin_lib(plugin_lib),
+ _plugin_label(plugin_label),
+ _poly(poly),
+ _patch(NULL),
+ _node(NULL),
+ _compiled_patch(NULL),
+ _node_already_exists(false)
+{
+}
+
+
+void
+CreateNodeEvent::pre_process()
+{
+ if (_engine.object_store()->find_object(_path) != NULL) {
+ _node_already_exists = true;
+ QueuedEvent::pre_process();
+ return;
+ }
+
+ _patch = _engine.object_store()->find_patch(_path.parent());
+
+ const Plugin* plugin = (_plugin_uri != "")
+ ? _engine.node_factory()->plugin(_plugin_uri)
+ : _engine.node_factory()->plugin(_plugin_type, _plugin_lib, _plugin_label);
+
+ if (_patch && plugin) {
+
+ _node = _engine.node_factory()->load_plugin(plugin, _path.name(), _poly, _patch);
+
+ if (_node != NULL) {
+ _node->activate();
+
+ // This can be done here because the audio thread doesn't touch the
+ // node tree - just the process order array
+ _patch->add_node(new Raul::ListNode<Node*>(_node));
+ //_node->add_to_store(_engine.object_store());
+ _engine.object_store()->add(_node);
+
+ // FIXME: not really necessary to build process order since it's not connected,
+ // just append to the list
+ if (_patch->enabled())
+ _compiled_patch = _patch->compile();
+ }
+ }
+ QueuedEvent::pre_process();
+}
+
+
+void
+CreateNodeEvent::execute(ProcessContext& context)
+{
+ QueuedEvent::execute(context);
+
+ if (_node != NULL) {
+ if (_patch->compiled_patch() != NULL)
+ _engine.maid()->push(_patch->compiled_patch());
+ _patch->compiled_patch(_compiled_patch);
+ }
+}
+
+
+void
+CreateNodeEvent::post_process()
+{
+ string msg;
+ if (_node_already_exists) {
+ msg = string("Could not create node - ").append(_path);// + " already exists.";
+ _responder->respond_error(msg);
+ } else if (_patch == NULL) {
+ msg = "Could not find patch '" + _path.parent() +"' for add_node.";
+ _responder->respond_error(msg);
+ } else if (_node == NULL) {
+ msg = "Unable to load node ";
+ msg.append(_path).append(" (you're missing the plugin \"").append(
+ _plugin_uri);
+ _responder->respond_error(msg);
+ } else {
+ _responder->respond_ok();
+ _engine.broadcaster()->send_node(_node, true); // yes, send ports
+ }
+}
+
+
+} // namespace Ingen
+