summaryrefslogtreecommitdiffstats
path: root/src/libs/engine/events/AddNodeEvent.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-06-10 01:52:02 +0000
committerDavid Robillard <d@drobilla.net>2006-06-10 01:52:02 +0000
commit98fe0e7056e6697396249531785d3899f94d79be (patch)
tree233319008d4bfb6c8bdc546bdf4a81b87ecf7f3a /src/libs/engine/events/AddNodeEvent.cpp
parent6c8eaee73b0ea66216744f49b452e22e26fe83e1 (diff)
downloadingen-98fe0e7056e6697396249531785d3899f94d79be.tar.gz
ingen-98fe0e7056e6697396249531785d3899f94d79be.tar.bz2
ingen-98fe0e7056e6697396249531785d3899f94d79be.zip
More juggling
git-svn-id: http://svn.drobilla.net/lad/grauph@15 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine/events/AddNodeEvent.cpp')
-rw-r--r--src/libs/engine/events/AddNodeEvent.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/libs/engine/events/AddNodeEvent.cpp b/src/libs/engine/events/AddNodeEvent.cpp
new file mode 100644
index 00000000..2b31ef4a
--- /dev/null
+++ b/src/libs/engine/events/AddNodeEvent.cpp
@@ -0,0 +1,128 @@
+/* This file is part of Om. Copyright (C) 2006 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "AddNodeEvent.h"
+#include "Responder.h"
+#include "Patch.h"
+#include "Node.h"
+#include "Tree.h"
+#include "Plugin.h"
+#include "Om.h"
+#include "OmApp.h"
+#include "Patch.h"
+#include "NodeFactory.h"
+#include "ClientBroadcaster.h"
+#include "Maid.h"
+#include "util/Path.h"
+#include "ObjectStore.h"
+#include "util/Path.h"
+#include "Port.h"
+
+namespace Om {
+
+
+AddNodeEvent::AddNodeEvent(CountedPtr<Responder> responder, const string& path, Plugin* plugin, bool poly)
+: QueuedEvent(responder),
+ m_path(path),
+ m_plugin(plugin),
+ m_poly(poly),
+ m_patch(NULL),
+ m_node(NULL),
+ m_process_order(NULL),
+ m_node_already_exists(false)
+{
+}
+
+
+AddNodeEvent::~AddNodeEvent()
+{
+ delete m_plugin;
+}
+
+
+void
+AddNodeEvent::pre_process()
+{
+ if (om->object_store()->find(m_path) != NULL) {
+ m_node_already_exists = true;
+ QueuedEvent::pre_process();
+ return;
+ }
+
+ m_patch = om->object_store()->find_patch(m_path.parent());
+
+ if (m_patch != NULL) {
+ if (m_poly)
+ m_node = om->node_factory()->load_plugin(m_plugin, m_path.name(), m_patch->internal_poly(), m_patch);
+ else
+ m_node = om->node_factory()->load_plugin(m_plugin, m_path.name(), 1, m_patch);
+
+ if (m_node != NULL) {
+ m_node->activate();
+
+ // This can be done here because the audio thread doesn't touch the
+ // node tree - just the process order array
+ m_patch->add_node(new ListNode<Node*>(m_node));
+ m_node->add_to_store();
+
+ if (m_patch->process())
+ m_process_order = m_patch->build_process_order();
+ }
+ }
+ QueuedEvent::pre_process();
+}
+
+
+void
+AddNodeEvent::execute(samplecount offset)
+{
+ QueuedEvent::execute(offset);
+
+ if (m_node != NULL) {
+ m_node->add_to_patch();
+
+ if (m_patch->process_order() != NULL)
+ om->maid()->push(m_patch->process_order());
+ m_patch->process_order(m_process_order);
+ }
+}
+
+
+void
+AddNodeEvent::post_process()
+{
+ string msg;
+ if (m_node_already_exists) {
+ msg = string("Could not create node - ").append(m_path);// + " already exists.";
+ m_responder->respond_error(msg);
+ } else if (m_patch == NULL) {
+ msg = "Could not find patch '" + m_path.parent() +"' for add_node.";
+ m_responder->respond_error(msg);
+ } else if (m_node == NULL) {
+ msg = "Unable to load node ";
+ msg.append(m_path).append(" (you're missing the plugin \"").append(
+ m_plugin->lib_name()).append(":").append(m_plugin->plug_label()).append("\")");;
+ m_responder->respond_error(msg);
+ } else {
+ m_responder->respond_ok();
+ //om->client_broadcaster()->send_node_creation_messages(m_node);
+ om->client_broadcaster()->send_node(m_node);
+ }
+}
+
+
+} // namespace Om
+