make import dialog non-modal
[ardour.git] / gtk2_ardour / sfdb_ui.h
1 /*
2     Copyright (C) 2005-2006 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_sfdb_ui_h__
21 #define __ardour_sfdb_ui_h__
22
23 #include <string>
24 #include <vector>
25 #include <map>
26
27 #include <sigc++/signal.h>
28
29 #include <gtkmm/stock.h>
30 #include <gtkmm/box.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/checkbutton.h>
33 #include <gtkmm/comboboxtext.h>
34 #include <gtkmm/dialog.h>
35 #include <gtkmm/entry.h>
36 #include <gtkmm/filechooserwidget.h>
37 #include <gtkmm/frame.h>
38 #include <gtkmm/label.h>
39 #include <gtkmm/textview.h>
40 #include <gtkmm/table.h>
41 #include <gtkmm/liststore.h>
42 #include <gtkmm/spinbutton.h>
43 #include <gtkmm/notebook.h>
44
45
46 #include "ardour/audiofilesource.h"
47 #include "ardour/session_handle.h"
48
49 #include "ardour_window.h"
50 #include "editing.h"
51 #include "audio_clock.h"
52
53 namespace ARDOUR {
54         class Session;
55 };
56
57 class GainMeter;
58 class Mootcher;
59
60 class SoundFileBox : public Gtk::VBox, public ARDOUR::SessionHandlePtr
61 {
62   public:
63         SoundFileBox (bool persistent);
64         virtual ~SoundFileBox () {};
65
66         void set_session (ARDOUR::Session* s);
67         bool setup_labels (const std::string& filename);
68
69         void audition();
70         bool audition_oneshot();
71         bool autoplay () const;
72
73   protected:
74         std::string path;
75
76         ARDOUR::SoundFileInfo sf_info;
77
78         Gtk::Table table;
79
80         Gtk::Label length;
81         Gtk::Label format;
82         Gtk::Label channels;
83         Gtk::Label samplerate;
84         Gtk::Label timecode;
85
86         Gtk::Label channels_value;
87         Gtk::Label samplerate_value;
88
89         Gtk::Label format_text;
90         AudioClock length_clock;
91         AudioClock timecode_clock;
92
93         Gtk::Frame border_frame;
94         Gtk::Label preview_label;
95
96         Gtk::TextView tags_entry;
97
98         Gtk::VBox main_box;
99         Gtk::VBox path_box;
100         Gtk::HBox bottom_box;
101
102         Gtk::Button play_btn;
103         Gtk::Button stop_btn;
104         Gtk::CheckButton autoplay_btn;
105         Gtk::Button apply_btn;
106
107         bool tags_entry_left (GdkEventFocus* event);
108         void tags_changed ();
109         void save_tags (const std::vector<std::string>&);
110         void stop_audition ();
111 };
112
113 class SoundFileBrowser : public ArdourWindow
114 {
115   private:
116         class FoundTagColumns : public Gtk::TreeModel::ColumnRecord
117         {
118           public:
119                 Gtk::TreeModelColumn<std::string> pathname;
120
121                 FoundTagColumns() { add(pathname); }
122         };
123
124         class FreesoundColumns : public Gtk::TreeModel::ColumnRecord
125         {
126           public:
127                 Gtk::TreeModelColumn<std::string> id;
128                 Gtk::TreeModelColumn<std::string> uri;
129                 Gtk::TreeModelColumn<std::string> filename;
130                 Gtk::TreeModelColumn<std::string> duration;
131                 Gtk::TreeModelColumn<std::string> filesize;
132                 Gtk::TreeModelColumn<std::string> smplrate;
133                 Gtk::TreeModelColumn<std::string> license;
134
135                 FreesoundColumns() {
136                         add(id); 
137                         add(filename); 
138                         add(uri);
139                         add(duration);
140                         add(filesize);
141                         add(smplrate);
142                         add(license);
143                 }
144         };
145
146         FoundTagColumns found_list_columns;
147         Glib::RefPtr<Gtk::ListStore> found_list;
148
149         FreesoundColumns freesound_list_columns;
150         Glib::RefPtr<Gtk::ListStore> freesound_list;
151
152         Gtk::Button freesound_stop_btn;
153
154   public:
155         SoundFileBrowser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, bool persistent);
156         virtual ~SoundFileBrowser ();
157
158         int run ();
159         int status () const { return _status; }
160         
161         virtual void set_session (ARDOUR::Session*);
162         std::vector<std::string> get_paths ();
163
164         void clear_selection ();
165
166         Gtk::FileChooserWidget chooser;
167
168         SoundFileBox preview;
169
170         Gtk::Entry found_entry;
171         Gtk::Button found_search_btn;
172         Gtk::TreeView found_list_view;
173
174         Gtk::Entry freesound_entry;
175         Gtk::ComboBoxText freesound_sort;
176         Gtk::SpinButton freesound_page;
177         
178         Gtk::Button freesound_search_btn;
179         Gtk::TreeView freesound_list_view;
180         Gtk::ProgressBar freesound_progress_bar;
181
182         bool freesound_search_cancel;
183         bool freesound_download_cancel;
184
185         void freesound_search();
186         
187 #ifdef FREESOUND
188         Mootcher *mootcher;
189 #endif
190
191   protected:
192         bool resetting_ourselves;
193         int matches;
194         int _status;
195         bool _done;
196
197         Gtk::FileFilter audio_and_midi_filter;
198         Gtk::FileFilter audio_filter;
199         Gtk::FileFilter midi_filter;
200         Gtk::FileFilter custom_filter;
201         Gtk::FileFilter matchall_filter;
202         Gtk::HBox hpacker;
203         Gtk::VBox vpacker;
204
205         Gtk::Button ok_button;
206         Gtk::Button cancel_button;
207         Gtk::Button apply_button;
208
209         static std::string persistent_folder;
210
211         Gtk::Notebook notebook;
212
213         GainMeter* gm;
214         Gtk::VBox meter_packer;
215         void add_gain_meter ();
216         void remove_gain_meter ();
217         void meter ();
218         void start_metering ();
219         void stop_metering ();
220         sigc::connection metering_connection;
221
222         void update_preview ();
223
224         void found_list_view_selected ();
225         void found_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
226         void found_search_clicked ();
227
228         void freesound_list_view_selected ();
229         void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
230         void freesound_search_clicked ();
231         void freesound_stop_clicked ();
232         
233         void chooser_file_activated ();
234
235         bool on_audio_filter (const Gtk::FileFilter::Info& filter_info);
236         bool on_midi_filter (const Gtk::FileFilter::Info& filter_info);
237         bool on_audio_and_midi_filter (const Gtk::FileFilter::Info& filter_info);
238
239         virtual bool reset_options() { return true; }
240
241   protected:
242         void on_show();
243         virtual void do_something (int action);
244 };
245
246 class SoundFileChooser : public SoundFileBrowser
247 {
248   public:
249         SoundFileChooser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s = 0);
250         virtual ~SoundFileChooser () {};
251
252         std::string get_filename ();
253
254   protected:
255         void on_hide();
256 };
257
258 class SoundFileOmega : public SoundFileBrowser
259 {
260
261   public:
262         SoundFileOmega (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, 
263                         uint32_t selected_audio_tracks, uint32_t selected_midi_tracks,
264                         bool persistent,
265                         Editing::ImportMode mode_hint = Editing::ImportAsTrack);
266
267         void reset (uint32_t selected_audio_tracks, uint32_t selected_midi_tracks);
268
269         Gtk::ComboBoxText action_combo;
270         Gtk::ComboBoxText where_combo;
271         Gtk::ComboBoxText channel_combo;
272         Gtk::ComboBoxText src_combo;
273
274         Gtk::CheckButton copy_files_btn;
275
276         void set_mode (Editing::ImportMode);
277         Editing::ImportMode get_mode() const;
278         Editing::ImportPosition get_position() const;
279         Editing::ImportDisposition get_channel_disposition() const;
280         ARDOUR::SrcQuality get_src_quality() const;
281
282   protected:
283         void on_hide();
284
285   private:
286         uint32_t selected_audio_track_cnt;
287         uint32_t selected_midi_track_cnt;
288
289         typedef std::map<std::string,Editing::ImportDisposition> DispositionMap;
290         DispositionMap disposition_map;
291
292         Gtk::HBox options;
293         Gtk::VBox block_two;
294         Gtk::VBox block_three;
295         Gtk::VBox block_four;
296
297         bool check_info (const std::vector<std::string>& paths,
298                          bool& same_size, bool& src_needed, bool& multichannel);
299
300         static bool check_link_status (const ARDOUR::Session*, const std::vector<std::string>& paths);
301
302         void file_selection_changed ();
303         bool reset_options ();
304         void reset_options_noret ();
305         bool bad_file_message ();
306
307         void do_something (int action);
308 };
309
310 #endif // __ardour_sfdb_ui_h__