X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fport_matrix_body.cc;h=66ed3ecc3e2c0cea55212f770ea8a05b45004c6e;hb=abf1f286d49482ade939da7e49863a3d63048b42;hp=41faaa31eff432bdbe63b57cff65d4e8ab3880b2;hpb=be55dcbce3b26d9af7562cedb75dee25eab66623;p=ardour.git diff --git a/gtk2_ardour/port_matrix_body.cc b/gtk2_ardour/port_matrix_body.cc index 41faaa31ef..66ed3ecc3e 100644 --- a/gtk2_ardour/port_matrix_body.cc +++ b/gtk2_ardour/port_matrix_body.cc @@ -20,12 +20,16 @@ #include #include "ardour/bundle.h" #include "ardour/types.h" + +#include "gui_thread.h" #include "port_matrix_body.h" #include "port_matrix.h" #include "port_matrix_column_labels.h" #include "port_matrix_row_labels.h" #include "port_matrix_grid.h" +#include "pbd/i18n.h" + using namespace std; PortMatrixBody::PortMatrixBody (PortMatrix* p) @@ -34,10 +38,12 @@ PortMatrixBody::PortMatrixBody (PortMatrix* p) _alloc_height (0), _xoffset (0), _yoffset (0), + _column_labels_border_x (0), + _column_labels_height (0), _ignore_component_size_changed (false) { _column_labels = new PortMatrixColumnLabels (p, this); - _row_labels = new PortMatrixRowLabels (p, this); + _row_labels = new PortMatrixRowLabels (p, this, *_column_labels); _grid = new PortMatrixGrid (p, this); _components.push_back (_column_labels); @@ -58,7 +64,10 @@ PortMatrixBody::~PortMatrixBody () bool PortMatrixBody::on_expose_event (GdkEventExpose* event) { - if (_matrix->visible_columns()->bundles().empty() || _matrix->visible_rows()->bundles().empty()) { + if ( + _matrix->visible_columns() == 0 || _matrix->visible_rows() == 0 || + _matrix->visible_columns()->bundles().empty() || _matrix->visible_rows()->bundles().empty() + ) { /* nothing to connect */ @@ -68,15 +77,19 @@ PortMatrixBody::on_expose_event (GdkEventExpose* event) cairo_rectangle (cr, 0, 0, _alloc_width, _alloc_height); cairo_fill (cr); - stringstream t; - t << _("There are no ") << (_matrix->type() == ARDOUR::DataType::AUDIO ? _("audio") : _("MIDI")) << _(" ports to connect."); + string t; + if (_matrix->type() == ARDOUR::DataType::NIL) { + t = _("There are no ports to connect."); + } else { + t = string_compose (_("There are no %1 ports to connect."), _matrix->type().to_i18n_string()); + } cairo_text_extents_t ext; - cairo_text_extents (cr, t.str().c_str(), &ext); + cairo_text_extents (cr, t.c_str(), &ext); cairo_set_source_rgb (cr, 1, 1, 1); cairo_move_to (cr, (_alloc_width - ext.width) / 2, (_alloc_height + ext.height) / 2); - cairo_show_text (cr, t.str().c_str ()); + cairo_show_text (cr, t.c_str ()); cairo_destroy (cr); @@ -99,7 +112,7 @@ PortMatrixBody::on_expose_event (GdkEventExpose* event) r.intersect ((*i)->parent_rectangle(), intersects); if (intersects) { - + gdk_draw_drawable ( get_window()->gobj(), get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(), @@ -171,7 +184,7 @@ PortMatrixBody::compute_rectangles () { /* full sizes of components */ pair const col = _column_labels->dimensions (); - uint32_t col_overhang = _column_labels->overhang (); + uint32_t const col_overhang = _column_labels->overhang (); pair const row = _row_labels->dimensions (); pair const grid = _grid->dimensions (); @@ -182,6 +195,7 @@ PortMatrixBody::compute_rectangles () if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) { col_rect.set_x (0); + _column_labels_border_x = col_overhang; col_rect.set_y (0); grid_rect.set_x (0); @@ -209,26 +223,30 @@ PortMatrixBody::compute_rectangles () } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) { col_rect.set_height (min (_alloc_height, col.second)); + row_rect.set_height (std::min (_alloc_height - col_rect.get_height(), row.second)); row_rect.set_x (0); - row_rect.set_y (0); + row_rect.set_y (_alloc_height - row_rect.get_height() - col_rect.get_height()); row_rect.set_width (min (_alloc_width, row.first)); - row_rect.set_height (std::min (_alloc_height - col_rect.get_height(), row.second)); grid_rect.set_x (row_rect.get_width()); - grid_rect.set_y (0); + grid_rect.set_y (_alloc_height - row_rect.get_height() - col_rect.get_height()); grid_rect.set_width (std::min (_alloc_width - row_rect.get_width(), grid.first)); grid_rect.set_height (row_rect.get_height ()); col_rect.set_width (grid_rect.get_width () + col_overhang); col_rect.set_x (row_rect.get_width() + grid_rect.get_width() - col_rect.get_width()); - col_rect.set_y (row_rect.get_height()); - + _column_labels_border_x = col_rect.get_x () >= 0 ? col_rect.get_x () : 0; + col_rect.set_y (_alloc_height - col_rect.get_height()); } + _column_labels_height = col_rect.get_height (); + _row_labels->set_parent_rectangle (row_rect); _column_labels->set_parent_rectangle (col_rect); _grid->set_parent_rectangle (grid_rect); + + DimensionsChanged (); /* EMIT SIGNAL */ } void @@ -236,27 +254,24 @@ PortMatrixBody::setup () { /* Discard any old connections to bundles */ - for (list::iterator i = _bundle_connections.begin(); i != _bundle_connections.end(); ++i) { - i->disconnect (); - } - _bundle_connections.clear (); + _bundle_connections.drop_connections (); /* Connect to bundles so that we find out when their names change */ - PortGroup::BundleList r = _matrix->rows()->bundles (); - for (PortGroup::BundleList::iterator i = r.begin(); i != r.end(); ++i) { + if (_matrix->visible_rows()) { + PortGroup::BundleList r = _matrix->visible_rows()->bundles (); + for (PortGroup::BundleList::iterator i = r.begin(); i != r.end(); ++i) { - _bundle_connections.push_back ( - i->bundle->Changed.connect (sigc::hide (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_row_labels))) - ); + (*i)->bundle->Changed.connect (_bundle_connections, invalidator (*this), boost::bind (&PortMatrixBody::rebuild_and_draw_row_labels, this), gui_context()); + } } - PortGroup::BundleList c = _matrix->columns()->bundles (); - for (PortGroup::BundleList::iterator i = c.begin(); i != c.end(); ++i) { - _bundle_connections.push_back ( - i->bundle->Changed.connect (sigc::hide (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_column_labels))) - ); + if (_matrix->visible_columns()) { + PortGroup::BundleList c = _matrix->visible_columns()->bundles (); + for (PortGroup::BundleList::iterator i = c.begin(); i != c.end(); ++i) { + (*i)->bundle->Changed.connect (_bundle_connections, invalidator (*this), boost::bind (&PortMatrixBody::rebuild_and_draw_column_labels, this), gui_context()); + } } for (list::iterator i = _components.begin(); i != _components.end(); ++i) { @@ -264,7 +279,7 @@ PortMatrixBody::setup () } set_mouseover (PortMatrixNode ()); - + _ignore_component_size_changed = true; compute_rectangles (); _ignore_component_size_changed = false; @@ -295,6 +310,7 @@ PortMatrixBody::alloc_scroll_height () return _grid->parent_rectangle().get_height(); } +/** Set x offset (for scrolling) */ void PortMatrixBody::set_xoffset (uint32_t xo) { @@ -302,6 +318,7 @@ PortMatrixBody::set_xoffset (uint32_t xo) queue_draw (); } +/** Set y offset (for scrolling) */ void PortMatrixBody::set_yoffset (uint32_t yo) { @@ -317,7 +334,7 @@ PortMatrixBody::on_button_press_event (GdkEventButton* ev) (*i)->button_press ( (*i)->parent_to_component_x (ev->x), (*i)->parent_to_component_y (ev->y), - ev->button, ev->time, ev->state + ev ); } } @@ -333,12 +350,12 @@ PortMatrixBody::on_button_release_event (GdkEventButton* ev) (*i)->button_release ( (*i)->parent_to_component_x (ev->x), (*i)->parent_to_component_y (ev->y), - ev->button, ev->time, ev->state + ev ); } else { (*i)->button_release ( -1, -1, - ev->button, ev->time, ev->state + ev ); } } @@ -381,7 +398,7 @@ bool PortMatrixBody::on_motion_notify_event (GdkEventMotion* ev) { bool done = false; - + for (list::iterator i = _components.begin(); i != _components.end(); ++i) { if (Gdk::Region ((*i)->parent_rectangle()).point_in (ev->x, ev->y)) { (*i)->motion ( @@ -392,7 +409,7 @@ PortMatrixBody::on_motion_notify_event (GdkEventMotion* ev) done = true; } } - + if (!done) { set_mouseover (PortMatrixNode ()); @@ -429,7 +446,7 @@ PortMatrixBody::set_mouseover (list const & n) list old = _mouseover; _mouseover = n; - + for (list::iterator i = _components.begin(); i != _components.end(); ++i) { (*i)->mouseover_changed (old); } @@ -441,7 +458,7 @@ PortMatrixBody::highlight_associated_channels (int dim, ARDOUR::BundleChannel h) ARDOUR::BundleChannel bc[2]; bc[dim] = h; - if (!bc[dim].bundle) { + if (!PortMatrix::bundle_with_channels (bc[dim].bundle)) { return; } @@ -454,9 +471,19 @@ PortMatrixBody::highlight_associated_channels (int dim, ARDOUR::BundleChannel h) PortGroup::BundleList const b = _matrix->visible_ports(1 - dim)->bundles (); for (PortGroup::BundleList::const_iterator i = b.begin(); i != b.end(); ++i) { - for (uint32_t j = 0; j < i->bundle->nchannels(); ++j) { - bc[1 - dim] = ARDOUR::BundleChannel (i->bundle, j); - if (_matrix->get_state (bc) == PortMatrixNode::ASSOCIATED) { + for (uint32_t j = 0; j < (*i)->bundle->nchannels().n_total(); ++j) { + + if (!_matrix->should_show ((*i)->bundle->channel_type(j))) { + continue; + } + + bc[1 - dim] = ARDOUR::BundleChannel ((*i)->bundle, j); + + PortMatrixNode n; + n.row = bc[_matrix->row_index()]; + n.column = bc[_matrix->column_index()]; + + if (_matrix->get_association(n) != PortMatrixNode::NOT_ASSOCIATED) { if (dim == _matrix->column_index()) { _row_labels->add_channel_highlight (bc[1 - dim]); } else { @@ -480,7 +507,7 @@ PortMatrixBody::component_size_changed () if (_ignore_component_size_changed) { return; } - + compute_rectangles (); _matrix->setup_scrollbars (); } @@ -494,3 +521,16 @@ PortMatrixBody::max_size () const return make_pair (std::max (row.first, _column_labels->overhang()) + grid.first, col.second + grid.second); } + +/** @return x position at which the column labels meet the border of the matrix */ +uint32_t +PortMatrixBody::column_labels_border_x () const +{ + return _column_labels_border_x; +} + +uint32_t +PortMatrixBody::column_labels_height () const +{ + return _column_labels_height; +}