2831384cd3680fd05de3bc179dcc3f2f75a9796d
[ardour.git] / gtk2_ardour / export_dialog.h
1 /*
2     Copyright (C) 1999-2002 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_export_dialog_h__
21 #define __ardour_export_dialog_h__
22
23 #include <gtkmm/alignment.h>
24 #include <gtkmm/box.h>
25 #include <gtkmm/table.h>
26 #include <gtkmm/frame.h>
27 #include <gtkmm/frame.h>
28 #include <gtkmm/button.h>
29 #include <gtkmm/progressbar.h>
30 #include <gtkmm/scrolledwindow.h>
31 #include <gtkmm/fileselection.h>
32 #include <gtkmm/filechooser.h>
33 #include <gtkmm/comboboxtext.h>
34 #include <gtkmm/treeview.h>
35 #include <gtkmm/liststore.h>
36
37 #include <ardour/export.h>
38 #include <ardour/location.h>
39
40 #include "ardour_dialog.h"
41
42 class PublicEditor;
43
44 namespace ARDOUR {
45         class Session;
46         class AudioRegion;
47         class Port;
48 }
49
50 class ExportDialog : public ArdourDialog
51 {
52   public:
53         ExportDialog (PublicEditor&);
54         ~ExportDialog ();
55
56         void connect_to_session (ARDOUR::Session*);
57         virtual void set_range (nframes_t start, nframes_t end);
58         void start_export ();
59
60         virtual Gtk::FileChooserAction browse_action() const { return Gtk::FILE_CHOOSER_ACTION_SAVE; }
61
62   protected:
63         ARDOUR::AudioExportSpecification spec;
64         Gtk::Frame  file_frame;
65
66     struct ExportModelColumns : public Gtk::TreeModel::ColumnRecord
67         {
68         public:
69           Gtk::TreeModelColumn<std::string>     output;
70           Gtk::TreeModelColumn<bool>            left;
71           Gtk::TreeModelColumn<bool>            right;
72           Gtk::TreeModelColumn<ARDOUR::Port*>   port;
73
74           ExportModelColumns() { add(output); add(left); add(right); add(port);}
75         };
76
77         ExportModelColumns exp_cols;
78         
79         // These methods are intended to be used in constructors of subclasses
80         void do_not_allow_track_and_master_selection();
81         void do_not_allow_channel_count_selection();
82         void do_not_allow_export_cd_markers(); 
83         
84         // Checks the given filename for validity when export gets started.
85         // Export will interrupt when this method returns 'false'.
86         // Method is responsible for informing user.
87         virtual bool is_filepath_valid(string &filepath);
88
89         // Gets called from within do_export. Is responsible for exporting the
90         // audio data. spec has already been filled with user input before calling
91         // this method. The dialog will be closed after this function exited.
92         virtual void export_audio_data() = 0;
93
94         virtual bool wants_dir() { return false; }
95         
96         // reads the user input and fills spec with the according values
97         // filepath: complete path to the target file, including filename
98         void initSpec(string &filepath);
99
100         void set_progress_fraction(double progress) {
101                         progress_bar.set_fraction (progress); }
102         
103         ARDOUR::Session& getSession() { return *session; };
104         string get_selected_header_format() {
105                 return header_format_combo.get_active_text(); };
106         string get_selected_file_name() { return file_entry.get_text(); };
107         
108   private:
109         PublicEditor&    editor;
110         ARDOUR::Session* session;
111     bool        track_and_master_selection_allowed;
112         bool    channel_count_selection_allowed;
113         bool    export_cd_markers_allowed;
114     
115         Gtk::VBox   track_vpacker;
116         Gtk::HBox   hpacker;
117
118         Gtk::Table  format_table;
119         Gtk::Frame  format_frame;
120
121         Gtk::Label  cue_file_label;
122         Gtk::ComboBoxText cue_file_combo;
123         
124         Gtk::Label  channel_count_label;
125         Gtk::ComboBoxText channel_count_combo;
126
127         Gtk::Label  header_format_label;
128         Gtk::ComboBoxText header_format_combo;
129
130         Gtk::Label  bitdepth_format_label;
131         Gtk::ComboBoxText bitdepth_format_combo;
132
133         Gtk::Label  endian_format_label;
134         Gtk::ComboBoxText endian_format_combo;
135         
136         Gtk::Label  sample_rate_label;
137         Gtk::ComboBoxText sample_rate_combo;
138
139         Gtk::Label  src_quality_label;
140         Gtk::ComboBoxText src_quality_combo;
141
142         Gtk::Label  dither_type_label;
143         Gtk::ComboBoxText dither_type_combo;
144
145         Gtk::CheckButton cuefile_only_checkbox;
146
147         Gtk::Entry  file_entry;
148         Gtk::HBox   file_hbox;
149         Gtk::Button file_browse_button;
150
151         Gtk::Button* ok_button;
152         Gtk::Button* cancel_button;
153         Gtk::Label  cancel_label;
154         Gtk::ProgressBar progress_bar;
155         Gtk::ScrolledWindow track_scroll;
156         Gtk::ScrolledWindow master_scroll;
157         Gtk::Button         track_selector_button;
158         Gtk::TreeView  track_selector;
159         Glib::RefPtr<Gtk::ListStore> track_list;
160         Gtk::TreeView  master_selector;
161         Glib::RefPtr<Gtk::ListStore> master_list;
162
163         static void *_thread (void *arg);
164         // sets the export progress in the progress bar
165         virtual gint progress_timeout ();
166         sigc::connection progress_connection;
167         void build_window ();
168         void end_dialog();
169         void header_chosen ();
170         void channels_chosen ();
171         void bitdepth_chosen ();
172         void sample_rate_chosen ();
173         void cue_file_type_chosen();
174
175         void fill_lists();
176         void write_track_and_master_selection_to_spec();
177
178     void do_export_cd_markers (const string& path, const string& cuefile_type);
179         void export_cue_file (ARDOUR::Locations::LocationList& locations, const string& path);
180         void export_toc_file (ARDOUR::Locations::LocationList& locations, const string& path);
181         void do_export ();
182         gint window_closed (GdkEventAny *ignored);
183
184         void track_selector_button_click ();
185
186         void browse ();
187
188         void set_state();
189         void save_state();
190 };
191
192 #endif // __ardour_export_dialog_h__