A few cleanups. Also make port matrix notice when routes or processors change.
authorCarl Hetherington <carl@carlh.net>
Tue, 27 Jan 2009 17:37:07 +0000 (17:37 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 27 Jan 2009 17:37:07 +0000 (17:37 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@4447 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/port_matrix.cc
gtk2_ardour/port_matrix.h
gtk2_ardour/port_matrix_column_labels.cc
gtk2_ardour/port_matrix_column_labels.h
gtk2_ardour/port_matrix_row_labels.cc
gtk2_ardour/port_matrix_types.h

index fccc7076944d0705181ebd23dc18f0c9af1ee04e..c080b3365d7e4ee250b0227b8334acaae9b8bfcf 100644 (file)
@@ -23,6 +23,8 @@
 #include <gtkmm/label.h>
 #include "ardour/bundle.h"
 #include "ardour/types.h"
+#include "ardour/session.h"
+#include "ardour/route.h"
 #include "port_matrix.h"
 #include "i18n.h"
 
@@ -65,6 +67,9 @@ PortMatrix::PortMatrix (ARDOUR::Session& session, ARDOUR::DataType type, bool of
        _vscroll.signal_value_changed().connect (sigc::mem_fun (*this, &PortMatrix::vscroll_changed));
        setup_scrollbars ();
 
+       _session.RouteAdded.connect (sigc::hide (sigc::mem_fun (*this, &PortMatrix::routes_changed)));
+       routes_changed ();
+
        /* XXX hard-coded initial size suggestion */
        set_size_request (400, 200);
        show_all ();
@@ -77,6 +82,23 @@ PortMatrix::~PortMatrix ()
        }
 }
 
+void
+PortMatrix::routes_changed ()
+{
+       for (std::vector<sigc::connection>::iterator i = _route_connections.begin(); i != _route_connections.end(); ++i) {
+               i->disconnect ();
+       }
+
+       boost::shared_ptr<ARDOUR::Session::RouteList> routes = _session.get_routes ();
+       for (ARDOUR::Session::RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
+               _route_connections.push_back (
+                       (*i)->processors_changed.connect (sigc::mem_fun (*this, &PortMatrix::setup))
+                       );
+       }
+
+       setup ();
+}
+
 void
 PortMatrix::setup ()
 {
index 85a273265eec651e1a919840939a6ea2a91e3907..425e3915c4e0e9cc8974f011d8bf5b65942b1130 100644 (file)
@@ -121,6 +121,7 @@ private:
 
        void hscroll_changed ();
        void vscroll_changed ();
+       void routes_changed ();
 
        ARDOUR::Session& _session;
        /// true to offer inputs, otherwise false
@@ -132,6 +133,7 @@ private:
        Gtk::HScrollbar _hscroll;
        Gtk::VScrollbar _vscroll;
        std::list<PortGroupUI*> _port_group_uis;
+       std::vector<sigc::connection> _route_connections;
 };
 
 #endif
index bd6a14e6fa5a5d2afc97ebc21bed312a7907daac..d99cb92d86322488b69cd658c6acd4709246ea2b 100644 (file)
@@ -123,7 +123,7 @@ PortMatrixColumnLabels::render (cairo_t* cr)
        double y = 0;
        
        if (_location == TOP) {
-               x = (_height - _highest_group_name - 2 * name_pad()) / tan (angle());
+               x = slanted_height() / tan (angle());
                y = _highest_group_name + name_pad();
        } else {
                x = 0;
@@ -175,22 +175,21 @@ PortMatrixColumnLabels::render (cairo_t* cr)
                set_source_rgb (cr, colour);
 
                double const w = (*i)->nchannels() * column_width();
-               double const ph = _height - _highest_group_name - 2 * name_pad();
 
                double x_ = x;
                
                if (_location == TOP) {
                        y = _height;
                } else if (_location == BOTTOM) {
-                       y = ph;
+                       y = slanted_height();
                }
 
                double y_ = y;
                cairo_move_to (cr, x_, y_);
                x_ += w;
                cairo_line_to (cr, x_, y_);
-               x_ += ph / tan (angle ());
-               y_ -= ph;
+               x_ += slanted_height() / tan (angle ());
+               y_ -= slanted_height();
                cairo_line_to (cr, x_, y_);
                x_ -= w;
                cairo_line_to (cr, x_, y_);
@@ -216,7 +215,7 @@ PortMatrixColumnLabels::render (cairo_t* cr)
                        cairo_move_to (
                                cr,
                                x + basic_text_x_pos (0),
-                               ph - name_pad() * sin (angle())
+                               slanted_height() - name_pad() * sin (angle())
                                );
                }
                        
@@ -285,21 +284,19 @@ PortMatrixColumnLabels::draw_extra (cairo_t* cr)
                        _body->mouseover().column
                        );
        }
-
 }
 
 void
-PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double x, double y, PortMatrixBundleChannel const &bc)
+PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double xoff, double yoff, PortMatrixBundleChannel const &bc)
 {
        double const lc = _longest_channel_name + name_pad();
        double const w = column_width();
-       double const ph = _height - _highest_group_name - 2 * name_pad();
 
        if (_location == BOTTOM) {
 
-               double x_ = x + ph / tan (angle()) + w;
+               double x_ = xoff + slanted_height() / tan (angle()) + w;
                double const ix = x_;
-               double y_ = y;
+               double y_ = yoff;
                cairo_move_to (cr, x_, y_);
                x_ -= w;
                cairo_line_to (cr, x_, y_);
@@ -309,12 +306,12 @@ PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double
                x_ += w * pow (sin (angle()), 2);
                y_ += w * sin (angle()) * cos (angle());
                cairo_line_to (cr, x_, y_);
-               cairo_line_to (cr, ix, y);
+               cairo_line_to (cr, ix, yoff);
                
        } else if (_location == TOP) {
                
-               double x_ = x;
-               double y_ = y + _height;
+               double x_ = xoff;
+               double y_ = yoff + _height;
                cairo_move_to (cr, x_, y_);
                x_ += w;
                cairo_line_to (cr, x_, y_);
@@ -324,7 +321,7 @@ PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double
                x_ -= column_width() * pow (sin (angle()), 2);
                y_ -= column_width() * sin (angle()) * cos (angle());
                cairo_line_to (cr, x_, y_);
-               cairo_line_to (cr, x, y + _height);
+               cairo_line_to (cr, xoff, yoff + _height);
                
        }
        
@@ -340,8 +337,8 @@ PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double
 
                cairo_move_to (
                        cr,
-                       x + basic_text_x_pos(bc.channel),
-                       y + _height - name_pad() * sin (angle())
+                       xoff + basic_text_x_pos(bc.channel),
+                       yoff + _height - name_pad() * sin (angle())
                        );
                
        } else if (_location == BOTTOM) {
@@ -349,8 +346,8 @@ PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double
                double const rl = 3 * name_pad() + _longest_bundle_name;
                cairo_move_to (
                        cr,
-                       x + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
-                       y + ph - rl * sin (angle())
+                       xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
+                       yoff + slanted_height() - rl * sin (angle())
                        );
        }
        
@@ -368,17 +365,7 @@ PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double
 double
 PortMatrixColumnLabels::channel_x (PortMatrixBundleChannel const &bc) const
 {
-       double x = 0;
-
-       ARDOUR::BundleList::const_iterator i = _body->column_ports().bundles().begin();
-       while (i != _body->column_ports().bundles().end() && *i != bc.bundle) {
-               x += column_width() * (*i)->nchannels();
-               ++i;
-       }
-
-       x += column_width() * bc.channel;
-
-       return x;
+       return bc.nchannels (_body->column_ports().bundles()) * column_width();
 }
 
 void
@@ -400,9 +387,7 @@ PortMatrixColumnLabels::queue_draw_for (PortMatrixNode const& n)
                        
                } else if (_location == BOTTOM) {
                        
-                       double const ph = _height - _highest_group_name - 2 * name_pad();
-                       double const w = column_width() + lc * cos (angle());
-                       double const x_ = x + ph / tan (angle()) - lc * cos (angle());
+                       double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
                        
                        _body->queue_draw_area (
                                component_to_parent_x (x_),
index 213b760a25a9751eff422420b14f1c519610eea3..9021ec55e38b75a2b9551f1b5be73ee18ce43657 100644 (file)
@@ -57,6 +57,10 @@ private:
        double channel_x (PortMatrixBundleChannel const &) const;
        void queue_draw_for (PortMatrixNode const &);
 
+       double slanted_height () const {
+               return _height - _highest_group_name - 2 * name_pad();
+       }
+
        std::vector<boost::shared_ptr<ARDOUR::Bundle> > _bundles;
        double _longest_bundle_name;
        double _longest_channel_name;
index 278ae8e003a4b1694a1482d31430c38fdff06e2f..b938f22a21d72f20f8f32f9bbbe727c9b0f50409 100644 (file)
@@ -187,7 +187,7 @@ PortMatrixRowLabels::render (cairo_t* cr)
        y = 0;
        for (ARDOUR::BundleList::const_iterator i = r.begin(); i != r.end(); ++i) {
                for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
-                       render_port_name (cr, get_a_bundle_colour (i - r.begin()), port_name_x(), y, PortMatrixBundleChannel (*i, j));
+                       render_port_name (cr, get_a_bundle_colour (i - r.begin()), 0, y, PortMatrixBundleChannel (*i, j));
                        y += row_height();
                }
        }
@@ -316,11 +316,11 @@ PortMatrixRowLabels::port_name_x () const
 
 void
 PortMatrixRowLabels::render_port_name (
-       cairo_t* cr, Gdk::Color colour, double x, double y, PortMatrixBundleChannel const& bc
+       cairo_t* cr, Gdk::Color colour, double xoff, double yoff, PortMatrixBundleChannel const& bc
        )
 {
        set_source_rgb (cr, colour);
-       cairo_rectangle (cr, x, y, _longest_port_name + name_pad() * 2, row_height());
+       cairo_rectangle (cr, port_name_x() + xoff, yoff, _longest_port_name + name_pad() * 2, row_height());
        cairo_fill_preserve (cr);
        set_source_rgb (cr, background_colour());
        cairo_set_line_width (cr, label_border_width ());
@@ -331,24 +331,14 @@ PortMatrixRowLabels::render_port_name (
        double const off = (row_height() - ext.height) / 2;
        
        set_source_rgb (cr, text_colour());
-       cairo_move_to (cr, x + name_pad(), y + name_pad() + off);
+       cairo_move_to (cr, port_name_x() + xoff + name_pad(), yoff + name_pad() + off);
        cairo_show_text (cr, bc.bundle->channel_name(bc.channel).c_str());
 }
 
 double
 PortMatrixRowLabels::channel_y (PortMatrixBundleChannel const& bc) const
 {
-       double y = 0;
-
-       ARDOUR::BundleList::const_iterator i = _body->row_ports().bundles().begin();
-       while (i != _body->row_ports().bundles().end() && *i != bc.bundle) {
-               y += row_height() * (*i)->nchannels();
-               ++i;
-       }
-
-       y += row_height() * bc.channel;
-
-       return y;
+       return bc.nchannels (_body->row_ports().bundles()) * row_height();
 }
 
 void
@@ -380,7 +370,7 @@ PortMatrixRowLabels::draw_extra (cairo_t* cr)
                render_port_name (
                        cr,
                        mouseover_port_colour (),
-                       component_to_parent_x (port_name_x()),
+                       component_to_parent_x (0),
                        component_to_parent_y (channel_y (_body->mouseover().row)),
                        _body->mouseover().row
                        );
index 66dcf619b7d87da055c8f32473a150ca65cfbd18..16fb440ace04087438803d76fba3bcc958988af5 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef __ardour_gtk_port_matrix_types_h__
 #define __ardour_gtk_port_matrix_types_h__
 
+#include "ardour/bundle.h"
+
 struct PortMatrixBundleChannel {
        PortMatrixBundleChannel () : channel (0) {}
        PortMatrixBundleChannel (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c)
@@ -31,6 +33,17 @@ struct PortMatrixBundleChannel {
        bool operator!= (PortMatrixBundleChannel const& other) const {
                return bundle != other.bundle || channel != other.channel;
        }
+
+       uint32_t nchannels (ARDOUR::BundleList const& bl) const {
+               uint32_t n = 0;
+               ARDOUR::BundleList::const_iterator i = bl.begin();
+               while (i != bl.end() && *i != bundle) {
+                       n += (*i)->nchannels ();
+                       ++i;
+               }
+               n += channel;
+               return n;
+       }
        
        boost::shared_ptr<ARDOUR::Bundle> bundle;
        uint32_t channel;