summaryrefslogtreecommitdiffstats
path: root/src/PatchageModule.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-29 18:31:45 +0100
committerDavid Robillard <d@drobilla.net>2020-11-29 18:31:45 +0100
commit98e2535b82ab601081a56c8a22d789d2da25cfd8 (patch)
tree5627e1219725342edd6aba36cd48ba24a256ba1c /src/PatchageModule.cpp
parent178d1cbe1dfc9e7b66c36cbb75590e1cee419174 (diff)
downloadpatchage-98e2535b82ab601081a56c8a22d789d2da25cfd8.tar.gz
patchage-98e2535b82ab601081a56c8a22d789d2da25cfd8.tar.bz2
patchage-98e2535b82ab601081a56c8a22d789d2da25cfd8.zip
Use more reasonable class names
Diffstat (limited to 'src/PatchageModule.cpp')
-rw-r--r--src/PatchageModule.cpp166
1 files changed, 0 insertions, 166 deletions
diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp
deleted file mode 100644
index 1931b3b..0000000
--- a/src/PatchageModule.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-/* This file is part of Patchage.
- * Copyright 2010-2020 David Robillard <d@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 3 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 Patchage. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "PatchageModule.hpp"
-
-#include "Patchage.hpp"
-#include "PatchageCanvas.hpp"
-#include "PatchagePort.hpp"
-#include "SignalDirection.hpp"
-
-namespace patchage {
-
-PatchageModule::PatchageModule(Patchage* app,
- const std::string& name,
- SignalDirection type,
- ClientID id,
- double x,
- double y)
- : Module(*app->canvas(), name, x, y)
- , _app(app)
- , _menu(nullptr)
- , _name(name)
- , _type(type)
- , _id(std::move(id))
-{
- signal_event().connect(sigc::mem_fun(this, &PatchageModule::on_event));
-
- signal_moved().connect(
- sigc::mem_fun(this, &PatchageModule::store_location));
-
- // Set as source by default, turned off if input ports added
- set_is_source(true);
-}
-
-PatchageModule::~PatchageModule()
-{
- _app->canvas()->remove_module(this);
- delete _menu;
- _menu = nullptr;
-}
-
-void
-PatchageModule::update_menu()
-{
- if (!_menu) {
- return;
- }
-
- if (_type == SignalDirection::duplex) {
- bool has_in = false;
- bool has_out = false;
- for (const auto* p : *this) {
- if (p->is_input()) {
- has_in = true;
- } else {
- has_out = true;
- }
-
- if (has_in && has_out) {
- _menu->items()[0].show(); // Show "Split" menu item
- return;
- }
- }
- _menu->items()[0].hide(); // Hide "Split" menu item
- }
-}
-
-bool
-PatchageModule::show_menu(GdkEventButton* ev)
-{
- _menu = new Gtk::Menu();
- Gtk::Menu::MenuList& items = _menu->items();
- if (_type == SignalDirection::duplex) {
- items.push_back(Gtk::Menu_Helpers::MenuElem(
- "_Split", sigc::mem_fun(this, &PatchageModule::split)));
- update_menu();
- } 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)));
-
- _menu->popup(ev->button, ev->time);
- return true;
-}
-
-bool
-PatchageModule::on_event(GdkEvent* ev)
-{
- if (ev->type == GDK_BUTTON_PRESS && ev->button.button == 3) {
- return show_menu(&ev->button);
- }
- return false;
-}
-
-void
-PatchageModule::load_location()
-{
- Coord loc;
-
- if (_app->conf().get_module_location(_name, _type, loc)) {
- move_to(loc.x, loc.y);
- } else {
- move_to(20 + rand() % 640, 20 + rand() % 480);
- }
-}
-
-void
-PatchageModule::store_location(double x, double y)
-{
- _app->conf().set_module_location(_name, _type, {x, y});
-}
-
-void
-PatchageModule::split()
-{
- assert(_type == SignalDirection::duplex);
- _app->conf().set_module_split(_name, true);
- _app->refresh();
-}
-
-void
-PatchageModule::join()
-{
- assert(_type != SignalDirection::duplex);
- _app->conf().set_module_split(_name, false);
- _app->refresh();
-}
-
-void
-PatchageModule::menu_disconnect_all()
-{
- for (Ganv::Port* p : *this) {
- p->disconnect();
- }
-}
-
-PatchagePort*
-PatchageModule::get_port(const PortID& id)
-{
- for (Ganv::Port* p : *this) {
- auto* pport = dynamic_cast<PatchagePort*>(p);
- if (pport && pport->id() == id) {
- return pport;
- }
- }
-
- return nullptr;
-}
-
-} // namespace patchage