1dd77dd5a1f3ac48b4d202862b19c9b4c13210ce
[ardour.git] / gtk2_ardour / io_selector.h
1 /*
2     Copyright (C) 2002 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     $Id$
19 */
20
21 #ifndef __ardour_ui_io_selector_h__
22 #define __ardour_ui_io_selector_h__
23
24 #if __GNUC__ >= 3
25 #include <ext/slist>
26 using __gnu_cxx::slist;
27 #else
28 #include <slist.h>
29 #endif
30
31 #include <string>
32 #include <gtkmm/box.h>
33 #include <gtkmm/frame.h>
34 #include <gtkmm/button.h>
35 #include <gtkmm/scrolledwindow.h>
36 #include <gtkmm/notebook.h>
37 #include <gtkmm/treeview.h>
38 #include <gtkmm/liststore.h>
39
40 #include <ardour_dialog.h>
41
42 namespace ARDOUR {
43         class IO;
44         class Session;
45         class PortInsert;
46         class Port;
47         class Redirect;
48 }
49
50 class IOSelector : public Gtk::VBox {
51   public:
52         IOSelector (ARDOUR::Session&, ARDOUR::IO&, bool for_input);
53         ~IOSelector ();
54
55         void redisplay ();
56
57         enum Result {
58                 Cancelled,
59                 Accepted
60         };
61
62         sigc::signal<void,Result> Finished;
63
64   protected:
65         ARDOUR::Session& session;
66
67   private:
68         ARDOUR::IO& io;
69         bool for_input;
70         ARDOUR::Port *selected_port;
71
72         Gtk::VBox main_box;
73         Gtk::HBox port_and_selector_box;
74
75         /* column model */
76
77         struct PortDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
78
79             PortDisplayModelColumns() { 
80                     add (displayed_name);
81                     add (full_name);
82             }
83
84             Gtk::TreeModelColumn<Glib::ustring>       displayed_name;
85             Gtk::TreeModelColumn<Glib::ustring>       full_name;
86         };
87
88         PortDisplayModelColumns port_display_columns;
89
90         /* client/port selection */
91
92         Gtk::Notebook notebook;
93         Gtk::Frame selector_frame;
94         Gtk::VBox selector_box;
95         Gtk::HBox selector_button_box;
96
97         /* ports */
98
99         Gtk::VBox port_box;
100         Gtk::HBox port_button_box;
101         Gtk::VBox port_and_button_box;
102         Gtk::Frame port_frame;
103         Gtk::Button add_port_button;
104         Gtk::Button remove_port_button;
105         Gtk::Button clear_connections_button;
106         Gtk::ScrolledWindow port_display_scroller;
107
108         PBD::Lock port_display_lock;
109         slist<Gtk::TreeView *> port_displays;
110         void display_ports ();
111
112         void rescan ();
113         void clear_connections ();
114
115         bool port_selection_changed(GdkEventButton *, Gtk::TreeView*);
116
117         void ports_changed (ARDOUR::IOChange, void *);
118         void name_changed (void*);
119
120         void add_port ();
121         void remove_port ();
122         gint remove_port_when_idle (ARDOUR::Port *);
123
124         gint port_column_button_release (GdkEventButton *, Gtk::TreeView*);
125         gint connection_button_release (GdkEventButton *, Gtk::TreeView*);
126         
127         void select_treeview(Gtk::TreeView*);
128         void select_next_treeview ();
129 };
130
131 class IOSelectorWindow : public ArdourDialog
132 {
133   public:
134         IOSelectorWindow (ARDOUR::Session&, ARDOUR::IO&, bool for_input, bool can_cancel=false);
135         ~IOSelectorWindow ();
136
137         IOSelector& selector() { return _selector; }
138
139   protected:
140         void on_map ();
141         
142   private:
143         IOSelector _selector;
144
145         /* overall operation buttons */
146
147         Gtk::Button ok_button;
148         Gtk::Button cancel_button;
149         Gtk::Button rescan_button;
150         Gtk::HBox button_box;
151
152         void rescan ();
153         void cancel ();
154         void accept ();
155 };
156
157
158 class PortInsertUI : public Gtk::VBox
159 {
160   public: 
161         PortInsertUI (ARDOUR::Session&, ARDOUR::PortInsert&);
162         
163         void redisplay ();
164         void finished (IOSelector::Result);
165
166   private:
167         
168         Gtk::HBox  hbox;
169         IOSelector input_selector;
170         IOSelector output_selector;
171         
172 };
173
174 class PortInsertWindow : public ArdourDialog
175 {
176   public: 
177         PortInsertWindow (ARDOUR::Session&, ARDOUR::PortInsert&, bool can_cancel=false);
178         
179   protected:
180         void on_map ();
181         
182   private:
183         
184         PortInsertUI _portinsertui;
185         Gtk::VBox vbox;
186         
187         Gtk::Button ok_button;
188         Gtk::Button cancel_button;
189         Gtk::Button rescan_button;
190         Gtk::Frame button_frame;
191         Gtk::HBox button_box;
192         
193         void rescan ();
194         void cancel ();
195         void accept ();
196
197         void plugin_going_away (ARDOUR::Redirect*);
198 };
199
200
201 #endif /* __ardour_ui_io_selector_h__ */