summaryrefslogtreecommitdiffstats
path: root/src/libs/engine/events/AddPortEvent.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-06-19 18:25:21 +0000
committerDavid Robillard <d@drobilla.net>2006-06-19 18:25:21 +0000
commitf260589c35d4bfdac6add58dd92c2394d143813a (patch)
tree9db27a88621836d46f96ff1afadd10e4a028c862 /src/libs/engine/events/AddPortEvent.cpp
parentd65ce9b2402eb287caf45f216b6ac806b99aaf4d (diff)
downloadingen-f260589c35d4bfdac6add58dd92c2394d143813a.tar.gz
ingen-f260589c35d4bfdac6add58dd92c2394d143813a.tar.bz2
ingen-f260589c35d4bfdac6add58dd92c2394d143813a.zip
Added AddPortEvent
git-svn-id: http://svn.drobilla.net/lad/grauph@65 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine/events/AddPortEvent.cpp')
-rw-r--r--src/libs/engine/events/AddPortEvent.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/libs/engine/events/AddPortEvent.cpp b/src/libs/engine/events/AddPortEvent.cpp
new file mode 100644
index 00000000..0318c5c0
--- /dev/null
+++ b/src/libs/engine/events/AddPortEvent.cpp
@@ -0,0 +1,119 @@
+/* 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 "AddPortEvent.h"
+#include "Responder.h"
+#include "Patch.h"
+#include "Tree.h"
+#include "Plugin.h"
+#include "Om.h"
+#include "OmApp.h"
+#include "Patch.h"
+#include "Maid.h"
+#include "util/Path.h"
+#include "ObjectStore.h"
+#include "ClientBroadcaster.h"
+#include "util/Path.h"
+#include "Port.h"
+#include "AudioDriver.h"
+#include "List.h"
+
+namespace Om {
+
+
+AddPortEvent::AddPortEvent(CountedPtr<Responder> responder, const string& path, const string& type, bool is_output)
+: QueuedEvent(responder),
+ _path(path),
+ _type(type),
+ _is_output(is_output),
+ _data_type(DataType::UNKNOWN),
+ _patch(NULL),
+ _port(NULL),
+ _succeeded(true)
+{
+ string type_str;
+ if (type == "CONTROL" || type == "AUDIO")
+ _data_type = DataType::FLOAT;
+ else if (type == "MIDI")
+ _data_type = DataType::MIDI;
+}
+
+
+AddPortEvent::~AddPortEvent()
+{
+}
+
+
+void
+AddPortEvent::pre_process()
+{
+ if (om->object_store()->find(_path) != NULL) {
+ QueuedEvent::pre_process();
+ return;
+ }
+
+ _patch = om->object_store()->find_patch(_path.parent());
+
+ if (_patch != NULL) {
+ assert(_patch->path() == _path.parent());
+
+ size_t buffer_size = 1;
+ if (_type == "AUDIO" || _type == "MIDI")
+ buffer_size = om->audio_driver()->buffer_size();
+
+ _port = _patch->create_port(_path.name(), _data_type, buffer_size, _is_output);
+ if (_port) {
+ if (_is_output)
+ _patch->add_output(new ListNode<Port*>(_port));
+ else
+ _patch->add_input(new ListNode<Port*>(_port));
+ _ports_array = new Array<Port*>(_patch->num_ports() + 1, _patch->external_ports());
+ _ports_array->at(_patch->num_ports()) = _port;
+ om->object_store()->add(_port);
+ }
+ }
+ QueuedEvent::pre_process();
+}
+
+
+void
+AddPortEvent::execute(samplecount offset)
+{
+ QueuedEvent::execute(offset);
+
+ if (_port) {
+ om->maid()->push(_patch->external_ports());
+ //_patch->add_port(_port);
+ _patch->external_ports(_ports_array);
+ }
+}
+
+
+void
+AddPortEvent::post_process()
+{
+ if (!_succeeded) {
+ const string msg = string("Could not create port - ").append(_path);// + " already exists.";
+ m_responder->respond_error(msg);
+ } else {
+ m_responder->respond_ok();
+ om->client_broadcaster()->send_port(_port);
+ }
+}
+
+
+} // namespace Om
+