Make Dropdown menus at least as wide as the button
[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 #ifdef interface
29 #undef interface
30 #endif
31
32 #include <gtkmm.h>
33 #include <sigc++/signal.h>
34 #include <boost/shared_ptr.hpp>
35
36 namespace ARDOUR {
37         class Session;
38         class ExportChannelConfiguration;
39         class RegionExportChannelFactory;
40         class ExportHandler;
41         class AudioPort;
42         class IO;
43         class AudioRegion;
44         class AudioTrack;
45 }
46
47 class XMLNode;
48
49 class ExportChannelSelector : public Gtk::HBox, public ARDOUR::SessionHandlePtr
50 {
51   protected:
52         typedef boost::shared_ptr<ARDOUR::ExportChannelConfiguration> ChannelConfigPtr;
53         typedef std::list<ChannelConfigPtr> ChannelConfigList;
54         typedef boost::shared_ptr<ARDOUR::ExportProfileManager> ProfileManagerPtr;
55
56         ProfileManagerPtr manager;
57
58   public:
59         ExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager)
60                 : SessionHandlePtr (session)
61                 , manager (manager)
62         {}
63
64         virtual ~ExportChannelSelector () {}
65
66         virtual void sync_with_manager () = 0;
67
68         sigc::signal<void> CriticalSelectionChanged;
69 };
70
71 class PortExportChannelSelector : public ExportChannelSelector
72 {
73
74   public:
75
76         PortExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager);
77         ~PortExportChannelSelector ();
78
79         void sync_with_manager ();
80
81   private:
82
83         void fill_route_list ();
84         void update_channel_count ();
85         void update_split_state ();
86
87         typedef std::list<ARDOUR::ExportChannelPtr> CahnnelList;
88
89         ARDOUR::ExportProfileManager::ChannelConfigStatePtr state;
90
91         /*** GUI stuff ***/
92
93         Gtk::VBox         channels_vbox;
94         Gtk::HBox         channels_hbox;
95
96         Gtk::Label        channels_label;
97         Gtk::SpinButton   channels_spinbutton;
98         Gtk::CheckButton  split_checkbox;
99
100         /* Column record for channel selector view */
101
102         class RouteCols : public Gtk::TreeModelColumnRecord
103         {
104           public:
105
106                 struct Channel;
107
108                 RouteCols () : n_channels (0)
109                         { add (selected); add (name); add (io); add (port_list_col); }
110
111                 void add_channels (uint32_t chans);
112                 uint32_t n_channels;
113
114                 /* Channel count starts from one! */
115
116                 Channel & get_channel (uint32_t channel);
117
118                 /* Static columns */
119
120                 Gtk::TreeModelColumn<bool>           selected;
121                 Gtk::TreeModelColumn<std::string>  name;
122                 Gtk::TreeModelColumn<ARDOUR::IO *>   io;
123
124                 /* Combo list column (shared by all channels) */
125
126                 typedef Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> > ComboCol;
127                 ComboCol                             port_list_col;
128
129                 /* Channel struct, that represents the selected port and its name */
130
131                 struct Channel {
132                   public:
133                         Channel (RouteCols & cols) { cols.add (port); cols.add (label); }
134
135                         Gtk::TreeModelColumn<boost::weak_ptr<ARDOUR::AudioPort> > port;
136                         Gtk::TreeModelColumn<std::string> label;
137                 };
138                 std::list<Channel> channels;
139
140                 /* List of available ports
141                  * Note: We need only one list of selectable ports per route,
142                  * so the list is kept in the column record
143                  */
144
145                 /* Column record for selecting ports for a channel from a route */
146
147                 class PortCols : public Gtk::TreeModel::ColumnRecord
148                 {
149                   public:
150                         PortCols () { add(selected); add(port); add(label); }
151
152                         Gtk::TreeModelColumn<bool> selected;  // not used ATM
153                         Gtk::TreeModelColumn<boost::weak_ptr<ARDOUR::AudioPort> > port;
154                         Gtk::TreeModelColumn<std::string> label;
155                 };
156                 PortCols port_cols;
157         };
158
159         /* Channels view */
160
161         class ChannelTreeView : public Gtk::TreeView {
162           public:
163
164                 ChannelTreeView (uint32_t max_channels);
165                 void set_config (ChannelConfigPtr c);
166
167                 /* Routes have to be added before adding channels */
168
169                 void clear_routes () { route_list->clear (); }
170                 void add_route (ARDOUR::IO * route);
171                 void set_channel_count (uint32_t channels);
172
173                 sigc::signal<void> CriticalSelectionChanged;
174
175           private:
176
177                 ChannelConfigPtr config;
178                 void update_config ();
179
180                 /* Signal handlers for selections changes in the view */
181
182                 void update_toggle_selection (std::string const & path);
183                 void update_selection_text (std::string const & path, std::string const & new_text, uint32_t channel);
184
185                 RouteCols                     route_cols;
186                 Glib::RefPtr<Gtk::ListStore>  route_list;
187
188                 uint32_t                      static_columns;
189                 uint32_t                      n_channels;
190         };
191
192         uint32_t                     max_channels;
193
194         Gtk::ScrolledWindow          channel_scroller;
195         Gtk::Alignment               channel_alignment;
196         ChannelTreeView              channel_view;
197
198 };
199
200 class RegionExportChannelSelector : public ExportChannelSelector
201 {
202   public:
203         RegionExportChannelSelector (ARDOUR::Session * session,
204                                      ProfileManagerPtr manager,
205                                      ARDOUR::AudioRegion const & region,
206                                      ARDOUR::AudioTrack & track);
207
208         virtual void sync_with_manager ();
209
210   private:
211
212         void handle_selection ();
213
214         ARDOUR::ExportProfileManager::ChannelConfigStatePtr state;
215         boost::shared_ptr<ARDOUR::RegionExportChannelFactory> factory;
216         ARDOUR::AudioRegion const & region;
217         ARDOUR::AudioTrack & track;
218
219         uint32_t region_chans;
220         uint32_t track_chans;
221
222         /*** GUI components ***/
223
224         Gtk::VBox             vbox;
225
226         Gtk::RadioButtonGroup type_group;
227         Gtk::RadioButton      raw_button;
228         Gtk::RadioButton      fades_button;
229         Gtk::RadioButton      processed_button;
230 };
231
232 class TrackExportChannelSelector : public ExportChannelSelector
233 {
234   public:
235         TrackExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager);
236
237         virtual void sync_with_manager ();
238
239         bool track_output () const { return track_output_button.get_active(); }
240
241   private:
242
243         void fill_list();
244         void add_track (boost::shared_ptr<ARDOUR::Route> route);
245         void update_config();
246         ChannelConfigList configs;
247
248         Gtk::VBox main_layout;
249
250         struct TrackCols : public Gtk::TreeModelColumnRecord
251         {
252           public:
253                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Route> > route;
254                 Gtk::TreeModelColumn<std::string>     label;
255                 Gtk::TreeModelColumn<bool>            selected;
256                 Gtk::TreeModelColumn<uint32_t>        order_key;
257
258                 TrackCols () { add (route); add(label); add(selected); add(order_key); }
259         };
260         TrackCols                    track_cols;
261
262         Glib::RefPtr<Gtk::ListStore> track_list;
263         Gtk::TreeView                track_view;
264
265         Gtk::ScrolledWindow          track_scroller;
266
267         Gtk::HBox                    options_box;
268         Gtk::CheckButton             track_output_button;
269         Gtk::Button                  select_tracks_button;
270         Gtk::Button                  select_busses_button;
271         Gtk::Button                  select_none_button;
272         void select_tracks ();
273         void select_busses ();
274         void select_none ();
275
276         void track_outputs_selected ();
277 };
278
279 #endif /* __export_channel_selector_h__ */