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