diff options
author | David Robillard <d@drobilla.net> | 2011-12-03 21:45:57 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-03 21:45:57 +0000 |
commit | 74a3eb19f586e3548f59bb9ff9137703cdc45de8 (patch) | |
tree | 07d9070e88dd46e7b536b7b8aeed2e248ffc00b1 /src | |
parent | 0654b5d4017b2dbd605ea9d7567f220ceeca44e1 (diff) | |
download | patchage-74a3eb19f586e3548f59bb9ff9137703cdc45de8.tar.gz patchage-74a3eb19f586e3548f59bb9ff9137703cdc45de8.tar.bz2 patchage-74a3eb19f586e3548f59bb9ff9137703cdc45de8.zip |
Don't expose canvas data structures.
git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@3775 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/Patchage.cpp | 49 | ||||
-rw-r--r-- | src/PatchageCanvas.cpp | 81 | ||||
-rw-r--r-- | src/PatchageModule.cpp | 12 | ||||
-rw-r--r-- | src/PatchageModule.hpp | 3 | ||||
-rw-r--r-- | src/PatchagePort.hpp | 4 |
5 files changed, 103 insertions, 46 deletions
diff --git a/src/Patchage.cpp b/src/Patchage.cpp index e815891..2c35255 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -412,15 +412,22 @@ Patchage::warning_msg(const std::string& msg) _status_text->scroll_to_mark(buffer->get_insert(), 0); } +static void +load_module_location(FlowCanvasNode* node, void* data) +{ + if (FLOW_CANVAS_IS_MODULE(node)) { + FlowCanvas::Module* cmodule = Glib::wrap(FLOW_CANVAS_MODULE(node)); + PatchageModule* pmodule = dynamic_cast<PatchageModule*>(cmodule); + if (pmodule) { + pmodule->load_location(); + } + } +} + void Patchage::update_state() { - for (FlowCanvas::Canvas::Items::const_iterator i = _canvas->items().begin(); - i != _canvas->items().end(); ++i) { - PatchageModule* module = dynamic_cast<PatchageModule*>(*i); - if (module) - module->load_location(); - } + _canvas->for_each_node(load_module_location, NULL); } /** Update the sensitivity status of menus to reflect the present. @@ -485,6 +492,23 @@ Patchage::show_open_session_dialog() } } +static void +print_edge(FlowCanvasEdge* edge, void* data) +{ + std::ofstream* script = (std::ofstream*)data; + FlowCanvas::Edge* edgemm = Glib::wrap(edge); + + PatchagePort* src = dynamic_cast<PatchagePort*>((edgemm)->get_tail()); + PatchagePort* dst = dynamic_cast<PatchagePort*>((edgemm)->get_head()); + + if (!src || !dst || src->type() == ALSA_MIDI || dst->type() == ALSA_MIDI) { + return; + } + + (*script) << "jack_connect '" << src->full_name() + << "' '" << dst->full_name() << "' &" << endl; +} + void Patchage::save_session(bool close) { @@ -531,18 +555,7 @@ Patchage::save_session(bool close) script << "sleep 3" << endl; script << endl; - for (FlowCanvas::Canvas::Edges::const_iterator c = _canvas->edges().begin(); - c != _canvas->edges().end(); ++c) { - PatchagePort* src = dynamic_cast<PatchagePort*>((*c)->get_tail()); - PatchagePort* dst = dynamic_cast<PatchagePort*>((*c)->get_head()); - - if (!src || !dst || src->type() == ALSA_MIDI || dst->type() == ALSA_MIDI) { - continue; - } - - script << "jack_connect '" << src->full_name() - << "' '" << dst->full_name() << "' &" << endl; - } + _canvas->for_each_edge(print_edge, &script); script.close(); g_chmod(script_path.c_str(), 0740); diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index 907cdba..25483a4 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -121,28 +121,50 @@ PatchageCanvas::remove_port(const PortID& id) delete port; } -void -PatchageCanvas::remove_ports(bool (*pred)(const PatchagePort*)) -{ +struct RemovePortsData { + typedef bool (*Predicate)(const PatchagePort*); + + RemovePortsData(Predicate p) : pred(p) {} + + Predicate pred; std::set<PatchageModule*> empty; - for (Items::const_iterator i = items().begin(); i != items().end(); ++i) { - PatchageModule* module = dynamic_cast<PatchageModule*>(*i); - if (!module) - continue; - - FlowCanvas::Module::Ports ports = module->ports(); // copy - for (FlowCanvas::Module::Ports::iterator p = ports.begin(); - p != ports.end(); ++p) { - if (pred(dynamic_cast<PatchagePort*>(*p))) { - delete *p; - } - } +}; + +static void +remove_ports_matching(FlowCanvasNode* node, void* cdata) +{ + if (!FLOW_CANVAS_IS_MODULE(node)) { + return; + } + + FlowCanvas::Module* cmodule = Glib::wrap(FLOW_CANVAS_MODULE(node)); + PatchageModule* pmodule = dynamic_cast<PatchageModule*>(cmodule); + if (!pmodule) { + return; + } - if (module->num_ports() == 0) { - empty.insert(module); + RemovePortsData* data = (RemovePortsData*)cdata; + + FlowCanvas::Module::Ports ports = pmodule->ports(); // copy + for (FlowCanvas::Module::Ports::iterator p = ports.begin(); + p != ports.end(); ++p) { + if (data->pred(dynamic_cast<PatchagePort*>(*p))) { + delete *p; } } + if (pmodule->num_ports() == 0) { + data->empty.insert(pmodule); + } +} + +void +PatchageCanvas::remove_ports(bool (*pred)(const PatchagePort*)) +{ + RemovePortsData data(pred); + + for_each_node(remove_ports_matching, &data); + for (PortIndex::iterator i = _port_index.begin(); i != _port_index.end();) { PortIndex::iterator next = i; @@ -153,8 +175,8 @@ PatchageCanvas::remove_ports(bool (*pred)(const PatchagePort*)) i = next; } - for (std::set<PatchageModule*>::iterator i = empty.begin(); - i != empty.end(); ++i) { + for (std::set<PatchageModule*>::iterator i = data.empty.begin(); + i != data.empty.end(); ++i) { delete *i; } } @@ -274,19 +296,24 @@ PatchageCanvas::on_connection_event(FlowCanvas::Edge* c, GdkEvent* ev) return false; } +static void +disconnect_edge(FlowCanvasEdge* edge, void* data) +{ + PatchageCanvas* canvas = (PatchageCanvas*)data; + FlowCanvas::Edge* edgemm = Glib::wrap(edge); + canvas->disconnect(edgemm->get_tail(), edgemm->get_head()); +} + bool PatchageCanvas::on_event(GdkEvent* ev) { if (ev->type == GDK_KEY_PRESS && ev->key.keyval == GDK_Delete) { - SelectedEdges cs = selected_edges(); + for_each_selected_edge(disconnect_edge, this); clear_selection(); - - for (Edges::const_iterator i = cs.begin(); i != cs.end(); ++i) { - disconnect((*i)->get_tail(), (*i)->get_head()); - } + return true; } - return false; + return Canvas::on_event(ev); } bool @@ -315,8 +342,8 @@ PatchageCanvas::remove_item(FlowCanvas::Node* i) return ret; // Remove module from cache - for (ModuleIndex::iterator i = _module_index.find(module->name()); - i != _module_index.end() && i->first == module->name(); ++i) { + for (ModuleIndex::iterator i = _module_index.find(module->get_label()); + i != _module_index.end() && i->first == module->get_label(); ++i) { if (i->second == module) { _module_index.erase(i); return true; diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp index fd7d0ef..85538cd 100644 --- a/src/PatchageModule.cpp +++ b/src/PatchageModule.cpp @@ -148,3 +148,15 @@ PatchageModule::menu_disconnect_all() for (Ports::iterator p = _ports.begin(); p != _ports.end(); ++p) (*p)->disconnect_all(); } + +PatchagePort* +PatchageModule::get_port(const std::string& name) +{ + for (Ports::const_iterator p = _ports.begin(); p != _ports.end(); ++p) { + if ((*p)->get_label() == name) { + return dynamic_cast<PatchagePort*>(*p); + } + } + + return NULL; +} diff --git a/src/PatchageModule.hpp b/src/PatchageModule.hpp index 7b8c02d..56c7980 100644 --- a/src/PatchageModule.hpp +++ b/src/PatchageModule.hpp @@ -27,6 +27,7 @@ #include "StateManager.hpp" class Patchage; +class PatchagePort; class PatchageModule : public FlowCanvas::Module { @@ -40,6 +41,8 @@ public: bool show_menu(GdkEventButton* ev); void update_menu(); + PatchagePort* get_port(const std::string& name); + void load_location(); void menu_disconnect_all(); void show_dialog() {} diff --git a/src/PatchagePort.hpp b/src/PatchagePort.hpp index 693091a..e2e6679 100644 --- a/src/PatchagePort.hpp +++ b/src/PatchagePort.hpp @@ -49,7 +49,9 @@ public: virtual ~PatchagePort() {} /** Returns the full name of this port, as "modulename:portname" */ - std::string full_name() const { return _module->name() + ":" + _name; } + std::string full_name() const { + return std::string(_module->get_label()) + ":" + get_label(); + } bool on_click(GdkEventButton* ev) { if (ev->button != 3) { |