summaryrefslogtreecommitdiffstats
path: root/src/PatchageModule.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-15 05:43:22 +0000
committerDavid Robillard <d@drobilla.net>2010-12-15 05:43:22 +0000
commit8edc1165f245d1131dcbeacb20db57722a74f110 (patch)
tree747cffd0c72f1025c618437d6f765fa198c13e1e /src/PatchageModule.cpp
parent9e04ed83e757fc860b069ebb09c52484d751adc5 (diff)
downloadpatchage-8edc1165f245d1131dcbeacb20db57722a74f110.tar.gz
patchage-8edc1165f245d1131dcbeacb20db57722a74f110.tar.bz2
patchage-8edc1165f245d1131dcbeacb20db57722a74f110.zip
Add file missing from last commit.
Mnemonics for module menu. git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@2701 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/PatchageModule.cpp')
-rw-r--r--src/PatchageModule.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp
new file mode 100644
index 0000000..416c2b6
--- /dev/null
+++ b/src/PatchageModule.cpp
@@ -0,0 +1,98 @@
+/* This file is part of Patchage.
+ * Copyright (C) 2010 David Robillard <http://drobilla.net>
+ *
+ * Patchage 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.
+ *
+ * Patchage 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 "Patchage.hpp"
+#include "PatchageCanvas.hpp"
+#include "PatchageModule.hpp"
+#include "PatchagePort.hpp"
+
+PatchageModule::PatchageModule(
+ Patchage* app, const std::string& name, ModuleType type, double x, double y)
+ : Module(app->canvas(), name, x, y)
+ , _app(app)
+ , _type(type)
+{
+}
+
+PatchageModule::~PatchageModule()
+{
+ delete _menu;
+ _menu = NULL;
+}
+
+void
+PatchageModule::create_menu()
+{
+ _menu = new Gtk::Menu();
+ Gtk::Menu::MenuList& items = _menu->items();
+ if (_type == InputOutput) {
+ items.push_back(
+ Gtk::Menu_Helpers::MenuElem("_Split", sigc::mem_fun(this, &PatchageModule::split)));
+ } else {
+ items.push_back(
+ Gtk::Menu_Helpers::MenuElem("_Join", sigc::mem_fun(this, &PatchageModule::join)));
+ }
+ items.push_back(
+ Gtk::Menu_Helpers::MenuElem("_Disconnect All",
+ sigc::mem_fun(this, &PatchageModule::menu_disconnect_all)));
+}
+
+void
+PatchageModule::load_location()
+{
+ boost::shared_ptr<Canvas> canvas = _canvas.lock();
+ if (!canvas)
+ return;
+
+ Coord loc;
+
+ if (_app->state_manager()->get_module_location(_name, _type, loc))
+ move_to(loc.x, loc.y);
+ else
+ move_to((canvas->width()/2) - 100 + rand() % 400,
+ (canvas->height()/2) - 100 + rand() % 400);
+}
+
+void
+PatchageModule::store_location()
+{
+ Coord loc(property_x().get_value(), property_y().get_value());
+ _app->state_manager()->set_module_location(_name, _type, loc);
+}
+
+void
+PatchageModule::split()
+{
+ assert(_type == InputOutput);
+ _app->state_manager()->set_module_split(_name, true);
+ _app->refresh();
+}
+
+void
+PatchageModule::join()
+{
+ assert(_type != InputOutput);
+ _app->state_manager()->set_module_split(_name, false);
+ _app->refresh();
+}
+
+void
+PatchageModule::menu_disconnect_all()
+{
+ for (PortVector::iterator p = _ports.begin(); p != _ports.end(); ++p)
+ (*p)->disconnect_all();
+}