New matrix-based editor for connections and bundles, based on thorwil's design.
[ardour.git] / gtk2_ardour / port_matrix.h
1 /*
2     Copyright (C) 2002-2009 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __gtk_ardour_port_matrix_h__
21 #define __gtk_ardour_port_matrix_h__
22
23 #include <list>
24 #include <gtkmm/box.h>
25 #include <gtkmm/scrollbar.h>
26 #include <boost/shared_ptr.hpp>
27 #include "port_matrix_body.h"
28 #include "port_group.h"
29
30 /** The `port matrix' UI.  This is a widget which lets the user alter
31  *  associations between one set of ports and another.  e.g. to connect
32  *  things together.
33  *
34  *  The columns are labelled with various ports from around Ardour and the
35  *  system.
36  *
37  *  It is made up of a body, PortMatrixBody, which is rendered using cairo,
38  *  and some scrollbars.  All of this is arranged inside the VBox that we
39  *  inherit from.
40  */
41
42 namespace ARDOUR {
43         class Bundle;
44 }
45
46 class PortMatrix : public Gtk::VBox
47 {
48 public:
49         PortMatrix (ARDOUR::Session&, ARDOUR::DataType, bool, PortGroupList::Mask);
50         ~PortMatrix ();
51
52         virtual void setup ();
53         void set_offer_inputs (bool);
54         void set_type (ARDOUR::DataType);
55         bool offering_input () const { return _offer_inputs; }
56         void disassociate_all ();
57
58         enum Result {
59                 Cancelled,
60                 Accepted
61         };
62
63         sigc::signal<void, Result> Finished;
64
65         /** @param ab Our bundle.
66          *  @param ac Channel on our bundle.
67          *  @param bb Other bundle.
68          *  @arapm bc Channel on other bundle.
69          *  @param s New state.
70          *  @param k XXX
71          */
72         virtual void set_state (
73                 boost::shared_ptr<ARDOUR::Bundle> ab,
74                 uint32_t ac,
75                 boost::shared_ptr<ARDOUR::Bundle> bb,
76                 uint32_t bc,
77                 bool s,
78                 uint32_t k
79                 ) = 0;
80
81         /** @param ab Our bundle.
82          *  @param ac Channel on our bundle.
83          *  @param bb Other bundle.
84          *  @arapm bc Channel on other bundle.
85          *  @return true if r is connected to p, otherwise false.
86          */
87         virtual bool get_state (
88                 boost::shared_ptr<ARDOUR::Bundle> ab,
89                 uint32_t ac,
90                 boost::shared_ptr<ARDOUR::Bundle> bb,
91                 uint32_t bc
92                 ) const = 0;
93
94         virtual void add_channel (boost::shared_ptr<ARDOUR::Bundle>) = 0;
95         virtual void remove_channel (boost::shared_ptr<ARDOUR::Bundle>, uint32_t) = 0;
96         virtual bool can_rename_channels () const = 0;
97         virtual void rename_channel (boost::shared_ptr<ARDOUR::Bundle>, uint32_t) {}
98         
99         void setup_scrollbars ();
100
101 protected:
102         /// our bundle
103         boost::shared_ptr<ARDOUR::Bundle> _our_bundle;
104         
105 private:
106
107         void hscroll_changed ();
108         void vscroll_changed ();
109         std::string common_prefix (std::vector<std::string> const &) const;
110         
111         /// true to offer inputs, otherwise false
112         bool _offer_inputs;
113         /// list of port groups
114         PortGroupList _port_group_list;
115         /// port type that we are working with
116         ARDOUR::DataType _type;
117
118         PortMatrixBody _body;
119         Gtk::HScrollbar _hscroll;
120         Gtk::VScrollbar _vscroll;
121         std::list<PortGroupUI*> _port_group_uis;
122 };
123
124 #endif