94420a74ec71e3b92643d9743abb50253150086f
[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.h>
24
25 #include <ardour/export.h>
26 #include <ardour/location.h>
27
28 #include "ardour_dialog.h"
29
30 class PublicEditor;
31
32 namespace ARDOUR {
33         class Session;
34         class AudioRegion;
35         class Port;
36 }
37
38 class ExportDialog : public ArdourDialog
39 {
40   public:
41         ExportDialog (PublicEditor&);
42         ~ExportDialog ();
43
44         void connect_to_session (ARDOUR::Session*);
45         virtual void set_range (nframes_t start, nframes_t end);
46         void start_export ();
47
48         virtual Gtk::FileChooserAction browse_action() const { return Gtk::FILE_CHOOSER_ACTION_SAVE; }
49
50         bool on_event (GdkEvent* ev);
51
52   protected:
53         ARDOUR::AudioExportSpecification spec;
54         Gtk::Frame  file_frame;
55
56     struct ExportModelColumns : public Gtk::TreeModel::ColumnRecord
57         {
58         public:
59           Gtk::TreeModelColumn<std::string>     output;
60           Gtk::TreeModelColumn<bool>            left;
61           Gtk::TreeModelColumn<bool>            right;
62           Gtk::TreeModelColumn<ARDOUR::Port*>   port;
63
64           ExportModelColumns() { add(output); add(left); add(right); add(port);}
65         };
66
67         ExportModelColumns exp_cols;
68         
69         // These methods are intended to be used in constructors of subclasses
70         void do_not_allow_track_and_master_selection();
71         void do_not_allow_channel_count_selection();
72         void do_not_allow_export_cd_markers(); 
73         
74         // Checks the given filename for validity when export gets started.
75         // Export will interrupt when this method returns 'false'.
76         // Method is responsible for informing user.
77         virtual bool is_filepath_valid(string &filepath);
78
79         // Gets called from within do_export. Is responsible for exporting the
80         // audio data. spec has already been filled with user input before calling
81         // this method. The dialog will be closed after this function exited.
82         virtual void export_audio_data() = 0;
83
84         virtual bool wants_dir() { return false; }
85         
86         // reads the user input and fills spec with the according values
87         // filepath: complete path to the target file, including filename
88         void initSpec(string &filepath);
89
90         void set_progress_fraction(double progress) {
91                         progress_bar.set_fraction (progress); }
92         
93         ARDOUR::Session& getSession() { return *session; };
94         string get_selected_header_format() {
95                 return header_format_combo.get_active_text(); };
96         string get_selected_file_name() { return file_entry.get_text(); };
97         
98   private:
99         PublicEditor&    editor;
100         ARDOUR::Session* session;
101     bool        track_and_master_selection_allowed;
102         bool    channel_count_selection_allowed;
103         bool    export_cd_markers_allowed;
104     
105         Gtk::VBox   track_vpacker;
106         Gtk::HBox   hpacker;
107
108         Gtk::Table  format_table;
109         Gtk::Frame  format_frame;
110
111         Gtk::Label  cue_file_label;
112         Gtk::ComboBoxText cue_file_combo;
113         
114         Gtk::Label  channel_count_label;
115         Gtk::ComboBoxText channel_count_combo;
116
117         Gtk::Label  header_format_label;
118         Gtk::ComboBoxText header_format_combo;
119
120         Gtk::Label  bitdepth_format_label;
121         Gtk::ComboBoxText bitdepth_format_combo;
122
123         Gtk::Label  endian_format_label;
124         Gtk::ComboBoxText endian_format_combo;
125         
126         Gtk::Label  sample_rate_label;
127         Gtk::ComboBoxText sample_rate_combo;
128
129         Gtk::Label  src_quality_label;
130         Gtk::ComboBoxText src_quality_combo;
131
132         Gtk::Label  dither_type_label;
133         Gtk::ComboBoxText dither_type_combo;
134
135         Gtk::CheckButton cuefile_only_checkbox;
136
137         Gtk::Entry  file_entry;
138         Gtk::HBox   file_hbox;
139         Gtk::Button file_browse_button;
140
141         Gtk::Button* ok_button;
142         Gtk::Button* cancel_button;
143         Gtk::Label  cancel_label;
144         Gtk::ProgressBar progress_bar;
145         Gtk::ScrolledWindow track_scroll;
146         Gtk::ScrolledWindow master_scroll;
147         Gtk::Button         track_selector_button;
148         Gtk::TreeView  track_selector;
149         Glib::RefPtr<Gtk::ListStore> track_list;
150         Gtk::TreeView  master_selector;
151         Glib::RefPtr<Gtk::ListStore> master_list;
152
153         static void *_thread (void *arg);
154         // sets the export progress in the progress bar
155         virtual gint progress_timeout ();
156         sigc::connection progress_connection;
157         void build_window ();
158         void end_dialog();
159         void header_chosen ();
160         void channels_chosen ();
161         void bitdepth_chosen ();
162         void sample_rate_chosen ();
163         void cue_file_type_chosen();
164
165         void fill_lists();
166         void write_track_and_master_selection_to_spec();
167
168     void do_export_cd_markers (const string& path, const string& cuefile_type);
169         void export_cue_file (ARDOUR::Locations::LocationList& locations, const string& path);
170         void export_toc_file (ARDOUR::Locations::LocationList& locations, const string& path);
171         void do_export ();
172         gint window_closed (GdkEventAny *ignored);
173
174         void track_selector_button_click ();
175
176         void browse ();
177
178         void set_state();
179         void save_state();
180 };
181
182 #endif // __ardour_export_dialog_h__