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