switch to using boost::signals2 instead of sigc++, at least for libardour. not finish...
[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 <gtkmm/table.h>
27 #include <gtkmm/label.h>
28 #include <gtkmm/checkbutton.h>
29 #include <gtkmm/notebook.h>
30 #include <boost/shared_ptr.hpp>
31
32 #include "ardour/bundle.h"
33 #include "ardour/types.h"
34 #include "ardour/session_handle.h"
35
36 #include "port_group.h"
37 #include "port_matrix_types.h"
38 #include "i18n.h"
39
40 /** The `port matrix' UI.  This is a widget which lets the user alter
41  *  associations between one set of ports and another.  e.g. to connect
42  *  things together.
43  *
44  *  It is made up of a body, PortMatrixBody, which is rendered using cairo,
45  *  and some scrollbars and other stuff.  All of this is arranged inside the
46  *  Table that we inherit from.
47  */
48
49 namespace ARDOUR {
50         class Bundle;
51 }
52
53 namespace Gtk {
54         namespace Menu_Helpers {
55                 class MenuList;
56         }
57 }
58
59 class PortMatrixBody;
60
61 class PortMatrix : public Gtk::Table, public ARDOUR::SessionHandlePtr
62 {
63 public:
64         PortMatrix (Gtk::Window*, ARDOUR::Session *, ARDOUR::DataType);
65         ~PortMatrix ();
66
67         void set_type (ARDOUR::DataType);
68
69         ARDOUR::DataType type () const {
70                 return _type;
71         }
72
73         void disassociate_all ();
74         void setup_scrollbars ();
75         void popup_menu (ARDOUR::BundleChannel, ARDOUR::BundleChannel, uint32_t);
76
77         int min_height_divisor () const {
78                 return _min_height_divisor;
79         }
80         void set_min_height_divisor (int f) {
81                 _min_height_divisor = f;
82         }
83
84         enum Arrangement {
85                 TOP_TO_RIGHT,  ///< column labels on top, row labels to the right
86                 LEFT_TO_BOTTOM ///< row labels to the left, column labels on the bottom
87         };
88
89         
90         /** @return Arrangement in use */
91         Arrangement arrangement () const {
92                 return _arrangement;
93         }
94
95         bool show_only_bundles () const {
96                 return _show_only_bundles;
97         }
98
99         PortGroupList const * columns () const;
100         boost::shared_ptr<const PortGroup> visible_columns () const;
101
102         /** @return index into the _ports array for the list which is displayed as columns */
103         int column_index () const {
104                 return _column_index;
105         }
106
107         PortGroupList const * rows () const;
108         boost::shared_ptr<const PortGroup> visible_rows () const;
109
110         /** @return index into the _ports array for the list which is displayed as rows */
111         int row_index () const {
112                 return _row_index;
113         }
114
115         PortGroupList const * ports (int d) const {
116                 return &_ports[d];
117         }
118
119         boost::shared_ptr<const PortGroup> visible_ports (int d) const;
120         
121         void init ();
122         void setup ();
123         virtual void setup_ports (int) = 0;
124         void setup_all_ports ();
125
126         std::pair<uint32_t, uint32_t> max_size () const;
127
128         /** @param c Channels; where c[0] is from _ports[0] and c[1] is from _ports[1].
129          *  @param s New state.
130          */
131         virtual void set_state (ARDOUR::BundleChannel c[2], bool s) = 0;
132
133         /** @param c Channels; where c[0] is from _ports[0] and c[1] is from _ports[1].
134          *  @return state
135          */
136         virtual PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const = 0;
137         virtual bool list_is_global (int) const = 0;
138
139         virtual bool can_add_channel (boost::shared_ptr<ARDOUR::Bundle>) const;
140         virtual void add_channel (boost::shared_ptr<ARDOUR::Bundle>);
141         virtual bool can_remove_channels (boost::shared_ptr<ARDOUR::Bundle>) const;
142         virtual void remove_channel (ARDOUR::BundleChannel);
143         virtual bool can_rename_channels (boost::shared_ptr<ARDOUR::Bundle>) const {
144                 return false;
145         }
146         virtual void rename_channel (ARDOUR::BundleChannel) {}
147         virtual std::string disassociation_verb () const = 0;
148         virtual std::string channel_noun () const { return _("channel"); }
149
150         enum Result {
151                 Cancelled,
152                 Accepted
153         };
154
155         sigc::signal<void, Result> Finished;
156
157 protected:
158
159         /** We have two port group lists.  One will be presented on the rows of the matrix,
160             the other on the columns.  The PortMatrix chooses the arrangement based on which has
161             more ports in it.  Subclasses must fill these two lists with the port groups that they
162             wish to present.  The PortMatrix will arrange its layout such that signal flow is vaguely
163             from left to right as you go from list 0 to list 1.  Hence subclasses which deal with
164             inputs and outputs should put outputs in list 0 and inputs in list 1. */
165         PortGroupList _ports[2];
166
167 private:
168
169         void hscroll_changed ();
170         void vscroll_changed ();
171         void routes_changed ();
172         void reconnect_to_routes ();
173         void select_arrangement ();
174         void add_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>);
175         void remove_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>, uint32_t);
176         void rename_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>, uint32_t);
177         void disassociate_all_on_channel (boost::weak_ptr<ARDOUR::Bundle>, uint32_t, int);
178         void setup_global_ports ();
179         void toggle_show_only_bundles ();
180         bool on_scroll_event (GdkEventScroll *);
181         boost::shared_ptr<ARDOUR::IO> io_from_bundle (boost::shared_ptr<ARDOUR::Bundle>) const;
182         void setup_notebooks ();
183         void remove_notebook_pages (Gtk::Notebook &);
184         void notebook_page_selected (GtkNotebookPage *, guint);
185         void route_processors_changed (ARDOUR::RouteProcessorChange);
186         void body_dimensions_changed ();
187         void session_going_away ();
188         void add_remove_option (Gtk::Menu_Helpers::MenuList &, boost::weak_ptr<ARDOUR::Bundle>, int);
189         void add_disassociate_option (Gtk::Menu_Helpers::MenuList &, boost::weak_ptr<ARDOUR::Bundle>, int, int);
190
191         Gtk::Window* _parent;
192
193         /// port type that we are working with
194         ARDOUR::DataType _type;
195         PBD::ScopedConnectionList _route_connections;
196
197         PortMatrixBody* _body;
198         Gtk::HScrollbar _hscroll;
199         Gtk::VScrollbar _vscroll;
200         Gtk::Notebook _vnotebook;
201         Gtk::Notebook _hnotebook;
202         Gtk::Label _vlabel;
203         Gtk::Label _hlabel;
204         Gtk::VBox _vbox;
205         Gtk::HBox _hbox;
206         Gtk::Label _hspacer;
207         Gtk::Label _vspacer;
208         Gtk::Menu* _menu;
209         Arrangement _arrangement;
210         int _row_index;
211         int _column_index;
212         int _min_height_divisor;
213         bool _show_only_bundles;
214         bool _inhibit_toggle_show_only_bundles;
215         bool _ignore_notebook_page_selected;
216 };
217
218 #endif