2 Copyright (C) 2002-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <boost/weak_ptr.hpp>
22 #include <gtkmm/menu.h>
23 #include <gtkmm/menushell.h>
24 #include <gtkmm/menu_elems.h>
25 #include <cairo/cairo.h>
26 #include "ardour/bundle.h"
27 #include "port_matrix_row_labels.h"
28 #include "port_matrix.h"
31 PortMatrixRowLabels::PortMatrixRowLabels (PortMatrix* p, PortMatrixBody* b, Location l)
32 : PortMatrixComponent (b), _port_matrix (p), _menu (0), _location (l)
37 PortMatrixRowLabels::~PortMatrixRowLabels ()
43 PortMatrixRowLabels::compute_dimensions ()
45 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
46 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
47 cairo_t* cr = gdk_cairo_create (pm);
49 _longest_port_name = 0;
50 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
51 for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
52 cairo_text_extents_t ext;
53 cairo_text_extents (cr, (*i)->channel_name(j).c_str(), &ext);
54 if (ext.width > _longest_port_name) {
55 _longest_port_name = ext.width;
60 _longest_bundle_name = 0;
61 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
62 cairo_text_extents_t ext;
63 cairo_text_extents (cr, (*i)->name().c_str(), &ext);
64 if (ext.width > _longest_bundle_name) {
65 _longest_bundle_name = ext.width;
70 gdk_pixmap_unref (pm);
73 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
74 _height += (*i)->nchannels() * row_height();
77 _width = _longest_port_name + name_pad() * 4 + _longest_bundle_name;
82 PortMatrixRowLabels::render (cairo_t* cr)
86 set_source_rgb (cr, background_colour());
87 cairo_rectangle (cr, 0, 0, _width, _height);
90 /* SIDE BUNDLE NAMES */
93 if (_location == LEFT) {
95 } else if (_location == RIGHT) {
96 x = _longest_port_name + name_pad() * 3;
100 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
102 Gdk::Color const colour = get_a_bundle_colour (i - _body->row_bundles().begin ());
103 set_source_rgb (cr, colour);
104 cairo_rectangle (cr, 0, y, _width, row_height() * (*i)->nchannels());
105 cairo_fill_preserve (cr);
106 set_source_rgb (cr, background_colour());
107 cairo_set_line_width (cr, label_border_width ());
111 if ((*i)->nchannels () > 0) {
112 /* use the extent of our first channel name so that the bundle name is vertically aligned with it */
113 cairo_text_extents_t ext;
114 cairo_text_extents (cr, (*i)->channel_name(0).c_str(), &ext);
115 off = (row_height() - ext.height) / 2;
117 off = row_height() / 2;
120 set_source_rgb (cr, text_colour());
121 cairo_move_to (cr, x, y + name_pad() + off);
122 cairo_show_text (cr, (*i)->name().c_str());
124 y += row_height() * (*i)->nchannels ();
128 /* SIDE PORT NAMES */
131 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
132 for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
135 if (_location == LEFT) {
136 x = _longest_bundle_name + name_pad() * 2;
137 } else if (_location == RIGHT) {
141 Gdk::Color const colour = get_a_bundle_colour (i - _body->row_bundles().begin ());
142 set_source_rgb (cr, colour);
147 _longest_port_name + (name_pad() * 2),
150 cairo_fill_preserve (cr);
151 set_source_rgb (cr, background_colour());
152 cairo_set_line_width (cr, label_border_width ());
155 cairo_text_extents_t ext;
156 cairo_text_extents (cr, (*i)->channel_name(j).c_str(), &ext);
157 uint32_t const off = (row_height() - ext.height) / 2;
159 set_source_rgb (cr, text_colour());
160 cairo_move_to (cr, x + name_pad(), y + name_pad() + off);
161 cairo_show_text (cr, (*i)->channel_name(j).c_str());
169 PortMatrixRowLabels::button_press (double x, double y, int b, uint32_t t)
175 if ( (_location == LEFT && x > (_longest_bundle_name + name_pad() * 2)) ||
176 (_location == RIGHT && x < (_longest_port_name + name_pad() * 2))
181 _menu = new Gtk::Menu;
182 _menu->set_name ("ArdourContextMenu");
184 Gtk::Menu_Helpers::MenuList& items = _menu->items ();
186 uint32_t row = y / row_height ();
188 boost::shared_ptr<ARDOUR::Bundle> bundle;
189 uint32_t channel = 0;
191 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
192 if (row < (*i)->nchannels ()) {
197 row -= (*i)->nchannels ();
204 if (_port_matrix->can_rename_channels ()) {
205 snprintf (buf, sizeof (buf), _("Rename '%s'..."), bundle->channel_name (channel).c_str());
207 Gtk::Menu_Helpers::MenuElem (
209 sigc::bind (sigc::mem_fun (*this, &PortMatrixRowLabels::rename_channel_proxy), bundle, channel)
214 snprintf (buf, sizeof (buf), _("Remove '%s'"), bundle->channel_name (channel).c_str());
216 Gtk::Menu_Helpers::MenuElem (
218 sigc::bind (sigc::mem_fun (*this, &PortMatrixRowLabels::remove_channel_proxy), bundle, channel)
229 PortMatrixRowLabels::remove_channel_proxy (boost::weak_ptr<ARDOUR::Bundle> b, uint32_t c)
231 boost::shared_ptr<ARDOUR::Bundle> sb = b.lock ();
236 _port_matrix->remove_channel (sb, c);
241 PortMatrixRowLabels::rename_channel_proxy (boost::weak_ptr<ARDOUR::Bundle> b, uint32_t c)
243 boost::shared_ptr<ARDOUR::Bundle> sb = b.lock ();
248 _port_matrix->rename_channel (sb, c);