switch to using boost::signals2 instead of sigc++, at least for libardour. not finish...
[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, public ARDOUR::SessionHandlePtr
47 {
48   protected:
49         typedef boost::shared_ptr<ARDOUR::ExportChannelConfiguration> ChannelConfigPtr;
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<Glib::ustring>  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<ARDOUR::AudioPort *>  port;
132                         Gtk::TreeModelColumn<Glib::ustring>        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<ARDOUR::AudioPort *>   port;
150                         Gtk::TreeModelColumn<Glib::ustring>         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 (Glib::ustring const & path);
179                 void update_selection_text (Glib::ustring const & path, Glib::ustring 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 #endif /* __export_channel_selector_h__ */