summaryrefslogtreecommitdiffstats
path: root/src/clients/gtk/Controller.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-06-09 15:07:31 +0000
committerDavid Robillard <d@drobilla.net>2006-06-09 15:07:31 +0000
commitacbda29f838280ba98cf9e9e539e9d8a6e8fc6ad (patch)
treee31b37a2456e6d1e564c9a7146c88be259d338b0 /src/clients/gtk/Controller.cpp
downloadingen-acbda29f838280ba98cf9e9e539e9d8a6e8fc6ad.tar.gz
ingen-acbda29f838280ba98cf9e9e539e9d8a6e8fc6ad.tar.bz2
ingen-acbda29f838280ba98cf9e9e539e9d8a6e8fc6ad.zip
Added Om aka Graph aka god knows what
git-svn-id: http://svn.drobilla.net/lad/grauph@9 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/clients/gtk/Controller.cpp')
-rw-r--r--src/clients/gtk/Controller.cpp173
1 files changed, 173 insertions, 0 deletions
diff --git a/src/clients/gtk/Controller.cpp b/src/clients/gtk/Controller.cpp
new file mode 100644
index 00000000..05ebe84a
--- /dev/null
+++ b/src/clients/gtk/Controller.cpp
@@ -0,0 +1,173 @@
+/* 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 "PatchModel.h"
+#include "PatchController.h"
+#include "ControlInterface.h"
+#include "OSCModelEngineInterface.h"
+#include "OSCListener.h"
+//#include "GtkClientInterface.h"
+#include "PatchLibrarian.h"
+#include "Controller.h"
+#include "Loader.h"
+#include "interface/ClientKey.h"
+
+namespace OmGtk {
+
+
+Controller::Controller(const string& engine_url)
+: OSCModelEngineInterface(engine_url),
+ m_patch_librarian(new PatchLibrarian(this)),
+ m_loader(new Loader(m_patch_librarian))
+{
+ m_loader->launch();
+}
+
+
+Controller::~Controller()
+{
+ if (is_attached()) {
+ unregister_client(ClientKey()); // FIXME
+ detach();
+ }
+
+ delete m_loader;
+ delete m_patch_librarian;
+}
+
+
+/** "Attach" to the Om engine.
+ * See documentation OSCModelEngineInterface::attach.
+ */
+void
+Controller::attach()
+{
+ OSCModelEngineInterface::attach(false);
+}
+
+/*
+void
+Controller::register_client_and_wait()
+{
+// int id = get_next_request_id();
+// set_wait_response_id(id);
+ OSCModelEngineInterface::register_client();
+// wait_for_response();
+ cout << "[Controller] Registered with engine. maybe. fixme." << endl;
+}
+*/
+void Controller::set_engine_url(const string& url) { _engine_url = url; }
+
+void
+Controller::create_node_from_model(const NodeModel* nm)
+{
+ //push_added_node(nm);
+ OSCModelEngineInterface::create_node_from_model(nm);
+ char temp_buf[16];
+ snprintf(temp_buf, 16, "%f", nm->x());
+ set_metadata(nm->path(), "module-x", temp_buf);
+ snprintf(temp_buf, 16, "%f", nm->y());
+ set_metadata(nm->path(), "module-y", temp_buf);
+}
+
+void
+Controller::create_patch_from_model(const PatchModel* pm)
+{
+ //push_added_patch(pm);
+
+ //int id = get_next_request_id();
+ //set_wait_response_id(id);
+ create_patch_from_model(pm);
+ if (pm->parent() != NULL) {
+ // wait_for_response();
+ char temp_buf[16];
+ snprintf(temp_buf, 16, "%f", pm->x());
+ set_metadata(pm->path(), "module-x", temp_buf);
+ snprintf(temp_buf, 16, "%f", pm->y());
+ set_metadata(pm->path(), "module-y", temp_buf);
+ }
+ enable_patch(pm->path());
+}
+
+
+void
+Controller::set_patch_path(const string& path)
+{
+ m_patch_librarian->path(path);
+}
+
+
+/** Load patch in a seperate thread.
+ * This will return immediately and the patch will be loaded in the background.
+ * FIXME: merge parameter makes no sense, always true */
+void
+Controller::load_patch(PatchModel* model, bool wait, bool merge)
+{
+ //push_added_patch(model);
+ m_loader->load_patch(model, wait, merge);
+}
+
+
+/** Load patch in a seperate thread.
+ * This will return immediately and the patch will be saved in the background. */
+void
+Controller::save_patch(PatchModel* model, const string& filename, bool recursive)
+{
+ m_loader->save_patch(model, filename, recursive);
+}
+
+
+#if 0
+/** Returns the added node with the given path and removes it from the cache.
+ */
+NodeModel*
+Controller::yank_added_node(const string& path)
+{
+ NodeModel* nm = NULL;
+
+ for (list<NodeModel*>::iterator i = m_added_nodes.begin(); i != m_added_nodes.end(); ++i) {
+ if ((*i)->path() == path) {
+ nm = *i;
+ m_added_nodes.erase(i);
+ break;
+ }
+ }
+
+ return nm;
+}
+
+
+/** Returns the added patch with the given path and removes it from the cache.
+ */
+PatchModel*
+Controller::yank_added_patch(const string& path)
+{
+ PatchModel* pm = NULL;
+
+ for (list<PatchModel*>::iterator i = m_added_patches.begin(); i != m_added_patches.end(); ++i) {
+ if ((*i)->path() == path) {
+ pm = *i;
+ m_added_patches.erase(i);
+ break;
+ }
+ }
+
+ return pm;
+}
+#endif
+
+} // namespace OmGtk
+