/* Copyright (C) 2002-2007 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "ardour/session.h" #include "ardour/io.h" #include "ardour/audioengine.h" #include "ardour/track.h" #include "ardour/audio_track.h" #include "ardour/midi_track.h" #include "ardour/data_type.h" #include "io_selector.h" #include "keyboard.h" #include "utils.h" #include "gui_thread.h" #include "i18n.h" using namespace Gtk; /** Add a port to a group. * @param p Port name, with or without prefix. */ void PortGroup::add (std::string const & p) { if (prefix.empty() == false && p.substr (0, prefix.length()) == prefix) { ports.push_back (p.substr (prefix.length())); } else { ports.push_back (p); } } /** PortGroupUI constructor. * @param m PortMatrix to work for. * @Param g PortGroup to represent. */ PortGroupUI::PortGroupUI (PortMatrix& m, PortGroup& g) : _port_matrix (m) , _port_group (g) , _ignore_check_button_toggle (false) , _visibility_checkbutton (g.name) { int const ports = _port_group.ports.size(); int const rows = _port_matrix.n_rows (); if (rows == 0 || ports == 0) { return; } /* Sort out the table and the checkbuttons inside it */ _table.resize (rows, ports); _port_checkbuttons.resize (rows); for (int i = 0; i < rows; ++i) { _port_checkbuttons[i].resize (ports); } for (int i = 0; i < rows; ++i) { for (uint32_t j = 0; j < _port_group.ports.size(); ++j) { CheckButton* b = new CheckButton; b->signal_toggled().connect ( sigc::bind (sigc::mem_fun (*this, &PortGroupUI::port_checkbutton_toggled), b, i, j)); b->signal_button_release_event().connect ( sigc::bind (sigc::mem_fun (*this, &PortGroupUI::port_checkbutton_release), b, i, j), false); _port_checkbuttons[i][j] = b; cerr << this << " bind to " << &_port_checkbuttons << " via " << b << endl; _table.attach (*b, j, j + 1, i, i + 1); } } _table_box.add (_table); _ignore_check_button_toggle = true; /* Set the state of the check boxes according to current connections */ for (int i = 0; i < rows; ++i) { for (uint32_t j = 0; j < _port_group.ports.size(); ++j) { std::string const t = _port_group.prefix + _port_group.ports[j]; bool const s = _port_matrix.get_state (i, t); _port_checkbuttons[i][j]->set_active (s); if (s) { _port_group.visible = true; } } } _ignore_check_button_toggle = false; _visibility_checkbutton.signal_toggled().connect (sigc::mem_fun (*this, &PortGroupUI::visibility_checkbutton_toggled)); } /** The visibility of a PortGroupUI has been toggled */ void PortGroupUI::visibility_checkbutton_toggled () { _port_group.visible = _visibility_checkbutton.get_active (); } /** @return Width and height of a single checkbutton in a port group table */ std::pair PortGroupUI::unit_size () const { if (_port_checkbuttons.empty() || _port_checkbuttons[0].empty()) { return std::pair (0, 0); } int r = 0; /* We can't ask for row spacing unless there >1 rows, otherwise we get a warning */ if (_table.property_n_rows() > 1) { r = _table.get_row_spacing (0); } return std::make_pair ( _port_checkbuttons[0][0]->get_width() + _table.get_col_spacing (0), _port_checkbuttons[0][0]->get_height() + r ); } /** @return Table widget containing the port checkbuttons */ Widget& PortGroupUI::get_table () { return _table_box; } /** @return Checkbutton used to toggle visibility */ Widget& PortGroupUI::get_visibility_checkbutton () { return _visibility_checkbutton; } /** Handle a toggle of a port check button */ void PortGroupUI::port_checkbutton_toggled (CheckButton* b, int r, int c) { if (_ignore_check_button_toggle == false) { _port_matrix.set_state (r, _port_group.prefix + _port_group.ports[c], b->get_active(), 0); } } bool PortGroupUI::port_checkbutton_release (GdkEventButton* ev, CheckButton* b, int r, int c) { cerr << this << " RELEASE on " << b << " state = " << ev->state << endl; if (ev->state == 0) { /* let usual toggle handler take care of it */ return false; } /* The fun starts here */ const size_t ports = _port_group.ports.size(); const size_t rows = _port_matrix.n_rows (); if (rows == 0 || ports == 0) { return true; } /* For each port in the group, change the state of the connection for the corresponding "connector" port. */ for (size_t j = c; j < ports; ++j) { /* we've got a port to connect, now lets find the thing to connect it too ... (search "down" the rows) */ cerr << "we're going to connect port " << j << " of " << ports << endl; for (size_t i = r; i < rows; ++i) { cerr << this << " going to connect to row " << i << " of " << rows << endl; cerr << "access [" << i << "][" << j << "]\n"; cerr << " @ " << &_port_checkbuttons << endl; _port_checkbuttons[i][j]->set_active (!_port_checkbuttons[i][j]->get_active()); /* next time, get at least as far as this port before looking for more. */ r = i + 1; /* changed connection state, stop looking for more */ break; } } return true; } /** Set up visibility of the port group according to PortGroup::visible */ void PortGroupUI::setup_visibility () { if (!_port_group.ports.empty() && _port_group.visible) { _table_box.show (); } else { _table_box.hide (); } if (_visibility_checkbutton.get_active () != _port_group.visible) { _visibility_checkbutton.set_active (_port_group.visible); } } RotatedLabelSet::RotatedLabelSet (PortGroupList& g) : Glib::ObjectBase ("RotatedLabelSet"), Widget (), _port_group_list (g), _base_width (128) { set_flags (NO_WINDOW); set_angle (atoi (getenv ("AD_ANGLE"))); } RotatedLabelSet::~RotatedLabelSet () { } /** Set the angle that the labels are drawn at. * @param degrees New angle in degrees. */ void RotatedLabelSet::set_angle (int degrees) { _angle_degrees = degrees; _angle_radians = M_PI * _angle_degrees / 180; queue_resize (); } void RotatedLabelSet::on_size_request (Requisition* requisition) { *requisition = Requisition (); if (_pango_layout == 0) { return; } /* Our height is the highest label */ requisition->height = 0; for (PortGroupList::const_iterator i = _port_group_list.begin(); i != _port_group_list.end(); ++i) { for (std::vector::const_iterator j = (*i)->ports.begin(); j != (*i)->ports.end(); ++j) { std::pair const d = setup_layout (*j); if (d.second > requisition->height) { requisition->height = d.second; } } } /* And our width is the base plus the width of the last label */ requisition->width = _base_width; int const n = _port_group_list.n_visible_ports (); if (n > 0) { std::pair const d = setup_layout (_port_group_list.get_port_by_index (n - 1, false)); requisition->width += d.first; } cerr << "Labels will be " << requisition->width << " x " << requisition->height << endl; } void RotatedLabelSet::on_size_allocate (Allocation& allocation) { set_allocation (allocation); if (_gdk_window) { _gdk_window->move_resize (allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height()); } } void RotatedLabelSet::on_realize () { Widget::on_realize (); Glib::RefPtr