Quit when requested from the menu
[ladish.git] / gui / PatchageModule.hpp
blob59df0e65fadd23990459cbd23f8d88830045d1c0
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
7 **************************************************************************
8 * This file implements the canvas module class
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #ifndef PATCHAGE_PATCHAGEMODULE_HPP
28 #define PATCHAGE_PATCHAGEMODULE_HPP
30 #include "common.h"
31 #include "PatchageCanvas.hpp"
33 class PatchageModule
35 public:
36 PatchageModule(Patchage* app, const std::string& name, ModuleType type, double x=0, double y=0);
38 virtual ~PatchageModule();
40 bool
41 identify(const std::string& name, ModuleType type)
43 return _name == name && (_type == type || _type == InputOutput);
45 #if 0
46 void create_menu() {
47 _menu = new Gtk::Menu();
48 Gtk::Menu::MenuList& items = _menu->items();
49 if (_type == InputOutput) {
50 items.push_back(Gtk::Menu_Helpers::MenuElem("Split",
51 sigc::mem_fun(this, &PatchageModule::split)));
52 } else {
53 items.push_back(Gtk::Menu_Helpers::MenuElem("Join",
54 sigc::mem_fun(this, &PatchageModule::join)));
56 items.push_back(Gtk::Menu_Helpers::MenuElem("Disconnect All",
57 sigc::mem_fun(this, &PatchageModule::menu_disconnect_all)));
59 void move(double dx, double dy) {
60 FlowCanvas::Module::move(dx, dy);
61 store_location();
64 void load_location() {
65 boost::shared_ptr<Canvas> canvas = _canvas.lock();
66 if (!canvas)
67 return;
69 Coord loc;
71 if (_app->state_manager()->get_module_location(_name, _type, loc))
72 move_to(loc.x, loc.y);
73 else
74 move_to((canvas->width()/2) - 100 + rand() % 400,
75 (canvas->height()/2) - 100 + rand() % 400);
78 virtual void store_location() {
79 Coord loc(property_x().get_value(), property_y().get_value());
80 _app->state_manager()->set_module_location(_name, _type, loc);
83 void split() {
84 assert(_type == InputOutput);
85 _app->state_manager()->set_module_split(_name, true);
86 _app->refresh();
89 void join() {
90 assert(_type != InputOutput);
91 _app->state_manager()->set_module_split(_name, false);
92 _app->refresh();
95 virtual void show_dialog() {}
97 virtual void menu_disconnect_all() {
98 for (PortVector::iterator p = _ports.begin(); p != _ports.end(); ++p)
99 (*p)->disconnect_all();
101 #endif
103 protected:
104 Patchage* _app;
105 ModuleType _type;
106 std::string _name;
110 #endif // PATCHAGE_PATCHAGEMODULE_HPP