From f1c1d019c14ddb184078c79cd5d6a0631a644acd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 17 Feb 2015 03:41:45 +0000 Subject: Fix display of labels when port is created without. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5581 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/GraphCanvas.cpp | 19 ++++++++++++++++- src/gui/GraphPortModule.cpp | 5 ++--- src/gui/GraphPortModule.hpp | 3 +-- src/gui/NodeModule.cpp | 3 +-- src/gui/Port.cpp | 52 ++++++++++++++++++++++++++++++--------------- src/gui/Port.hpp | 4 +++- 6 files changed, 60 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/gui/GraphCanvas.cpp b/src/gui/GraphCanvas.cpp index b06b47b1..1fe665e7 100644 --- a/src/gui/GraphCanvas.cpp +++ b/src/gui/GraphCanvas.cpp @@ -256,13 +256,30 @@ void GraphCanvas::show_human_names(bool b) { _human_names = b; + _app.world()->conf().set("human-names", _app.forge().make(b)); + for_each_node(show_module_human_names, &b); } +static void +ensure_port_labels(GanvNode* node, void* data) +{ + if (GANV_IS_MODULE(node)) { + Ganv::Module* module = Glib::wrap(GANV_MODULE(node)); + for (Ganv::Port* p : *module) { + Ingen::GUI::Port* port = dynamic_cast(p); + if (port) { + port->ensure_label(); + } + } + } +} + void GraphCanvas::show_port_names(bool b) { ganv_canvas_set_direction(gobj(), b ? GANV_DIRECTION_RIGHT : GANV_DIRECTION_DOWN); + for_each_node(ensure_port_labels, &b); } void @@ -314,7 +331,7 @@ GraphCanvas::remove_block(SPtr bm) void GraphCanvas::add_port(SPtr pm) { - GraphPortModule* view = GraphPortModule::create(*this, pm, _human_names); + GraphPortModule* view = GraphPortModule::create(*this, pm); _views.insert(std::make_pair(pm, view)); view->show(); } diff --git a/src/gui/GraphPortModule.cpp b/src/gui/GraphPortModule.cpp index dc781a35..99704eaa 100644 --- a/src/gui/GraphPortModule.cpp +++ b/src/gui/GraphPortModule.cpp @@ -66,11 +66,10 @@ GraphPortModule::GraphPortModule(GraphCanvas& canvas, GraphPortModule* GraphPortModule::create(GraphCanvas& canvas, - SPtr model, - bool human) + SPtr model) { GraphPortModule* ret = new GraphPortModule(canvas, model); - Port* port = Port::create(canvas.app(), *ret, model, human, true); + Port* port = Port::create(canvas.app(), *ret, model, true); ret->set_port(port); if (model->is_numeric()) { diff --git a/src/gui/GraphPortModule.hpp b/src/gui/GraphPortModule.hpp index 5cffa7bc..8dcee1c9 100644 --- a/src/gui/GraphPortModule.hpp +++ b/src/gui/GraphPortModule.hpp @@ -48,8 +48,7 @@ class GraphPortModule : public Ganv::Module public: static GraphPortModule* create( GraphCanvas& canvas, - SPtr model, - bool human); + SPtr model); App& app() const; diff --git a/src/gui/NodeModule.cpp b/src/gui/NodeModule.cpp index 40303ad7..c03618cf 100644 --- a/src/gui/NodeModule.cpp +++ b/src/gui/NodeModule.cpp @@ -268,8 +268,7 @@ NodeModule::rename() void NodeModule::new_port_view(SPtr port) { - Port::create(app(), *this, port, - app().world()->conf().option("human-names").get()); + Port::create(app(), *this, port); port->signal_value_changed().connect( sigc::bind<0>(sigc::mem_fun(this, &NodeModule::port_value_changed), diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp index f15d067c..07e654db 100644 --- a/src/gui/Port.cpp +++ b/src/gui/Port.cpp @@ -44,25 +44,9 @@ Port* Port::create(App& app, Ganv::Module& module, SPtr pm, - bool human_name, bool flip) { - Glib::ustring label; - if (app.world()->conf().option("port-labels").get()) { - if (human_name) { - const Atom& name = pm->get_property(app.uris().lv2_name); - if (name.type() == app.forge().String) { - label = name.ptr(); - } else { - const SPtr parent(dynamic_ptr_cast(pm->parent())); - if (parent && parent->plugin_model()) - label = parent->plugin_model()->port_human_name(pm->index()); - } - } else { - label = pm->path().symbol(); - } - } - return new Port(app, module, pm, label, flip); + return new Port(app, module, pm, port_label(app, pm), flip); } /** @param flip Make an input port appear as an output port, and vice versa. @@ -118,6 +102,40 @@ Port::~Port() _app.activity_port_destroyed(this); } +std::string +Port::port_label(App& app, SPtr pm) +{ + if (!pm) { + return ""; + } + + std::string label; + if (app.world()->conf().option("port-labels").get()) { + if (app.world()->conf().option("human-names").get()) { + const Atom& name = pm->get_property(app.uris().lv2_name); + if (name.type() == app.forge().String) { + label = name.ptr(); + } else { + const SPtr parent( + dynamic_ptr_cast(pm->parent())); + if (parent && parent->plugin_model()) + label = parent->plugin_model()->port_human_name(pm->index()); + } + } else { + label = pm->path().symbol(); + } + } + return label; +} + +void +Port::ensure_label() +{ + if (!get_label()) { + set_label(port_label(_app, _port_model.lock()).c_str()); + } +} + void Port::update_metadata() { diff --git a/src/gui/Port.hpp b/src/gui/Port.hpp index e547fcc4..44703fb4 100644 --- a/src/gui/Port.hpp +++ b/src/gui/Port.hpp @@ -50,7 +50,6 @@ public: App& app, Ganv::Module& module, SPtr pm, - bool human_name, bool flip = false); ~Port(); @@ -59,6 +58,7 @@ public: bool show_menu(GdkEventButton* ev); void update_metadata(); + void ensure_label(); void value_changed(const Atom& value); void activity(const Atom& value); @@ -73,6 +73,8 @@ private: const std::string& name, bool flip = false); + static std::string port_label(App& app, SPtr pm); + Gtk::Menu* build_enum_menu(); Gtk::Menu* build_uri_menu(); GraphBox* get_graph_box() const; -- cgit v1.2.1