From 071e36b69b5bcc203f70179580c8bed924b7305b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 12 Jun 2012 21:46:22 +0000 Subject: Add "expose" (to parent) operation for ports. Partially implments #39. Export all the way to root has a few issues, I am considering this functionality good enough for now. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4496 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/PortMenu.cpp | 76 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 21 deletions(-) (limited to 'src/gui/PortMenu.cpp') diff --git a/src/gui/PortMenu.cpp b/src/gui/PortMenu.cpp index 0e3e215c..2785db77 100644 --- a/src/gui/PortMenu.cpp +++ b/src/gui/PortMenu.cpp @@ -35,21 +35,22 @@ namespace GUI { PortMenu::PortMenu(BaseObjectType* cobject, const Glib::RefPtr& xml) : ObjectMenu(cobject, xml) - , _patch_port(NULL) + , _is_patch_port(false) { xml->get_widget("object_menu", _port_menu); xml->get_widget("port_set_min_menuitem", _set_min_menuitem); xml->get_widget("port_set_max_menuitem", _set_max_menuitem); xml->get_widget("port_reset_range_menuitem", _reset_range_menuitem); + xml->get_widget("port_expose_menuitem", _expose_menuitem); } void -PortMenu::init(App& app, SharedPtr port, bool patch_port) +PortMenu::init(App& app, SharedPtr port, bool is_patch_port) { const URIs& uris = app.uris(); ObjectMenu::init(app, port); - _patch_port = patch_port; + _is_patch_port = is_patch_port; _set_min_menuitem->signal_activate().connect( sigc::mem_fun(this, &PortMenu::on_menu_set_min)); @@ -60,38 +61,36 @@ PortMenu::init(App& app, SharedPtr port, bool patch_port) _reset_range_menuitem->signal_activate().connect( sigc::mem_fun(this, &PortMenu::on_menu_reset_range)); - if (!PtrCast(port->parent())) { + _expose_menuitem->signal_activate().connect( + sigc::mem_fun(this, &PortMenu::on_menu_expose)); + + const bool is_control = app.can_control(port.get()) && port->is_numeric(); + const bool is_on_patch = PtrCast(port->parent()); + + if (!_is_patch_port) { _polyphonic_menuitem->set_sensitive(false); _rename_menuitem->set_sensitive(false); _destroy_menuitem->set_sensitive(false); } - if (port->is_a(uris.atom_AtomPort)) + if (port->is_a(uris.atom_AtomPort)) { _polyphonic_menuitem->hide(); - - const bool is_control = app.can_control(port.get()) - && port->is_numeric(); - - _reset_range_menuitem->set_visible(true); - _set_max_menuitem->set_visible(true); - _set_min_menuitem->set_visible(true); - - _reset_range_menuitem->set_sensitive(is_control); - _set_max_menuitem->set_sensitive(is_control); - _set_min_menuitem->set_sensitive(is_control); - - if (is_control) { - _learn_menuitem->show(); - _unlearn_menuitem->show(); } + _reset_range_menuitem->set_visible(is_control && !is_on_patch); + _set_max_menuitem->set_visible(is_control); + _set_min_menuitem->set_visible(is_control); + _expose_menuitem->set_visible(!is_on_patch); + _learn_menuitem->set_visible(is_control); + _unlearn_menuitem->set_visible(is_control); + _enable_signal = true; } void PortMenu::on_menu_disconnect() { - if (_patch_port) { + if (_is_patch_port) { _app->interface()->disconnect_all( _object->parent()->path(), _object->path()); } else { @@ -141,6 +140,41 @@ PortMenu::on_menu_reset_range() _app->forge().make(max)); } +void +PortMenu::on_menu_expose() +{ + const URIs& uris = _app->uris(); + SharedPtr port = PtrCast(_object); + SharedPtr node = PtrCast(_object->parent()); + + std::string label = node->label() + " " + node->port_label(port); + Raul::Path path = node->path().str() + "_" + _object->symbol().c_str(); + Raul::Atom symbol = _app->forge().alloc(path.symbol()); + Raul::Atom name = _app->forge().alloc(label.c_str()); + + Shared::ResourceImpl r(*_object.get()); + r.remove_property(uris.lv2_index, uris.wildcard); + r.set_property(uris.lv2_symbol, symbol); + r.set_property(uris.lv2_name, name); + + // TODO: Pretty kludgey coordinates + const float node_x = node->get_property(uris.ingen_canvasX).get_float(); + const float node_y = node->get_property(uris.ingen_canvasY).get_float(); + r.set_property(uris.ingen_canvasX, + _app->forge().make(node_x + ((label.length() * 16.0f) + * (port->is_input() ? -1 : 1)))); + r.set_property(uris.ingen_canvasY, + _app->forge().make(node_y + port->index() * 32.0f)); + + _app->interface()->put(path, r.properties()); + + if (port->is_input()) { + _app->interface()->connect(path, _object->path()); + } else { + _app->interface()->connect(_object->path(), path); + } +} + } // namespace GUI } // namespace Ingen -- cgit v1.2.1