Support for the port matrix working at the bundle level and hiding details of ports.

git-svn-id: svn://localhost/ardour2/branches/3.0@5029 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2009-05-03 14:31:42 +00:00
parent 7e48118bf1
commit 1ae39840b3
19 changed files with 560 additions and 256 deletions

View file

@ -67,17 +67,17 @@ BundleEditorMatrix::set_state (ARDOUR::BundleChannel c[2], bool s)
}
}
PortMatrix::State
PortMatrixNode::State
BundleEditorMatrix::get_state (ARDOUR::BundleChannel c[2]) const
{
ARDOUR::Bundle::PortList const& pl = c[OTHER].bundle->channel_ports (c[OTHER].channel);
for (ARDOUR::Bundle::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) {
if (!c[OURS].bundle->port_attached_to_channel (c[OURS].channel, *i)) {
return NOT_ASSOCIATED;
return PortMatrixNode::NOT_ASSOCIATED;
}
}
return ASSOCIATED;
return PortMatrixNode::ASSOCIATED;
}
void

View file

@ -37,7 +37,7 @@ class BundleEditorMatrix : public PortMatrix
BundleEditorMatrix (ARDOUR::Session &, boost::shared_ptr<ARDOUR::Bundle>);
void set_state (ARDOUR::BundleChannel c[2], bool s);
State get_state (ARDOUR::BundleChannel c[2]) const;
PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const;
void add_channel (boost::shared_ptr<ARDOUR::Bundle>);
bool can_remove_channels (int d) const {
return d == OURS;

View file

@ -71,7 +71,7 @@ GlobalPortMatrix::set_state (ARDOUR::BundleChannel c[2], bool s)
}
}
PortMatrix::State
PortMatrixNode::State
GlobalPortMatrix::get_state (ARDOUR::BundleChannel c[2]) const
{
ARDOUR::Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
@ -79,7 +79,7 @@ GlobalPortMatrix::get_state (ARDOUR::BundleChannel c[2]) const
if (in_ports.empty() || out_ports.empty()) {
/* we're looking at a bundle with no parts associated with this channel,
so nothing to connect */
return UNKNOWN;
return PortMatrixNode::UNKNOWN;
}
for (ARDOUR::Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
@ -90,22 +90,21 @@ GlobalPortMatrix::get_state (ARDOUR::BundleChannel c[2]) const
/* we don't know the state of connections between two non-Ardour ports */
if (!p && !q) {
return UNKNOWN;
return PortMatrixNode::UNKNOWN;
}
if (p && p->connected_to (*j) == false) {
return NOT_ASSOCIATED;
return PortMatrixNode::NOT_ASSOCIATED;
} else if (q && q->connected_to (*i) == false) {
return NOT_ASSOCIATED;
return PortMatrixNode::NOT_ASSOCIATED;
}
}
}
return ASSOCIATED;
return PortMatrixNode::ASSOCIATED;
}
GlobalPortMatrixWindow::GlobalPortMatrixWindow (ARDOUR::Session& s, ARDOUR::DataType t)
: _port_matrix (s, t)
{
@ -125,9 +124,20 @@ GlobalPortMatrixWindow::GlobalPortMatrixWindow (ARDOUR::Session& s, ARDOUR::Data
_rescan_button.signal_clicked().connect (sigc::mem_fun (_port_matrix, &GlobalPortMatrix::setup_all_ports));
buttons_hbox->pack_start (_rescan_button, Gtk::PACK_SHRINK);
_show_ports_button.set_label (_("Show individual ports"));
_show_ports_button.set_active (true);
_show_ports_button.signal_toggled().connect (sigc::mem_fun (*this, &GlobalPortMatrixWindow::show_ports_toggled));
buttons_hbox->pack_start (_show_ports_button, Gtk::PACK_SHRINK);
Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox);
vbox->pack_start (_port_matrix);
vbox->pack_start (*buttons_hbox, Gtk::PACK_SHRINK);
add (*vbox);
show_all ();
}
void
GlobalPortMatrixWindow::show_ports_toggled ()
{
_port_matrix.set_show_only_bundles (!_show_ports_button.get_active());
}

View file

@ -33,7 +33,7 @@ public:
void setup_ports (int);
void set_state (ARDOUR::BundleChannel c[2], bool);
State get_state (ARDOUR::BundleChannel c[2]) const;
PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const;
void add_channel (boost::shared_ptr<ARDOUR::Bundle>) {}
bool can_remove_channels (int d) const {
@ -63,8 +63,11 @@ public:
GlobalPortMatrixWindow (ARDOUR::Session&, ARDOUR::DataType);
private:
void show_ports_toggled ();
GlobalPortMatrix _port_matrix;
Gtk::Button _rescan_button;
Gtk::CheckButton _show_ports_button;
};

View file

@ -112,7 +112,7 @@ IOSelector::set_state (ARDOUR::BundleChannel c[2], bool s)
}
}
PortMatrix::State
PortMatrixNode::State
IOSelector::get_state (ARDOUR::BundleChannel c[2]) const
{
ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel);
@ -121,7 +121,7 @@ IOSelector::get_state (ARDOUR::BundleChannel c[2]) const
if (our_ports.empty() || other_ports.empty()) {
/* we're looking at a bundle with no parts associated with this channel,
so nothing to connect */
return UNKNOWN;
return PortMatrixNode::UNKNOWN;
}
for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
@ -135,12 +135,12 @@ IOSelector::get_state (ARDOUR::BundleChannel c[2]) const
if (!f->connected_to (*j)) {
/* if any one thing is not connected, all bets are off */
return NOT_ASSOCIATED;
return PortMatrixNode::NOT_ASSOCIATED;
}
}
}
return ASSOCIATED;
return PortMatrixNode::ASSOCIATED;
}
uint32_t

View file

@ -33,7 +33,7 @@ class IOSelector : public PortMatrix
IOSelector (ARDOUR::Session&, boost::shared_ptr<ARDOUR::IO>, bool);
void set_state (ARDOUR::BundleChannel c[2], bool);
State get_state (ARDOUR::BundleChannel c[2]) const;
PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const;
void add_channel (boost::shared_ptr<ARDOUR::Bundle>);
bool can_remove_channels (int d) const {

View file

@ -37,7 +37,8 @@
* @param type Port type that we are handling.
*/
PortMatrix::PortMatrix (ARDOUR::Session& session, ARDOUR::DataType type)
: _session (session),
: Gtk::Table (2, 2),
_session (session),
_type (type),
_column_visibility_box_added (false),
_row_visibility_box_added (false),
@ -46,7 +47,8 @@ PortMatrix::PortMatrix (ARDOUR::Session& session, ARDOUR::DataType type)
_arrangement (TOP_TO_RIGHT),
_row_index (0),
_column_index (1),
_min_height_divisor (1)
_min_height_divisor (1),
_show_only_bundles (false)
{
_body = new PortMatrixBody (this);
@ -147,15 +149,14 @@ PortMatrix::setup ()
_scroller_table.remove (*_body);
_scroller_table.remove (_hscroll);
_main_hbox.remove (_scroller_table);
remove (_scroller_table);
if (_row_visibility_box_added) {
_main_hbox.remove (_row_visibility_box);
remove (_row_visibility_box);
}
if (_column_visibility_box_added) {
remove (_column_visibility_box);
}
remove (_main_hbox);
}
if (_column_index == 0) {
@ -190,42 +191,38 @@ PortMatrix::setup ()
_scroller_table.attach (*_body, 0, 1, 1, 2);
_scroller_table.attach (_vscroll, 1, 2, 1, 2, Gtk::SHRINK);
_main_hbox.pack_start (_scroller_table);
attach (_scroller_table, 0, 1, 1, 2, Gtk::FILL | Gtk::EXPAND, Gtk::FILL | Gtk::EXPAND);
if (rows()->size() > 1) {
_main_hbox.pack_start (_row_visibility_box, Gtk::PACK_SHRINK);
attach (_row_visibility_box, 1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
_row_visibility_box_added = true;
} else {
_row_visibility_box_added = false;
}
if (columns()->size() > 1) {
pack_start (_column_visibility_box, Gtk::PACK_SHRINK);
attach (_column_visibility_box, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
_column_visibility_box_added = true;
} else {
_column_visibility_box_added = false;
}
pack_start (_main_hbox);
} else {
_scroller_table.attach (_vscroll, 0, 1, 0, 1, Gtk::SHRINK);
_scroller_table.attach (*_body, 1, 2, 0, 1);
_scroller_table.attach (_hscroll, 1, 2, 1, 2, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
if (rows()->size() > 1) {
_main_hbox.pack_start (_row_visibility_box, Gtk::PACK_SHRINK);
attach (_row_visibility_box, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
_row_visibility_box_added = true;
} else {
_row_visibility_box_added = false;
}
_main_hbox.pack_start (_scroller_table);
pack_start (_main_hbox);
attach (_scroller_table, 1, 2, 0, 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL | Gtk::EXPAND);
if (columns()->size() > 1) {
pack_start (_column_visibility_box, Gtk::PACK_SHRINK);
attach (_column_visibility_box, 1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
_column_visibility_box_added = true;
} else {
_column_visibility_box_added = false;
@ -294,7 +291,7 @@ PortMatrix::disassociate_all ()
ARDOUR::BundleChannel (*k, l)
};
if (get_state (c) == ASSOCIATED) {
if (get_state (c) == PortMatrixNode::ASSOCIATED) {
set_state (c, false);
}
@ -476,7 +473,7 @@ PortMatrix::disassociate_all_on_channel (boost::weak_ptr<ARDOUR::Bundle> bundle,
c[dim] = ARDOUR::BundleChannel (sb, channel);
c[1-dim] = ARDOUR::BundleChannel (*i, j);
if (get_state (c) == ASSOCIATED) {
if (get_state (c) == PortMatrixNode::ASSOCIATED) {
set_state (c, false);
}
}
@ -501,3 +498,12 @@ PortMatrix::setup_all_ports ()
setup_ports (0);
setup_ports (1);
}
void
PortMatrix::set_show_only_bundles (bool s)
{
_show_only_bundles = s;
_body->setup ();
setup_scrollbars ();
queue_draw ();
}

View file

@ -29,6 +29,7 @@
#include <boost/shared_ptr.hpp>
#include "ardour/bundle.h"
#include "port_group.h"
#include "port_matrix_types.h"
/** The `port matrix' UI. This is a widget which lets the user alter
* associations between one set of ports and another. e.g. to connect
@ -36,7 +37,7 @@
*
* It is made up of a body, PortMatrixBody, which is rendered using cairo,
* and some scrollbars and other stuff. All of this is arranged inside the
* VBox that we inherit from.
* Table that we inherit from.
*/
namespace ARDOUR {
@ -45,7 +46,7 @@ namespace ARDOUR {
class PortMatrixBody;
class PortMatrix : public Gtk::VBox
class PortMatrix : public Gtk::Table
{
public:
PortMatrix (ARDOUR::Session&, ARDOUR::DataType);
@ -78,6 +79,12 @@ public:
return _arrangement;
}
bool show_only_bundles () const {
return _show_only_bundles;
}
void set_show_only_bundles (bool);
PortGroupList const * columns () const;
/** @return index into the _ports array for the list which is displayed as columns */
@ -105,16 +112,10 @@ public:
*/
virtual void set_state (ARDOUR::BundleChannel c[2], bool s) = 0;
enum State {
ASSOCIATED, ///< the ports are associaed
NOT_ASSOCIATED, ///< the ports are not associated
UNKNOWN ///< we don't know anything about these two ports' relationship
};
/** @param c Channels; where c[0] is from _ports[0] and c[1] is from _ports[1].
* @return state
*/
virtual State get_state (ARDOUR::BundleChannel c[2]) const = 0;
virtual PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const = 0;
virtual bool list_is_global (int) const = 0;
virtual void add_channel (boost::shared_ptr<ARDOUR::Bundle>) = 0;
@ -161,7 +162,6 @@ private:
PortMatrixBody* _body;
Gtk::HScrollbar _hscroll;
Gtk::VScrollbar _vscroll;
Gtk::HBox _main_hbox;
Gtk::HBox _column_visibility_box;
bool _column_visibility_box_added;
Gtk::Label _column_visibility_label;
@ -177,6 +177,7 @@ private:
int _row_index;
int _column_index;
int _min_height_divisor;
bool _show_only_bundles;
};
#endif

View file

@ -483,7 +483,7 @@ PortMatrixBody::highlight_associated_channels (int dim, uint32_t N)
for (ARDOUR::BundleList::const_iterator i = b.begin(); i != b.end(); ++i) {
for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
bc[1 - dim] = ARDOUR::BundleChannel (*i, j);
if (_matrix->get_state (bc) == PortMatrix::ASSOCIATED) {
if (_matrix->get_state (bc) == PortMatrixNode::ASSOCIATED) {
if (dim == _matrix->column_index()) {
_row_labels->add_channel_highlight (bc[1 - dim]);
} else {

View file

@ -74,8 +74,12 @@ PortMatrixColumnLabels::compute_dimensions ()
}
}
if (_matrix->show_only_bundles()) {
_width += column_width();
} else {
_width += (*i)->nchannels() * column_width();
}
}
_highest_group_name = 0;
for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
@ -93,9 +97,12 @@ PortMatrixColumnLabels::compute_dimensions ()
/* height of the whole thing */
double const parallelogram_height =
(_longest_bundle_name + _longest_channel_name + 4 * name_pad()) * sin (angle())
+ _highest_text * cos (angle());
int a = _longest_bundle_name + 4 * name_pad();
if (!_matrix->show_only_bundles()) {
a += _longest_channel_name;
}
double const parallelogram_height = a * sin (angle()) + _highest_text * cos (angle());
_height = parallelogram_height + _highest_group_name + 2 * name_pad();
@ -139,7 +146,12 @@ PortMatrixColumnLabels::render (cairo_t* cr)
}
/* compute width of this group */
uint32_t w = (*i)->total_channels() * column_width();
uint32_t w = 0;
if (_matrix->show_only_bundles()) {
w = (*i)->bundles().size() * column_width();
} else {
w = (*i)->total_channels() * column_width();
}
/* rectangle */
set_source_rgb (cr, get_a_group_colour (g));
@ -168,65 +180,19 @@ PortMatrixColumnLabels::render (cairo_t* cr)
ARDOUR::BundleList const c = _matrix->columns()->bundles();
for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
Gdk::Color colour = get_a_bundle_colour (i - c.begin ());
set_source_rgb (cr, colour);
render_bundle_name (cr, get_a_bundle_colour (i - c.begin ()), x, 0, *i);
double const w = (*i)->nchannels() * column_width();
double x_ = x;
if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
y = _height;
if (_matrix->show_only_bundles()) {
x += column_width();
} else {
y = slanted_height();
}
double y_ = y;
cairo_move_to (cr, x_, y_);
x_ += w;
cairo_line_to (cr, x_, y_);
x_ += slanted_height() / tan (angle ());
y_ -= slanted_height();
cairo_line_to (cr, x_, y_);
x_ -= w;
cairo_line_to (cr, x_, y_);
cairo_line_to (cr, x, y);
cairo_fill_preserve (cr);
set_source_rgb (cr, background_colour());
cairo_set_line_width (cr, label_border_width());
cairo_stroke (cr);
set_source_rgb (cr, text_colour());
if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
double const rl = 3 * name_pad() + _longest_channel_name;
cairo_move_to (
cr,
x + basic_text_x_pos (0) + rl * cos (angle()),
_height - rl * sin (angle())
);
} else {
cairo_move_to (
cr,
x + basic_text_x_pos (0),
slanted_height() - name_pad() * sin (angle())
);
}
cairo_save (cr);
cairo_rotate (cr, -angle());
cairo_show_text (cr, (*i)->name().c_str());
cairo_restore (cr);
x += (*i)->nchannels () * column_width();
}
}
/* PORT NAMES */
if (!_matrix->show_only_bundles()) {
x = 0;
for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
@ -236,6 +202,7 @@ PortMatrixColumnLabels::render (cairo_t* cr)
x += column_width();
}
}
}
}
double
@ -312,7 +279,78 @@ PortMatrixColumnLabels::port_name_shape (double xoff, double yoff) const
}
void
PortMatrixColumnLabels::render_channel_name (cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc)
PortMatrixColumnLabels::render_bundle_name (
cairo_t* cr, Gdk::Color colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
)
{
set_source_rgb (cr, colour);
double w = 0;
if (_matrix->show_only_bundles()) {
w = column_width ();
} else {
w = b->nchannels() * column_width();
}
double x_ = xoff;
uint32_t y = yoff;
if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
y += _height;
} else {
y += slanted_height();
}
double y_ = y;
cairo_move_to (cr, x_, y_);
x_ += w;
cairo_line_to (cr, x_, y_);
x_ += slanted_height() / tan (angle ());
y_ -= slanted_height();
cairo_line_to (cr, x_, y_);
x_ -= w;
cairo_line_to (cr, x_, y_);
cairo_line_to (cr, xoff, y);
cairo_fill_preserve (cr);
set_source_rgb (cr, background_colour());
cairo_set_line_width (cr, label_border_width());
cairo_stroke (cr);
set_source_rgb (cr, text_colour());
if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
double rl = 0;
if (_matrix->show_only_bundles()) {
rl = name_pad();
} else {
rl = 3 * name_pad() + _longest_channel_name;
}
cairo_move_to (
cr,
xoff + basic_text_x_pos (0) + rl * cos (angle()),
yoff + _height - rl * sin (angle())
);
} else {
cairo_move_to (
cr,
xoff + basic_text_x_pos (0),
yoff + slanted_height() - name_pad() * sin (angle())
);
}
cairo_save (cr);
cairo_rotate (cr, -angle());
cairo_show_text (cr, b->name().c_str());
cairo_restore (cr);
}
void
PortMatrixColumnLabels::render_channel_name (
cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc
)
{
std::vector<std::pair<double, double> > const shape = port_name_shape (xoff, yoff);
@ -366,11 +404,18 @@ PortMatrixColumnLabels::channel_x (ARDOUR::BundleChannel const &bc) const
ARDOUR::BundleList::const_iterator i = _matrix->columns()->bundles().begin();
while (i != _matrix->columns()->bundles().end() && *i != bc.bundle) {
if (_matrix->show_only_bundles()) {
n += 1;
} else {
n += (*i)->nchannels ();
}
++i;
}
if (!_matrix->show_only_bundles()) {
n += bc.channel;
}
return n * column_width();
}
@ -383,11 +428,25 @@ PortMatrixColumnLabels::channel_y (ARDOUR::BundleChannel const &bc) const
void
PortMatrixColumnLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
{
if (bc.bundle) {
if (!bc.bundle) {
return;
}
if (_matrix->show_only_bundles()) {
_body->queue_draw_area (
component_to_parent_x (channel_x (bc)),
component_to_parent_y (0),
column_width() + _height * tan (angle()),
_height
);
} else {
double const x = channel_x (bc);
double const lc = _longest_channel_name + name_pad();
double const h = lc * sin (angle ()) + column_width() * sin (angle()) * cos (angle());
if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
_body->queue_draw_area (

View file

@ -45,6 +45,7 @@ public:
void mouseover_changed (PortMatrixNode const &);
private:
void render_bundle_name (cairo_t *, Gdk::Color, double, double, boost::shared_ptr<ARDOUR::Bundle>);
void render_channel_name (cairo_t *, Gdk::Color, double, double, ARDOUR::BundleChannel const &);
double channel_x (ARDOUR::BundleChannel const &) const;
double channel_y (ARDOUR::BundleChannel const &) const;

View file

@ -42,6 +42,7 @@ public:
virtual void mouseover_changed (PortMatrixNode const &) = 0;
virtual void draw_extra (cairo_t *) = 0;
void set_show_ports (bool);
void setup ();
GdkPixmap* get_pixmap (GdkDrawable *);
std::pair<uint32_t, uint32_t> dimensions ();

View file

@ -36,15 +36,23 @@ PortMatrixGrid::compute_dimensions ()
{
_width = 0;
ARDOUR::BundleList const c = _matrix->columns()->bundles();
if (_matrix->show_only_bundles()) {
_width = c.size() * column_width();
} else {
for (ARDOUR::BundleList::const_iterator i = c.begin(); i != c.end(); ++i) {
_width += (*i)->nchannels() * column_width();
}
}
_height = 0;
ARDOUR::BundleList const r = _matrix->rows()->bundles();
if (_matrix->show_only_bundles()) {
_height = r.size() * column_width();
} else {
for (ARDOUR::BundleList::const_iterator i = r.begin(); i != r.end(); ++i) {
_height += (*i)->nchannels() * row_height();
}
}
}
@ -64,6 +72,7 @@ PortMatrixGrid::render (cairo_t* cr)
ARDOUR::BundleList const c = _matrix->columns()->bundles();
for (ARDOUR::BundleList::size_type i = 0; i < c.size(); ++i) {
if (!_matrix->show_only_bundles()) {
cairo_set_line_width (cr, thin_grid_line_width());
for (uint32_t j = 1; j < c[i]->nchannels(); ++j) {
x += column_width();
@ -71,6 +80,7 @@ PortMatrixGrid::render (cairo_t* cr)
cairo_line_to (cr, x, _height);
cairo_stroke (cr);
}
}
if (i < (c.size() - 1)) {
x += column_width();
@ -89,6 +99,7 @@ PortMatrixGrid::render (cairo_t* cr)
ARDOUR::BundleList const r = _matrix->rows()->bundles();
for (ARDOUR::BundleList::size_type i = 0; i < r.size(); ++i) {
if (!_matrix->show_only_bundles()) {
cairo_set_line_width (cr, thin_grid_line_width());
for (uint32_t j = 1; j < r[i]->nchannels(); ++j) {
y += row_height();
@ -96,6 +107,7 @@ PortMatrixGrid::render (cairo_t* cr)
cairo_line_to (cr, grid_width, y);
cairo_stroke (cr);
}
}
if (i < (r.size() - 1)) {
y += row_height();
@ -111,13 +123,41 @@ PortMatrixGrid::render (cairo_t* cr)
uint32_t bx = 0;
uint32_t by = 0;
if (_matrix->show_only_bundles()) {
for (ARDOUR::BundleList::const_iterator i = c.begin(); i < c.end(); ++i) {
by = 0;
for (ARDOUR::BundleList::const_iterator j = r.begin(); j < r.end(); ++j) {
PortMatrixNode::State s = bundle_to_bundle_state (*i, *j);
switch (s) {
case PortMatrixNode::UNKNOWN:
draw_unknown_indicator (cr, bx, by);
break;
case PortMatrixNode::ASSOCIATED:
draw_association_indicator (cr, bx, by);
break;
case PortMatrixNode::PARTIAL:
draw_association_indicator (cr, bx, by, 0.5);
break;
}
by += row_height();
}
bx += column_width();
}
} else {
for (ARDOUR::BundleList::const_iterator i = c.begin(); i < c.end(); ++i) {
by = 0;
for (ARDOUR::BundleList::const_iterator j = r.begin(); j < r.end(); ++j) {
x = bx;
for (uint32_t k = 0; k < (*i)->nchannels (); k++) {
for (uint32_t k = 0; k < (*i)->nchannels (); ++k) {
y = by;
for (uint32_t l = 0; l < (*j)->nchannels (); ++l) {
@ -126,10 +166,38 @@ PortMatrixGrid::render (cairo_t* cr)
c[_matrix->column_index()] = ARDOUR::BundleChannel (*i, k);
c[_matrix->row_index()] = ARDOUR::BundleChannel (*j, l);
PortMatrix::State const s = _matrix->get_state (c);
PortMatrixNode::State const s = _matrix->get_state (c);
switch (s) {
case PortMatrix::ASSOCIATED:
case PortMatrixNode::ASSOCIATED:
draw_association_indicator (cr, x, y);
break;
case PortMatrixNode::UNKNOWN:
draw_unknown_indicator (cr, x, y);
break;
case PortMatrixNode::NOT_ASSOCIATED:
break;
}
y += row_height();
}
x += column_width();
}
by += (*j)->nchannels () * row_height();
}
bx += (*i)->nchannels () * column_width();
}
}
}
void
PortMatrixGrid::draw_association_indicator (cairo_t* cr, uint32_t x, uint32_t y, double p)
{
set_source_rgba (cr, association_colour(), 0.5);
cairo_arc (
cr,
@ -137,13 +205,15 @@ PortMatrixGrid::render (cairo_t* cr)
y + column_width() / 2,
(column_width() - (2 * connection_indicator_pad())) / 2,
0,
2 * M_PI
p * 2 * M_PI
);
cairo_fill (cr);
break;
}
case PortMatrix::UNKNOWN:
void
PortMatrixGrid::draw_unknown_indicator (cairo_t* cr, uint32_t x, uint32_t y)
{
set_source_rgba (cr, unknown_colour(), 0.5);
cairo_rectangle (
cr,
@ -153,25 +223,8 @@ PortMatrixGrid::render (cairo_t* cr)
row_height() - 2 * thick_grid_line_width()
);
cairo_fill (cr);
break;
case PortMatrix::NOT_ASSOCIATED:
break;
}
y += row_height();
}
x += column_width();
}
by += (*j)->nchannels () * row_height();
}
bx += (*i)->nchannels () * column_width();
}
}
PortMatrixNode
PortMatrixGrid::position_to_node (double x, double y) const
{
@ -187,6 +240,18 @@ PortMatrixGrid::position_to_channel (double p, ARDOUR::BundleList const& bundles
{
uint32_t pos = p / inc;
if (_matrix->show_only_bundles()) {
for (ARDOUR::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
if (pos == 0) {
return ARDOUR::BundleChannel (*i, 0);
} else {
pos--;
}
}
} else {
for (ARDOUR::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
if (pos < (*i)->nchannels()) {
return ARDOUR::BundleChannel (*i, pos);
@ -195,6 +260,8 @@ PortMatrixGrid::position_to_channel (double p, ARDOUR::BundleList const& bundles
}
}
}
return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), 0);
}
@ -209,7 +276,13 @@ PortMatrixGrid::channel_position (
ARDOUR::BundleList::const_iterator i = bundles.begin ();
while (i != bundles.end() && *i != bc.bundle) {
if (_matrix->show_only_bundles()) {
p += inc;
} else {
p += inc * (*i)->nchannels();
}
++i;
}
@ -227,17 +300,37 @@ PortMatrixGrid::button_press (double x, double y, int b)
{
PortMatrixNode const node = position_to_node (x, y);
if (_matrix->show_only_bundles()) {
PortMatrixNode::State const s = bundle_to_bundle_state (node.column.bundle, node.row.bundle);
for (uint32_t i = 0; i < node.column.bundle->nchannels(); ++i) {
for (uint32_t j = 0; j < node.row.bundle->nchannels(); ++j) {
ARDOUR::BundleChannel c[2];
c[_matrix->column_index()] = ARDOUR::BundleChannel (node.column.bundle, i);
c[_matrix->row_index()] = ARDOUR::BundleChannel (node.row.bundle, j);
if (s == PortMatrixNode::NOT_ASSOCIATED || s == PortMatrixNode::PARTIAL) {
_matrix->set_state (c, i == j);
} else {
_matrix->set_state (c, false);
}
}
}
} else {
if (node.row.bundle && node.column.bundle) {
ARDOUR::BundleChannel c[2];
c[_matrix->row_index()] = node.row;
c[_matrix->column_index()] = node.column;
PortMatrix::State const s = _matrix->get_state (c);
PortMatrixNode::State const s = _matrix->get_state (c);
if (s == PortMatrix::ASSOCIATED || s == PortMatrix::NOT_ASSOCIATED) {
if (s == PortMatrixNode::ASSOCIATED || s == PortMatrixNode::NOT_ASSOCIATED) {
bool const n = !(s == PortMatrix::ASSOCIATED);
bool const n = !(s == PortMatrixNode::ASSOCIATED);
ARDOUR::BundleChannel c[2];
c[_matrix->row_index()] = node.row;
@ -246,9 +339,11 @@ PortMatrixGrid::button_press (double x, double y, int b)
_matrix->set_state (c, n);
}
}
}
require_render ();
_body->queue_draw ();
}
}
void
@ -352,3 +447,55 @@ PortMatrixGrid::parent_to_component_y (double y) const
return y + _body->yoffset() - _parent_rectangle.get_y();
}
PortMatrixNode::State
PortMatrixGrid::bundle_to_bundle_state (boost::shared_ptr<ARDOUR::Bundle> a, boost::shared_ptr<ARDOUR::Bundle> b) const
{
bool have_unknown = false;
bool have_off_diagonal_association = false;
bool have_diagonal_association = false;
bool have_diagonal_not_association = false;
for (uint32_t i = 0; i < a->nchannels (); ++i) {
for (uint32_t j = 0; j < b->nchannels (); ++j) {
ARDOUR::BundleChannel c[2];
c[_matrix->column_index()] = ARDOUR::BundleChannel (a, i);
c[_matrix->row_index()] = ARDOUR::BundleChannel (b, j);
PortMatrixNode::State const s = _matrix->get_state (c);
switch (s) {
case PortMatrixNode::ASSOCIATED:
if (i == j) {
have_diagonal_association = true;
} else {
have_off_diagonal_association = true;
}
break;
case PortMatrixNode::UNKNOWN:
have_unknown = true;
break;
case PortMatrixNode::NOT_ASSOCIATED:
if (i == j) {
have_diagonal_not_association = true;
}
break;
}
}
}
if (have_unknown) {
return PortMatrixNode::UNKNOWN;
} else if (have_diagonal_association && !have_off_diagonal_association && !have_diagonal_not_association) {
return PortMatrixNode::ASSOCIATED;
} else if (!have_diagonal_association && !have_off_diagonal_association) {
return PortMatrixNode::NOT_ASSOCIATED;
}
return PortMatrixNode::PARTIAL;
}

View file

@ -59,6 +59,10 @@ private:
PortMatrixNode position_to_node (double, double) const;
ARDOUR::BundleChannel position_to_channel (double, ARDOUR::BundleList const &, double) const;
void queue_draw_for (PortMatrixNode const &);
void draw_association_indicator (cairo_t *, uint32_t, uint32_t, double p = 1);
void draw_unknown_indicator (cairo_t *, uint32_t, uint32_t);
PortMatrixNode::State bundle_to_bundle_state (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::Bundle>) const;
};
#endif

View file

@ -19,12 +19,22 @@
#include "ardour/bundle.h"
#include "port_matrix_labels.h"
#include "port_matrix.h"
void
PortMatrixLabels::draw_extra (cairo_t* cr)
{
for (std::vector<ARDOUR::BundleChannel>::const_iterator i = _channel_highlights.begin(); i != _channel_highlights.end(); ++i) {
if (_matrix->show_only_bundles()) {
render_bundle_name (
cr,
highlighted_channel_colour(),
component_to_parent_x (channel_x (*i)),
component_to_parent_y (channel_y (*i)),
i->bundle
);
} else {
render_channel_name (
cr,
highlighted_channel_colour(),
@ -33,6 +43,7 @@ PortMatrixLabels::draw_extra (cairo_t* cr)
*i
);
}
}
}
void

View file

@ -39,6 +39,7 @@ public:
private:
virtual void render_channel_name (cairo_t *, Gdk::Color, double, double, ARDOUR::BundleChannel const &) = 0;
virtual void render_bundle_name (cairo_t *, Gdk::Color, double, double, boost::shared_ptr<ARDOUR::Bundle>) = 0;
virtual double channel_x (ARDOUR::BundleChannel const &) const = 0;
virtual double channel_y (ARDOUR::BundleChannel const &) const = 0;
virtual void queue_draw_for (ARDOUR::BundleChannel const &) = 0;

View file

@ -58,8 +58,12 @@ PortMatrixRowLabels::compute_dimensions ()
_longest_bundle_name = ext.width;
}
if (_matrix->show_only_bundles()) {
_height += row_height ();
} else {
_height += (*i)->nchannels() * row_height();
}
}
_highest_group_name = 0;
for (PortGroupList::List::const_iterator i = _matrix->rows()->begin(); i != _matrix->rows()->end(); ++i) {
@ -76,9 +80,13 @@ PortMatrixRowLabels::compute_dimensions ()
gdk_pixmap_unref (pm);
_width = _highest_group_name +
_longest_port_name +
_longest_bundle_name +
name_pad() * 6;
name_pad() * 4;
if (!_matrix->show_only_bundles()) {
_width += _longest_port_name;
_width += name_pad() * 2;
}
}
@ -109,7 +117,12 @@ PortMatrixRowLabels::render (cairo_t* cr)
}
/* compute height of this group */
double h = (*i)->total_channels () * row_height();
double h = 0;
if (_matrix->show_only_bundles()) {
h = (*i)->bundles().size() * row_height();
} else {
h = (*i)->total_channels () * row_height();
}
/* rectangle */
set_source_rgb (cr, get_a_group_colour (g));
@ -134,45 +147,18 @@ PortMatrixRowLabels::render (cairo_t* cr)
/* BUNDLE NAMES */
x = 0;
if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
x = _highest_group_name + 2 * name_pad();
} else {
x = _longest_port_name + name_pad() * 2;
}
y = 0;
ARDOUR::BundleList const r = _matrix->rows()->bundles();
for (ARDOUR::BundleList::const_iterator i = r.begin(); i != r.end(); ++i) {
Gdk::Color const colour = get_a_bundle_colour (i - r.begin ());
set_source_rgb (cr, colour);
cairo_rectangle (cr, x, y, _longest_bundle_name + name_pad() * 2, row_height() * (*i)->nchannels());
cairo_fill_preserve (cr);
set_source_rgb (cr, background_colour());
cairo_set_line_width (cr, label_border_width ());
cairo_stroke (cr);
double off = 0;
if ((*i)->nchannels () > 0) {
/* use the extent of our first channel name so that the bundle name is vertically aligned with it */
cairo_text_extents_t ext;
cairo_text_extents (cr, (*i)->channel_name(0).c_str(), &ext);
off = (row_height() - ext.height) / 2;
} else {
off = row_height() / 2;
}
set_source_rgb (cr, text_colour());
cairo_move_to (cr, x + name_pad(), y + name_pad() + off);
cairo_show_text (cr, (*i)->name().c_str());
y += row_height() * (*i)->nchannels ();
render_bundle_name (cr, get_a_bundle_colour (i - r.begin ()), 0, y, *i);
int const n = _matrix->show_only_bundles() ? 1 : (*i)->nchannels();
y += row_height() * n;
}
/* PORT NAMES */
if (!_matrix->show_only_bundles()) {
y = 0;
for (ARDOUR::BundleList::const_iterator i = r.begin(); i != r.end(); ++i) {
for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
@ -180,6 +166,7 @@ PortMatrixRowLabels::render (cairo_t* cr)
y += row_height();
}
}
}
}
void
@ -231,6 +218,25 @@ PortMatrixRowLabels::parent_to_component_y (double y) const
return y + _body->yoffset() - _parent_rectangle.get_y();
}
double
PortMatrixRowLabels::bundle_name_x () const
{
double x = 0;
if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
x = _highest_group_name + 2 * name_pad();
} else {
if (_matrix->show_only_bundles()) {
x = 0;
} else {
x = _longest_port_name + name_pad() * 2;
}
}
return x;
}
double
PortMatrixRowLabels::port_name_x () const
{
@ -243,6 +249,35 @@ PortMatrixRowLabels::port_name_x () const
return 0;
}
void
PortMatrixRowLabels::render_bundle_name (
cairo_t* cr, Gdk::Color colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
)
{
double const x = bundle_name_x ();
int const n = _matrix->show_only_bundles() ? 1 : b->nchannels();
set_source_rgb (cr, colour);
cairo_rectangle (cr, xoff + x, yoff, _longest_bundle_name + name_pad() * 2, row_height() * n);
cairo_fill_preserve (cr);
set_source_rgb (cr, background_colour());
cairo_set_line_width (cr, label_border_width ());
cairo_stroke (cr);
double const off = row_height() / 2;
// if ((*i)->nchannels () > 0 && !_matrix->show_only_bundles()) {
// /* use the extent of our first channel name so that the bundle name is vertically aligned with it */
// cairo_text_extents_t ext;
// cairo_text_extents (cr, (*i)->channel_name(0).c_str(), &ext);
// off = (row_height() - ext.height) / 2;
// }
set_source_rgb (cr, text_colour());
cairo_move_to (cr, xoff + x + name_pad(), yoff + name_pad() + off);
cairo_show_text (cr, b->name().c_str());
}
void
PortMatrixRowLabels::render_channel_name (
cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const& bc
@ -277,11 +312,18 @@ PortMatrixRowLabels::channel_y (ARDOUR::BundleChannel const& bc) const
ARDOUR::BundleList::const_iterator i = _matrix->rows()->bundles().begin();
while (i != _matrix->rows()->bundles().end() && *i != bc.bundle) {
if (_matrix->show_only_bundles()) {
n += 1;
} else {
n += (*i)->nchannels ();
}
++i;
}
if (!_matrix->show_only_bundles()) {
n += bc.channel;
}
return n * row_height();
}
@ -290,6 +332,14 @@ PortMatrixRowLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
{
if (bc.bundle) {
if (_matrix->show_only_bundles()) {
_body->queue_draw_area (
component_to_parent_x (bundle_name_x()),
component_to_parent_y (channel_y (bc)),
_longest_bundle_name + name_pad() * 2,
row_height()
);
} else {
_body->queue_draw_area (
component_to_parent_x (port_name_x()),
component_to_parent_y (channel_y (bc)),
@ -297,6 +347,7 @@ PortMatrixRowLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
row_height()
);
}
}
}

View file

@ -53,6 +53,7 @@ public:
private:
void render_channel_name (cairo_t *, Gdk::Color, double, double, ARDOUR::BundleChannel const &);
void render_bundle_name (cairo_t *, Gdk::Color, double, double, boost::shared_ptr<ARDOUR::Bundle>);
double channel_x (ARDOUR::BundleChannel const &) const;
double channel_y (ARDOUR::BundleChannel const &) const;
@ -63,6 +64,7 @@ private:
void queue_draw_for (ARDOUR::BundleChannel const &);
double port_name_x () const;
void maybe_popup_context_menu (double, double, uint32_t);
double bundle_name_x () const;
double _longest_port_name;
double _longest_bundle_name;

View file

@ -36,6 +36,13 @@ struct PortMatrixNode
ARDOUR::BundleChannel row;
ARDOUR::BundleChannel column;
enum State {
ASSOCIATED, ///< the ports are associated
NOT_ASSOCIATED, ///< the ports are not associated
UNKNOWN, ///< we don't know anything about these two ports' relationship
PARTIAL ///< used when we are examining bundles; the bundles are partially associated
};
};
#endif