next region list fix from chris g; more tweaks to port matrix/ioselector; remove...
[ardour.git] / gtk2_ardour / port_matrix.h
1 /*
2     Copyright (C) 2002-2007 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 __ardour_ui_port_matrix_h__
21 #define __ardour_ui_port_matrix_h__
22
23 #include <gtkmm/box.h>
24 #include <gtkmm/checkbutton.h>
25 #include <gtkmm/table.h>
26 #include <gtkmm/frame.h>
27 #include <gtkmm/eventbox.h>
28 #include <gtkmm/scrolledwindow.h>
29
30 #include "ardour_dialog.h"
31
32 namespace ARDOUR {
33         class Session;
34         class IO;
35         class PortInsert;
36 }
37
38 class PortMatrix;
39
40 /// A list of port names, grouped by some aspect of their type e.g. busses, tracks, system
41 class PortGroup
42 {
43   public:
44         /** PortGroup constructor.
45          * @param n Name.
46          * @param p Port name prefix.
47          * @param v true if group should be visible in the UI, otherwise false.
48          */
49         PortGroup (std::string const & n, std::string const & p, bool v) : name (n), prefix (p), visible (v) {}
50
51         void add (std::string const & p);
52
53         std::string name; ///< name for the group
54         std::string prefix; ///< prefix (before colon) e.g. "ardour:"
55         std::vector<std::string> ports; ///< port names
56         bool visible; ///< true if the group is visible in the UI
57 };
58
59 /// The UI for a PortGroup
60 class PortGroupUI
61 {
62   public:
63         PortGroupUI (PortMatrix&, PortGroup&);
64
65         Gtk::Widget& get_table ();
66         Gtk::Widget& get_visibility_checkbutton ();
67         std::pair<int, int> unit_size () const;
68         PortGroup& port_group () { return _port_group; }
69         void setup_visibility ();
70
71   private:
72         void port_checkbutton_toggled (Gtk::CheckButton*, int, int);
73         void visibility_checkbutton_toggled ();
74
75         PortMatrix& _port_matrix; ///< the PortMatrix that we are working for
76         PortGroup& _port_group; ///< the PortGroup that we are representing
77         bool _ignore_check_button_toggle;
78         Gtk::Table _table;
79         Gtk::EventBox _table_box;
80         std::vector<std::vector<Gtk::CheckButton* > > _port_checkbuttons;
81         Gtk::CheckButton _visibility_checkbutton;
82 };
83
84 /// A list of PortGroups
85 class PortGroupList : public std::list<PortGroup*>
86 {
87   public:
88         enum Mask {
89                 BUSS = 0x1,
90                 TRACK = 0x2,
91                 SYSTEM = 0x4,
92                 OTHER = 0x8
93         };
94
95         PortGroupList (ARDOUR::Session &, ARDOUR::DataType, bool, Mask);
96
97         void refresh ();
98         int n_visible_ports () const;
99         std::string get_port_by_index (int, bool with_prefix = true) const;
100         void set_type (ARDOUR::DataType);
101         void set_offer_inputs (bool);
102         
103   private:
104         ARDOUR::Session& _session;
105         ARDOUR::DataType _type;
106         bool _offer_inputs;
107
108         PortGroup buss;
109         PortGroup track;
110         PortGroup system;
111         PortGroup other;
112 };
113
114
115 /// A widget which provides a set of rotated text labels
116 class RotatedLabelSet : public Gtk::Widget {
117   public:
118         RotatedLabelSet (PortGroupList&);
119         virtual ~RotatedLabelSet ();
120
121         void set_angle (int);
122         void set_base_width (int);
123         void update_visibility ();
124         
125   protected:
126         virtual void on_size_request (Gtk::Requisition*);
127         virtual void on_size_allocate (Gtk::Allocation&);
128         virtual void on_realize ();
129         virtual void on_unrealize ();
130         virtual bool on_expose_event (GdkEventExpose*);
131
132         Glib::RefPtr<Gdk::Window> _gdk_window;
133
134   private:
135         std::pair<int, int> setup_layout (std::string const &);
136
137         PortGroupList& _port_group_list; ///< list of ports to display
138         int _angle_degrees; ///< label rotation angle in degrees
139         double _angle_radians; ///< label rotation angle in radians
140         int _base_width; ///< width of labels; see set_base_width() for more details
141         Glib::RefPtr<Pango::Context> _pango_context;
142         Glib::RefPtr<Pango::Layout> _pango_layout;
143         Glib::RefPtr<Gdk::GC> _gc;
144         Gdk::Color _fg_colour;
145         Gdk::Color _bg_colour;
146 };
147
148
149 class PortMatrix : public Gtk::VBox {
150   public:
151         PortMatrix (ARDOUR::Session&, ARDOUR::DataType, bool, PortGroupList::Mask);
152         ~PortMatrix ();
153
154         void redisplay ();
155
156         enum Result {
157                 Cancelled,
158                 Accepted
159         };
160
161         sigc::signal<void, Result> Finished;
162
163         void set_type (ARDOUR::DataType);
164         void set_offer_inputs (bool);
165         bool offering_input() const { return _offer_inputs; }
166
167         virtual void set_state (int, std::string const &, bool) = 0;
168         virtual bool get_state (int, std::string const &) const = 0;
169         virtual uint32_t n_rows () const = 0;
170         virtual uint32_t maximum_rows () const = 0;
171         virtual uint32_t minimum_rows () const = 0;
172         virtual std::string row_name (int) const = 0;
173         virtual void add_row () = 0;
174         virtual void remove_row (int) = 0;
175         virtual std::string row_descriptor () const = 0;
176
177         Gtk::Widget& scrolled_window() { return _scrolled_window; }
178
179   protected:
180
181         bool _offer_inputs;
182
183   private:
184         PortGroupList _port_group_list;
185         ARDOUR::DataType _type;
186         std::vector<PortGroupUI*> _port_group_ui;
187         std::vector<Gtk::EventBox*> _row_labels;
188         Gtk::VBox* _row_labels_vbox;
189         RotatedLabelSet _column_labels;
190         Gtk::HBox _overall_hbox;
191         Gtk::VBox _side_vbox;
192         Gtk::HBox _port_group_hbox;
193         Gtk::ScrolledWindow _scrolled_window;
194         Gtk::Label* _side_vbox_pad;
195         Gtk::HBox _visibility_checkbutton_box;
196
197         void setup ();
198         void clear ();
199         void setup_dimensions ();
200         bool row_label_button_pressed (GdkEventButton*, int);
201         void reset_visibility ();
202 };
203
204 #endif