* Some Export GUI tweaks
[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 #include <ardour/export_channel.h>
28
29 #include <gtkmm.h>
30 #include <sigc++/signal.h>
31 #include <boost/shared_ptr.hpp>
32
33 namespace ARDOUR {
34         class Session;
35         class ExportChannelConfiguration;
36         class RegionExportChannelFactory;
37         class ExportHandler;
38         class AudioPort;
39         class IO;
40         class AudioRegion;
41         class AudioTrack;
42 }
43
44 class XMLNode;
45
46 class ExportChannelSelector : public Gtk::HBox
47 {
48   protected:
49         typedef boost::shared_ptr<ARDOUR::ExportChannelConfiguration> ChannelConfigPtr;
50         typedef boost::shared_ptr<ARDOUR::ExportHandler> HandlerPtr;
51
52   public:
53         virtual ~ExportChannelSelector () {}
54         
55         virtual void set_state (ARDOUR::ExportProfileManager::ChannelConfigStatePtr const state_, ARDOUR::Session * session_) = 0;
56         sigc::signal<void> CriticalSelectionChanged;
57 };
58
59 class PortExportChannelSelector : public ExportChannelSelector
60 {
61
62   public:
63
64         PortExportChannelSelector ();
65         ~PortExportChannelSelector ();
66         
67         void set_state (ARDOUR::ExportProfileManager::ChannelConfigStatePtr const state_, ARDOUR::Session * session_);
68
69   private:
70
71         void fill_route_list ();
72         void update_channel_count ();
73         void update_split_state ();
74
75         typedef std::list<ARDOUR::ExportChannelPtr> CahnnelList;
76
77         ARDOUR::Session * session;
78         ARDOUR::ExportProfileManager::ChannelConfigStatePtr state;
79
80         /*** GUI stuff ***/
81
82         Gtk::VBox         channels_vbox;
83         Gtk::HBox         channels_hbox;
84
85         Gtk::Label        channels_label;
86         Gtk::SpinButton   channels_spinbutton;
87         Gtk::CheckButton  split_checkbox;
88         
89         /* Column record for channel selector view */
90         
91         class RouteCols : public Gtk::TreeModelColumnRecord
92         {
93           public:
94         
95                 struct Channel;
96         
97                 RouteCols () : n_channels (0)
98                         { add (selected); add (name); add (io); add (port_list_col); }
99         
100                 void add_channels (uint32_t chans);
101                 uint32_t n_channels;
102                 
103                 /* Channel count starts from one! */
104                 
105                 Channel & get_channel (uint32_t channel);
106         
107                 /* Static columns */
108         
109                 Gtk::TreeModelColumn<bool>           selected;
110                 Gtk::TreeModelColumn<Glib::ustring>  name;
111                 Gtk::TreeModelColumn<ARDOUR::IO *>   io;
112                 
113                 /* Combo list column (shared by all channels) */
114                 
115                 typedef Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> > ComboCol;
116                 ComboCol                             port_list_col;
117                 
118                 /* Channel struct, that represents the selected port and it's name */
119                 
120                 struct Channel {
121                   public:
122                         Channel (RouteCols & cols) { cols.add (port); cols.add (label); }
123                         
124                         Gtk::TreeModelColumn<ARDOUR::AudioPort *>  port;
125                         Gtk::TreeModelColumn<Glib::ustring>        label;
126                 };
127                 std::list<Channel> channels;
128                 
129                 /* List of available ports
130                  * Note: We need only one list of selectable ports per route,
131                  * so the list is kept in the column record
132                  */
133                 
134                 /* Column record for selecting ports for a channel from a route */
135                 
136                 class PortCols : public Gtk::TreeModel::ColumnRecord
137                 {
138                   public:
139                         PortCols () { add (selected); add(port); add(label); }
140                         
141                         Gtk::TreeModelColumn<bool>                  selected;  // not used ATM
142                         Gtk::TreeModelColumn<ARDOUR::AudioPort *>   port;
143                         Gtk::TreeModelColumn<Glib::ustring>         label;
144                 };
145                 PortCols port_cols;
146         };
147         
148         /* Channels view */
149         
150         class ChannelTreeView : public Gtk::TreeView {
151           public:
152         
153                 ChannelTreeView (uint32_t max_channels);
154                 void set_config (ChannelConfigPtr c);
155         
156                 /* Routes have to be added before adding channels */
157                 
158                 void clear_routes () { route_list->clear (); }
159                 void add_route (ARDOUR::IO * route);
160                 void set_channel_count (uint32_t channels);
161                 
162                 sigc::signal<void> CriticalSelectionChanged;
163                 
164           private:
165         
166                 ChannelConfigPtr config;
167                 void update_config ();
168         
169                 /* Signal handlers for selections changes in the view */
170         
171                 void update_toggle_selection (Glib::ustring const & path);
172                 void update_selection_text (Glib::ustring const & path, Glib::ustring const & new_text, uint32_t channel);
173                 
174                 RouteCols                     route_cols;
175                 Glib::RefPtr<Gtk::ListStore>  route_list;
176                 
177                 uint32_t                      static_columns;
178                 uint32_t                      n_channels;
179         };
180         
181         uint32_t                     max_channels;
182         
183         Gtk::ScrolledWindow          channel_scroller;
184         Gtk::Alignment               channel_alignment;
185         ChannelTreeView              channel_view;
186
187 };
188
189 class RegionExportChannelSelector : public ExportChannelSelector
190 {
191   public:
192         RegionExportChannelSelector (ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track);
193         
194         virtual void set_state (ARDOUR::ExportProfileManager::ChannelConfigStatePtr const state_, ARDOUR::Session * session_);
195
196   private:
197
198         void handle_selection ();
199
200         ARDOUR::Session * session;
201         ARDOUR::ExportProfileManager::ChannelConfigStatePtr state;
202         boost::shared_ptr<ARDOUR::RegionExportChannelFactory> factory;
203         ARDOUR::AudioRegion const & region;
204         ARDOUR::AudioTrack & track;
205         
206         uint32_t region_chans;
207         uint32_t track_chans;
208         
209         /*** GUI components ***/
210         
211         Gtk::VBox             vbox;
212         
213         Gtk::RadioButtonGroup type_group;
214         Gtk::RadioButton      raw_button;
215         Gtk::RadioButton      fades_button;
216         Gtk::RadioButton      processed_button;
217 };
218
219 #endif /* __export_channel_selector_h__ */