new files from sakari, missed last time
[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 ExportChannel;
35         class ExportChannelConfiguration;
36         class ExportHandler;
37         class AudioPort;
38         class IO;
39 }
40
41 class XMLNode;
42
43 /// 
44 class ExportChannelSelector : public Gtk::HBox {
45   private:
46
47         typedef boost::shared_ptr<ARDOUR::ExportChannelConfiguration> ChannelConfigPtr;
48         
49         typedef boost::shared_ptr<ARDOUR::ExportHandler> HandlerPtr;
50
51   public:
52
53         ExportChannelSelector ();
54         ~ExportChannelSelector ();
55         
56         void set_state (ARDOUR::ExportProfileManager::ChannelConfigStatePtr const state_, ARDOUR::Session * session_);
57         
58         sigc::signal<void> CriticalSelectionChanged;
59
60   private:
61
62         void fill_route_list ();
63         void update_channel_count ();
64         void update_split_state ();
65
66         typedef boost::shared_ptr<ARDOUR::ExportChannel> ChannelPtr;
67         typedef std::list<ChannelPtr> CahnnelList;
68
69         ARDOUR::Session * session;
70         ARDOUR::ExportProfileManager::ChannelConfigStatePtr state;
71
72         /*** GUI stuff ***/
73
74         Gtk::VBox         channels_vbox;
75         Gtk::HBox         channels_hbox;
76
77         Gtk::Label        channels_label;
78         Gtk::SpinButton   channels_spinbutton;
79         Gtk::CheckButton  split_checkbox;
80         
81         /* Column record for channel selector view */
82         
83         class RouteCols : public Gtk::TreeModelColumnRecord
84         {
85           public:
86         
87                 struct Channel;
88         
89                 RouteCols () : n_channels (0)
90                         { add (selected); add (name); add (io); add (port_list_col); }
91         
92                 void add_channels (uint32_t chans);
93                 uint32_t n_channels;
94                 
95                 /* Channel count starts from one! */
96                 
97                 Channel & get_channel (uint32_t channel);
98         
99                 /* Static columns */
100         
101                 Gtk::TreeModelColumn<bool>           selected;
102                 Gtk::TreeModelColumn<Glib::ustring>  name;
103                 Gtk::TreeModelColumn<ARDOUR::IO *>   io;
104                 
105                 /* Combo list column (shared by all channels) */
106                 
107                 typedef Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> > ComboCol;
108                 ComboCol                             port_list_col;
109                 
110                 /* Channel struct, that represents the selected port and it's name */
111                 
112                 struct Channel {
113                   public:
114                         Channel (RouteCols & cols) { cols.add (port); cols.add (label); }
115                         
116                         Gtk::TreeModelColumn<ARDOUR::AudioPort *>  port;
117                         Gtk::TreeModelColumn<Glib::ustring>        label;
118                 };
119                 std::list<Channel> channels;
120                 
121                 /* List of available ports
122                  * Note: We need only one list of selectable ports per route,
123                  * so the list is kept in the column record
124                  */
125                 
126                 /* Column record for selecting ports for a channel from a route */
127                 
128                 class PortCols : public Gtk::TreeModel::ColumnRecord
129                 {
130                   public:
131                         PortCols () { add (selected); add(port); add(label); }
132                         
133                         Gtk::TreeModelColumn<bool>                  selected;  // not used ATM
134                         Gtk::TreeModelColumn<ARDOUR::AudioPort *>   port;
135                         Gtk::TreeModelColumn<Glib::ustring>         label;
136                 };
137                 PortCols port_cols;
138         };
139         
140         /* Channels view */
141         
142         class ChannelTreeView : public Gtk::TreeView {
143           public:
144         
145                 ChannelTreeView (uint32_t max_channels);
146                 void set_config (ChannelConfigPtr c);
147         
148                 /* Routes have to be added before adding channels */
149                 
150                 void clear_routes () { route_list->clear (); }
151                 void add_route (ARDOUR::IO * route);
152                 void set_channel_count (uint32_t channels);
153                 
154                 sigc::signal<void> CriticalSelectionChanged;
155                 
156           private:
157         
158                 ChannelConfigPtr config;
159                 void update_config ();
160         
161                 /* Signal handlers for selections changes in the view */
162         
163                 void update_toggle_selection (Glib::ustring const & path);
164                 void update_selection_text (Glib::ustring const & path, Glib::ustring const & new_text, uint32_t channel);
165                 
166                 RouteCols                     route_cols;
167                 Glib::RefPtr<Gtk::ListStore>  route_list;
168                 
169                 uint32_t                      static_columns;
170                 uint32_t                      n_channels;
171         };
172         
173         uint32_t                     max_channels;
174         
175         Gtk::ScrolledWindow          channel_scroller;
176         Gtk::Alignment               channel_alignment;
177         ChannelTreeView              channel_view;
178
179 };
180
181 #endif /* __export_channel_selector_h__ */