add 0.5 second sleep after closing JACK connection so that next startup/connect is...
[ardour.git] / gtk2_ardour / export_channel_selector.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __export_channel_selector_h__
22 #define __export_channel_selector_h__
23
24 #include <list>
25
26 #include "ardour/export_profile_manager.h"
27
28 #include <gtkmm.h>
29 #include <sigc++/signal.h>
30 #include <boost/shared_ptr.hpp>
31
32 namespace ARDOUR {
33         class Session;
34         class ExportChannelConfiguration;
35         class RegionExportChannelFactory;
36         class ExportHandler;
37         class AudioPort;
38         class IO;
39         class AudioRegion;
40         class AudioTrack;
41 }
42
43 class XMLNode;
44
45 class ExportChannelSelector : public Gtk::HBox, public ARDOUR::SessionHandlePtr
46 {
47   protected:
48         typedef boost::shared_ptr<ARDOUR::ExportChannelConfiguration> ChannelConfigPtr;
49         typedef std::list<ChannelConfigPtr> ChannelConfigList;
50         typedef boost::shared_ptr<ARDOUR::ExportProfileManager> ProfileManagerPtr;
51
52         ProfileManagerPtr manager;
53
54   public:
55         ExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager)
56                 : SessionHandlePtr (session)
57                 , manager (manager)
58         {}
59
60         virtual ~ExportChannelSelector () {}
61
62         virtual void sync_with_manager () = 0;
63
64         sigc::signal<void> CriticalSelectionChanged;
65 };
66
67 class PortExportChannelSelector : public ExportChannelSelector
68 {
69
70   public:
71
72         PortExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager);
73         ~PortExportChannelSelector ();
74
75         void sync_with_manager ();
76
77   private:
78
79         void fill_route_list ();
80         void update_channel_count ();
81         void update_split_state ();
82
83         typedef std::list<ARDOUR::ExportChannelPtr> CahnnelList;
84
85         ARDOUR::ExportProfileManager::ChannelConfigStatePtr state;
86
87         /*** GUI stuff ***/
88
89         Gtk::VBox         channels_vbox;
90         Gtk::HBox         channels_hbox;
91
92         Gtk::Label        channels_label;
93         Gtk::SpinButton   channels_spinbutton;
94         Gtk::CheckButton  split_checkbox;
95
96         /* Column record for channel selector view */
97
98         class RouteCols : public Gtk::TreeModelColumnRecord
99         {
100           public:
101
102                 struct Channel;
103
104                 RouteCols () : n_channels (0)
105                         { add (selected); add (name); add (io); add (port_list_col); }
106
107                 void add_channels (uint32_t chans);
108                 uint32_t n_channels;
109
110                 /* Channel count starts from one! */
111
112                 Channel & get_channel (uint32_t channel);
113
114                 /* Static columns */
115
116                 Gtk::TreeModelColumn<bool>           selected;
117                 Gtk::TreeModelColumn<std::string>  name;
118                 Gtk::TreeModelColumn<ARDOUR::IO *>   io;
119
120                 /* Combo list column (shared by all channels) */
121
122                 typedef Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> > ComboCol;
123                 ComboCol                             port_list_col;
124
125                 /* Channel struct, that represents the selected port and it's name */
126
127                 struct Channel {
128                   public:
129                         Channel (RouteCols & cols) { cols.add (port); cols.add (label); }
130
131                         Gtk::TreeModelColumn<boost::weak_ptr<ARDOUR::AudioPort> > port;
132                         Gtk::TreeModelColumn<std::string> label;
133                 };
134                 std::list<Channel> channels;
135
136                 /* List of available ports
137                  * Note: We need only one list of selectable ports per route,
138                  * so the list is kept in the column record
139                  */
140
141                 /* Column record for selecting ports for a channel from a route */
142
143                 class PortCols : public Gtk::TreeModel::ColumnRecord
144                 {
145                   public:
146                         PortCols () { add(selected); add(port); add(label); }
147
148                         Gtk::TreeModelColumn<bool> selected;  // not used ATM
149                         Gtk::TreeModelColumn<boost::weak_ptr<ARDOUR::AudioPort> > port;
150                         Gtk::TreeModelColumn<std::string> label;
151                 };
152                 PortCols port_cols;
153         };
154
155         /* Channels view */
156
157         class ChannelTreeView : public Gtk::TreeView {
158           public:
159
160                 ChannelTreeView (uint32_t max_channels);
161                 void set_config (ChannelConfigPtr c);
162
163                 /* Routes have to be added before adding channels */
164
165                 void clear_routes () { route_list->clear (); }
166                 void add_route (ARDOUR::IO * route);
167                 void set_channel_count (uint32_t channels);
168
169                 sigc::signal<void> CriticalSelectionChanged;
170
171           private:
172
173                 ChannelConfigPtr config;
174                 void update_config ();
175
176                 /* Signal handlers for selections changes in the view */
177
178                 void update_toggle_selection (std::string const & path);
179                 void update_selection_text (std::string const & path, std::string const & new_text, uint32_t channel);
180
181                 RouteCols                     route_cols;
182                 Glib::RefPtr<Gtk::ListStore>  route_list;
183
184                 uint32_t                      static_columns;
185                 uint32_t                      n_channels;
186         };
187
188         uint32_t                     max_channels;
189
190         Gtk::ScrolledWindow          channel_scroller;
191         Gtk::Alignment               channel_alignment;
192         ChannelTreeView              channel_view;
193
194 };
195
196 class RegionExportChannelSelector : public ExportChannelSelector
197 {
198   public:
199         RegionExportChannelSelector (ARDOUR::Session * session,
200                                      ProfileManagerPtr manager,
201                                      ARDOUR::AudioRegion const & region,
202                                      ARDOUR::AudioTrack & track);
203
204         virtual void sync_with_manager ();
205
206   private:
207
208         void handle_selection ();
209
210         ARDOUR::ExportProfileManager::ChannelConfigStatePtr state;
211         boost::shared_ptr<ARDOUR::RegionExportChannelFactory> factory;
212         ARDOUR::AudioRegion const & region;
213         ARDOUR::AudioTrack & track;
214
215         uint32_t region_chans;
216         uint32_t track_chans;
217
218         /*** GUI components ***/
219
220         Gtk::VBox             vbox;
221
222         Gtk::RadioButtonGroup type_group;
223         Gtk::RadioButton      raw_button;
224         Gtk::RadioButton      fades_button;
225         Gtk::RadioButton      processed_button;
226 };
227
228 class TrackExportChannelSelector : public ExportChannelSelector
229 {
230   public:
231         TrackExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager);
232
233         virtual void sync_with_manager ();
234
235   private:
236
237         void fill_list();
238         void add_track (boost::shared_ptr<ARDOUR::Route> route);
239         void update_config();
240
241         ChannelConfigList configs;
242
243         Gtk::VBox main_layout;
244
245         struct TrackCols : public Gtk::TreeModelColumnRecord
246         {
247           public:
248                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Route> > route;
249                 Gtk::TreeModelColumn<std::string>     label;
250                 Gtk::TreeModelColumn<bool>            selected;
251
252                 TrackCols () { add (route); add(label); add(selected); }
253         };
254         TrackCols                    track_cols;
255
256         Glib::RefPtr<Gtk::ListStore> track_list;
257         Gtk::TreeView                track_view;
258
259         Gtk::ScrolledWindow          track_scroller;
260
261         Gtk::HBox                    options_box;
262         Gtk::RadioButton::Group      source_group;
263         Gtk::RadioButton             region_contents_button;
264         Gtk::RadioButton             track_output_button;
265 };
266
267 #endif /* __export_channel_selector_h__ */